Skip to content

Commit 83e9101

Browse files
Samuli RasiSamuli Rasi
Samuli Rasi
authored and
Samuli Rasi
committed
Add tests for timetable import and Hastus export
Timetable import and Hastus export tests and resources. Resolves [HSLdevcom/jore4#1011](HSLdevcom/jore4#1011) Resolves [HSLdevcom/jore4#1010](HSLdevcom/jore4#1010)
1 parent 4b5b370 commit 83e9101

38 files changed

+753
-15
lines changed

cypress/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ screenshots
44
cypress.env.json
55
jore4-e2e-*.xml
66
/runner-results
7+
jore4-export-*.csv

cypress/cypress.config.ts

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export default defineConfig({
1010
fixturesFolder: 'fixtures',
1111
screenshotsFolder: 'reports/screenshots',
1212
videosFolder: 'reports/videos',
13+
downloadsFolder: 'downloads',
1314
video: false,
1415
defaultCommandTimeout: 20000,
1516
viewportWidth: 1920,

cypress/e2e/hastusExport.cy.ts

+235
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,235 @@
1+
import {
2+
GetInfrastructureLinksByExternalIdsResult,
3+
buildLine,
4+
buildRoute,
5+
buildStop,
6+
buildStopsInJourneyPattern,
7+
buildTimingPlace,
8+
extractInfrastructureLinkIdsFromResponse,
9+
InfraLinkAlongRouteInsertInput,
10+
JourneyPatternInsertInput,
11+
LineInsertInput,
12+
mapToGetInfrastructureLinksByExternalIdsQuery,
13+
RouteInsertInput,
14+
StopInsertInput,
15+
} from '@hsl/jore4-test-db-manager';
16+
import { DateTime } from 'luxon';
17+
import { Tag } from '../enums';
18+
import { RoutesAndLinesPage } from '../pageObjects';
19+
import { UUID } from '../types';
20+
import {
21+
insertToDbHelper,
22+
removeFromDbHelper,
23+
SupportedResources,
24+
} from '../utils';
25+
26+
// These external IDs exist in the infralink seed data.
27+
// These form a straight line on Eerikinkatu in Helsinki.
28+
// Coordinates are partial since they are needed only for the stop creation.
29+
30+
const testInfraLinks = [
31+
{
32+
externalId: '445156',
33+
coordinates: [24.926699622176628, 60.164181083308065, 10.0969999999943],
34+
},
35+
{
36+
externalId: '442424',
37+
coordinates: [24.92904198486008, 60.16490775039894, 0],
38+
},
39+
{
40+
externalId: '442325',
41+
coordinates: [24.932072417514647, 60.166003223527824, 0],
42+
},
43+
];
44+
45+
const stopLabels = ['H1234', 'H1235', 'H1236'];
46+
47+
const lines: LineInsertInput[] = [
48+
{
49+
...buildLine({ label: '1234' }),
50+
line_id: '08d1fa6b-440c-421e-ad4d-0778d65afe60',
51+
},
52+
];
53+
54+
const timingPlaces = [
55+
buildTimingPlace('78ee94c3-e856-4fdc-89ad-10b72cadb444', '1AACKT'),
56+
buildTimingPlace('f8a93c6f-5ef7-4b09-ae5e-0a04ea8597e9', '1ELIMK'),
57+
buildTimingPlace('5240633b-5c94-49c1-b1c2-26e9d61a01cd', '1AURLA'),
58+
];
59+
60+
const buildStopsOnInfrastrucureLinks = (
61+
infrastructureLinkIds: UUID[],
62+
): StopInsertInput[] => [
63+
{
64+
...buildStop({
65+
label: stopLabels[0],
66+
located_on_infrastructure_link_id: infrastructureLinkIds[0],
67+
}),
68+
scheduled_stop_point_id: '7ef42a37-142d-44be-9b69-dbe6adca7f34',
69+
measured_location: {
70+
type: 'Point',
71+
coordinates: testInfraLinks[0].coordinates,
72+
},
73+
},
74+
{
75+
...buildStop({
76+
label: stopLabels[1],
77+
located_on_infrastructure_link_id: infrastructureLinkIds[1],
78+
}),
79+
scheduled_stop_point_id: '4f8df0bc-a5cb-4fbe-a6dc-0425d55be382',
80+
measured_location: {
81+
type: 'Point',
82+
coordinates: testInfraLinks[1].coordinates,
83+
},
84+
},
85+
{
86+
...buildStop({
87+
label: stopLabels[2],
88+
located_on_infrastructure_link_id: infrastructureLinkIds[2],
89+
}),
90+
scheduled_stop_point_id: '322a32cc-7a50-402b-9c01-5dc6a6b39af6',
91+
measured_location: {
92+
type: 'Point',
93+
coordinates: testInfraLinks[2].coordinates,
94+
},
95+
},
96+
];
97+
98+
const routes: RouteInsertInput[] = [
99+
{
100+
...buildRoute({ label: '99' }),
101+
route_id: '829e9d55-aa25-4ab9-858b-f2a5aa81d931',
102+
on_line_id: lines[0].line_id,
103+
validity_start: DateTime.fromISO('2022-08-11T13:08:43.315+03:00'),
104+
validity_end: DateTime.fromISO('2032-08-11T13:08:43.315+03:00'),
105+
},
106+
];
107+
108+
const buildInfraLinksAlongRoute = (
109+
infrastructureLinkIds: UUID[],
110+
): InfraLinkAlongRouteInsertInput[] => [
111+
{
112+
route_id: routes[0].route_id,
113+
infrastructure_link_id: infrastructureLinkIds[0],
114+
infrastructure_link_sequence: 0,
115+
is_traversal_forwards: true,
116+
},
117+
{
118+
route_id: routes[0].route_id,
119+
infrastructure_link_id: infrastructureLinkIds[1],
120+
infrastructure_link_sequence: 1,
121+
is_traversal_forwards: true,
122+
},
123+
{
124+
route_id: routes[0].route_id,
125+
infrastructure_link_id: infrastructureLinkIds[2],
126+
infrastructure_link_sequence: 2,
127+
is_traversal_forwards: true,
128+
},
129+
];
130+
131+
const journeyPatterns: JourneyPatternInsertInput[] = [
132+
{
133+
journey_pattern_id: '6cae356b-20f4-4e04-a969-097999b351f0',
134+
on_route_id: routes[0].route_id,
135+
},
136+
];
137+
138+
const stopsInJourneyPattern = buildStopsInJourneyPattern(
139+
stopLabels,
140+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
141+
journeyPatterns[0].journey_pattern_id!,
142+
);
143+
144+
// NOTE: Hastus export tests do not work currently when running e2e tests in parallel
145+
describe('Hastus export', () => {
146+
let routesAndLinesPage: RoutesAndLinesPage;
147+
148+
const exportDate = DateTime.now().toISODate();
149+
const exportFilePath = `${Cypress.config(
150+
'downloadsFolder',
151+
)}/jore4-export-${exportDate}.csv`;
152+
const comparisonExportFilePath = `${Cypress.config(
153+
'fixturesFolder',
154+
)}/hastusExport/comparison-export-1.csv`;
155+
const baseDbResources = {
156+
lines,
157+
routes,
158+
journeyPatterns,
159+
stopsInJourneyPattern,
160+
};
161+
let dbResources: SupportedResources;
162+
163+
before(() => {
164+
cy.task<GetInfrastructureLinksByExternalIdsResult>(
165+
'hasuraAPI',
166+
mapToGetInfrastructureLinksByExternalIdsQuery(
167+
testInfraLinks.map((infralink) => infralink.externalId),
168+
),
169+
).then((res) => {
170+
const infraLinkIds = extractInfrastructureLinkIdsFromResponse(res);
171+
const stops = buildStopsOnInfrastrucureLinks(infraLinkIds);
172+
const infraLinksAlongRoute = buildInfraLinksAlongRoute(infraLinkIds);
173+
dbResources = {
174+
...baseDbResources,
175+
timingPlaces,
176+
stops,
177+
infraLinksAlongRoute,
178+
};
179+
});
180+
});
181+
182+
beforeEach(() => {
183+
removeFromDbHelper(dbResources);
184+
insertToDbHelper(dbResources);
185+
186+
routesAndLinesPage = new RoutesAndLinesPage();
187+
188+
cy.setupTests();
189+
cy.mockLogin();
190+
cy.visit('/routes');
191+
});
192+
193+
afterEach(() => {
194+
removeFromDbHelper(dbResources);
195+
cy.task('deleteFile', exportFilePath);
196+
});
197+
198+
it(
199+
'Should export a line',
200+
{ tags: [Tag.Lines, Tag.HastusExport, Tag.Smoke] },
201+
() => {
202+
// Search and export a line
203+
routesAndLinesPage.searchContainer.getChevron().click();
204+
// Uncheck Temporary priority button so that only Standard priority is shown
205+
// and exporting works
206+
routesAndLinesPage.searchContainer.priorityCondition
207+
.getTemporaryPriorityConditionButton()
208+
.click();
209+
routesAndLinesPage.searchContainer.getSearchInput().type('1234{enter}');
210+
routesAndLinesPage.exportToolBar.getToggleSelectingButton().click();
211+
routesAndLinesPage.routeLineTableRow
212+
.getRouteLineTableRowCheckbox('1234')
213+
.check();
214+
routesAndLinesPage.exportToolBar.getExportSelectedButton().click();
215+
cy.wait('@hastusExport').its('response.statusCode').should('equal', 200);
216+
cy.readFile(exportFilePath).then((exportedFile) => {
217+
cy.readFile(comparisonExportFilePath).should('eq', exportedFile);
218+
});
219+
},
220+
);
221+
222+
it('Should export a route', { tags: [Tag.Routes, Tag.HastusExport] }, () => {
223+
// Skip searching via UI
224+
cy.visit('/routes/search?label=99&priorities=10&displayedType=routes');
225+
routesAndLinesPage.exportToolBar.getToggleSelectingButton().click();
226+
routesAndLinesPage.routeLineTableRow
227+
.getRouteLineTableRowCheckbox('99')
228+
.check();
229+
routesAndLinesPage.exportToolBar.getExportSelectedButton().click();
230+
cy.wait('@hastusExport').its('response.statusCode').should('equal', 200);
231+
cy.readFile(exportFilePath).then((exportedFile) => {
232+
cy.readFile(comparisonExportFilePath).should('eq', exportedFile);
233+
});
234+
});
235+
});

0 commit comments

Comments
 (0)