Skip to content

Commit d92aed9

Browse files
authored
feat(about): add version info component (#1037)
1 parent 20b1e80 commit d92aed9

File tree

7 files changed

+87
-3
lines changed

7 files changed

+87
-3
lines changed

src/locale/en.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,5 +253,7 @@
253253
"description": "Wikipedia - In public transport, bus bunching is a phenomenon whereby two or more transit vehicles that were scheduled at regular intervals along a common route instead bunch together and form a platoon. This occurs when leading vehicles are unable to keep their schedule and fall behind to such an extent that trailing vehicles catch up to them."
254254
}
255255
]
256-
}
256+
},
257+
"version": "Current version identifier",
258+
"failedToFetchVersion": "Failed to fetch current version identifier"
257259
}

src/locale/he.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,5 +272,8 @@
272272
"description": "ויקיפדיה - בתחבורה ציבורית, התקבצות אוטובוסים (באנגלית: Bus Bunching) היא מצב שבו שני אוטובוסים או יותר שהיו אמורים להגיע לתחנה בזמנים שונים, מגיעים אליה יחד. מצב זה מתרחש כשמתרחשת חריגה מלוח הזמנים והאוטובוס שהיה אמור להגיע שני משתווה לראשון."
273273
}
274274
]
275-
}
275+
},
276+
"loading": "טוען...",
277+
"version": "מזהה גרסה",
278+
"failedToFetchVersion": "נכשל בטעינת מידע אודות מזהה הגרסה הנוכחית"
276279
}

src/pages/about/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import Stack from '@mui/material/Stack'
55
import './About.scss'
66
import { useQuery } from '@tanstack/react-query'
77
import SlackIcon from '../../resources/slack-icon.svg'
8+
import { VersionInfo } from './version/VersionInfo'
89
import Widget from 'src/shared/Widget'
910

1011
const pageName = 'aboutPage'
@@ -24,8 +25,9 @@ const About = () => {
2425
<Questions />
2526
<Funding />
2627
<Attributions />
28+
<VersionInfo />
29+
<Contributors />
2730
</Stack>
28-
<Contributors />
2931
</AboutStyle>
3032
)
3133
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.version {
2+
font-family: monospace;
3+
font-size: 0.8em;
4+
color: #666;
5+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
2+
import { VersionInfo } from './VersionInfo'
3+
4+
export default {
5+
title: 'About/VersionInfo',
6+
component: VersionInfo,
7+
}
8+
9+
const queryClient = new QueryClient()
10+
queryClient.setQueryData(['version'], '1.2.3')
11+
12+
export const Default = () => (
13+
<QueryClientProvider client={queryClient}>
14+
<VersionInfo />
15+
</QueryClientProvider>
16+
)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { useTranslation } from 'react-i18next'
2+
import { useQuery } from '@tanstack/react-query'
3+
import Widget from 'src/shared/Widget'
4+
5+
import './VersionInfo.scss'
6+
7+
const versionUrl = 'https://open-bus-map-search.hasadna.org.il/hash.txt'
8+
9+
export const VersionInfo = () => {
10+
const { t } = useTranslation()
11+
const {
12+
data: version,
13+
isLoading,
14+
isError,
15+
} = useQuery({
16+
queryKey: ['version'],
17+
queryFn: () => fetch(versionUrl).then((response) => response.text()),
18+
})
19+
return (
20+
<Widget>
21+
<h2>{t('version')}</h2>
22+
{isLoading && <p>{t('loading')}</p>}
23+
{isError && <p>{t('failedToFetchVersion')}</p>}
24+
{version && <p className="version">{version}</p>}
25+
</Widget>
26+
)
27+
}

tests/version-info.spec.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { expect } from '@playwright/test'
2+
import { test } from './utils'
3+
4+
const versionUrl = 'https://open-bus-map-search.hasadna.org.il/hash.txt'
5+
6+
test.describe('Version info tests', () => {
7+
test.beforeEach(async ({ page }) => {
8+
await page.route(/google-analytics\.com|googletagmanager\.com/, (route) => route.abort())
9+
await page.route(/github.com/, (route) => route.abort())
10+
await page.goto('/about')
11+
})
12+
test('should see loading state', async ({ page }) => {
13+
await page.route(versionUrl, () => void 0)
14+
await expect(page.getByRole('heading', { name: 'גרסה' })).toBeVisible()
15+
await expect(page.getByText('טוען...')).toBeVisible()
16+
await page.getByLabel('English').click()
17+
await expect(page.getByText('Loading')).toBeVisible()
18+
})
19+
test('should see version', async ({ page }) => {
20+
await page.route(versionUrl, (route) => route.fulfill({ body: 'my version' }))
21+
await expect(page.getByText('my version')).toBeVisible()
22+
})
23+
test('should see error message', async ({ page }) => {
24+
await page.route(versionUrl, (route) => route.abort())
25+
await expect(page.getByText('נכשל בטעינת מידע')).toBeVisible({ timeout: 15_000 })
26+
await page.getByLabel('English').click()
27+
await expect(page.getByText('Failed to fetch current version identifier')).toBeVisible()
28+
})
29+
})

0 commit comments

Comments
 (0)