Skip to content

Commit

Permalink
Update tests for nonpassenger stations
Browse files Browse the repository at this point in the history
  • Loading branch information
mjaakko committed Feb 13, 2020
1 parent 9130924 commit a781574
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 18 deletions.
4 changes: 3 additions & 1 deletion src/components/pages/Station/Station.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ export default () => {
<StationName stationShortCode={stationShortCode} />
</Header>
{stationMetadata && !stationMetadata.passengerTraffic ? (
<p>{t('station.noPassengerTraffic')}</p>
<p className="noPassengerTraffic">
{t('station.noPassengerTraffic')}
</p>
) : (
<>
{loading && <Loader indeterminate active />}
Expand Down
52 changes: 35 additions & 17 deletions src/components/pages/Station/__tests__/Station.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,45 @@ import Station from '../Station';
jest.mock('../../../../hooks/useStationsTrains');

const stations = [
{ stationShortCode: 'TEST1', stationName: 'Test_1' },
{ stationShortCode: 'TEST2', stationName: 'Test_2' },
{ stationShortCode: 'TEST3', stationName: 'Test_3' },
{ stationShortCode: 'TEST1', stationName: 'Test_1', passengerTraffic: false },
{ stationShortCode: 'TEST2', stationName: 'Test_2', passengerTraffic: true },
{ stationShortCode: 'TEST3', stationName: 'Test_3', passengerTraffic: false },
].reduce(
(map, station) => map.set(station.stationShortCode, station),
new Map()
);

test('renders Station with correct amount of trains', () => {
const component = render(
<StaticRouter location="/station/TEST2">
<MetadataContext.Provider value={{ stations }}>
<Route path="/station/:stationShortCode">
<Station />
</Route>
</MetadataContext.Provider>
</StaticRouter>
);
describe('<Station />', () => {
test('renders Station with correct amount of trains', () => {
const component = render(
<StaticRouter location="/station/TEST2">
<MetadataContext.Provider value={{ stations }}>
<Route path="/station/:stationShortCode">
<Station />
</Route>
</MetadataContext.Provider>
</StaticRouter>
);

const tableRows = component.container.querySelectorAll(
'.stationTimetableRow'
);
expect(tableRows.length).toBe(1);
const tableRows = component.container.querySelectorAll(
'.stationTimetableRow'
);
expect(tableRows.length).toBe(1);
});

test('renders message if the station does not have regular passenger traffic', () => {
const component = render(
<StaticRouter location="/station/TEST1">
<MetadataContext.Provider value={{ stations }}>
<Route path="/station/:stationShortCode">
<Station />
</Route>
</MetadataContext.Provider>
</StaticRouter>
);

const message = component.container.querySelectorAll('.noPassengerTraffic');
expect(message.length).toBe(1);
expect(message[0]).not.toEqual(null);
});
});

0 comments on commit a781574

Please sign in to comment.