Skip to content

Commit d8729da

Browse files
committed
Add e2e tests for creating and removing hybrid stop
1 parent 2ef9be2 commit d8729da

7 files changed

Lines changed: 189 additions & 1 deletion

File tree

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
import {
2+
Priority,
3+
ReusableComponentsVehicleModeEnum,
4+
StopAreaInput,
5+
StopRegistryGeoJsonType,
6+
StopRegistryTransportModeType,
7+
} from '@hsl/jore4-test-db-manager/dist/CypressSpecExports';
8+
import { Tag } from '../../enums';
9+
import { MapPage, StopDetailsPage, Toast } from '../../pageObjects';
10+
import { InsertedStopRegistryIds } from '../utils';
11+
12+
// Test labels
13+
const busStopLabel = 'H9901';
14+
const busAreaCode = 'HYB01';
15+
const tramAreaCode = 'HYB02';
16+
17+
// Coordinates where bus infra links are known to exist (same as createStop.cy.ts)
18+
const testCoordinates = {
19+
lat: 60.164074274478054,
20+
lng: 24.93021804533524,
21+
};
22+
23+
const stopAreaInput: Array<StopAreaInput> = [
24+
{
25+
StopArea: {
26+
transportMode: StopRegistryTransportModeType.Bus,
27+
name: { lang: 'fin', value: 'Hybrid bussi-alue' },
28+
privateCode: { type: 'HSL/TEST', value: busAreaCode },
29+
geometry: {
30+
coordinates: [testCoordinates.lng, testCoordinates.lat],
31+
type: StopRegistryGeoJsonType.Point,
32+
},
33+
},
34+
organisations: null,
35+
},
36+
{
37+
StopArea: {
38+
transportMode: StopRegistryTransportModeType.Tram,
39+
name: { lang: 'fin', value: 'Hybrid ratikka-alue' },
40+
privateCode: { type: 'HSL/TEST', value: tramAreaCode },
41+
geometry: {
42+
coordinates: [testCoordinates.lng, testCoordinates.lat],
43+
type: StopRegistryGeoJsonType.Point,
44+
},
45+
},
46+
organisations: null,
47+
},
48+
];
49+
50+
describe(
51+
'Hybrid stop (multi-transport-mode)',
52+
{ tags: [Tag.StopRegistry, Tag.Stops] },
53+
() => {
54+
beforeEach(() => {
55+
cy.task('resetDbs');
56+
57+
cy.task<InsertedStopRegistryIds>('insertStopRegistryData', {
58+
stopPlaces: stopAreaInput,
59+
stopPointsRequired: false,
60+
});
61+
62+
cy.setupTests();
63+
cy.mockLogin();
64+
});
65+
66+
it('Should create a bus stop, make it hybrid (add tram), then remove tram', () => {
67+
// Step 1: Create a bus stop on the map
68+
MapPage.map.visit({
69+
zoom: 16,
70+
lat: testCoordinates.lat,
71+
lng: testCoordinates.lng,
72+
});
73+
74+
MapPage.createStopAtLocation({
75+
stopFormInfo: {
76+
publicCode: busStopLabel,
77+
stopPlace: busAreaCode,
78+
validityStartISODate: '2024-01-01',
79+
priority: Priority.Standard,
80+
reasonForChange: 'E2E test',
81+
},
82+
clickRelativePoint: {
83+
xPercentage: 40,
84+
yPercentage: 55,
85+
},
86+
vehicleMode: ReusableComponentsVehicleModeEnum.Bus,
87+
});
88+
89+
MapPage.gqlStopShouldBeCreatedSuccessfully();
90+
MapPage.checkStopSubmitSuccessToast();
91+
92+
// Step 2: Navigate to stop details page
93+
StopDetailsPage.visit(busStopLabel);
94+
StopDetailsPage.page().shouldBeVisible();
95+
96+
// Step 3: Open "Make hybrid" modal via extra actions menu
97+
StopDetailsPage.titleRow.actionsMenuButton().click();
98+
StopDetailsPage.titleRow.actionsMenuMakeHybridButton().click();
99+
100+
// Step 4: Select tram transport mode
101+
StopDetailsPage.makeHybridModal.modal().shouldBeVisible();
102+
StopDetailsPage.makeHybridModal.transportModeDropdown().click();
103+
cy.get('[role="option"]').contains('Raitiovaunu').click();
104+
105+
// Step 5: Search and select the tram stop area
106+
StopDetailsPage.makeHybridModal.stopAreaInput().type(tramAreaCode);
107+
StopDetailsPage.makeHybridModal.stopAreaOption(tramAreaCode).click();
108+
109+
// Step 6: Confirm
110+
StopDetailsPage.makeHybridModal.confirmButton().click();
111+
112+
Toast.expectSuccessToast('Yhteiskäyttöpysäkki luotu onnistuneesti');
113+
114+
// Step 7: Verify the mirrored quay card appears
115+
StopDetailsPage.mirroredQuayDetails.cards().should('exist');
116+
117+
// Step 8: Remove the hybrid relation
118+
StopDetailsPage.mirroredQuayDetails
119+
.cards()
120+
.first()
121+
.within(() => {
122+
StopDetailsPage.mirroredQuayDetails.removeButton().click();
123+
});
124+
125+
// Confirm removal in the dialog
126+
StopDetailsPage.mirroredQuayDetails.confirmationDialog
127+
.getConfirmButton()
128+
.click();
129+
130+
// Step 9: Verify the mirrored card is gone
131+
StopDetailsPage.mirroredQuayDetails.cards().should('not.exist');
132+
});
133+
},
134+
);

cypress/pageObjects/stop-registry/StopDetailsPage.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import {
55
InfoSpotsSection,
66
LocationDetailsSection,
77
MaintenanceSection,
8+
MakeHybridStopModal,
89
MeasurementsSection,
10+
MirroredQuayDetails,
911
SheltersSection,
1012
SignageDetailsSection,
1113
StopHeaderSummaryRow,
@@ -42,6 +44,10 @@ export class StopDetailsPage {
4244

4345
static headerSummaryRow = StopHeaderSummaryRow;
4446

47+
static makeHybridModal = MakeHybridStopModal;
48+
49+
static mirroredQuayDetails = MirroredQuayDetails;
50+
4551
static visit(label: string) {
4652
cy.visit(`/stop-registry/stops/${label}`);
4753
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
export class MakeHybridStopModal {
2+
static modal() {
3+
return cy.getByTestId('MakeHybridStopModal');
4+
}
5+
6+
static transportModeDropdown() {
7+
return cy.getByTestId('MakeHybridStopModal::transportMode::ListboxButton');
8+
}
9+
10+
static stopAreaInput() {
11+
return cy.getByTestId('MakeHybridStopModal::stopAreaInput');
12+
}
13+
14+
static stopAreaOption(code: string) {
15+
return cy.getByTestId(`MakeHybridStopModal::stopArea::${code}`);
16+
}
17+
18+
static confirmButton() {
19+
return cy.getByTestId('MakeHybridStopModal::confirm');
20+
}
21+
22+
static cancelButton() {
23+
return cy.getByTestId('MakeHybridStopModal::cancel');
24+
}
25+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { ConfirmationDialog } from '../../shared-components';
2+
3+
export class MirroredQuayDetails {
4+
static cards() {
5+
return cy.getByTestId('MirroredQuayDetails::container');
6+
}
7+
8+
static removeButton() {
9+
return cy.getByTestId('MirroredQuayDetails::remove');
10+
}
11+
12+
static confirmationDialog = ConfirmationDialog;
13+
}

cypress/pageObjects/stop-registry/stop-details/StopTitleRow.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,8 @@ export class StopTitleRow {
1818
static actionsMenuCopyButton() {
1919
return cy.getByTestId('StopTitleRow::extraActions::copy');
2020
}
21+
22+
static actionsMenuMakeHybridButton() {
23+
return cy.getByTestId('StopTitleRow::extraActions::makeHybrid');
24+
}
2125
}

cypress/pageObjects/stop-registry/stop-details/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,5 @@ export * from './SignageDetailsSection';
2424
export * from './SignageDetailsViewCard';
2525
export * from './StopHeaderSummaryRow';
2626
export * from './StopTitleRow';
27+
export * from './MakeHybridStopModal';
28+
export * from './MirroredQuayDetails';

ui/src/components/stop-registry/stops/queries/useDeleteQuay.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ export function useDeleteQuay() {
2626
(stopPlaceId: string, quayId: string) =>
2727
deleteQuay({
2828
variables: { stopPlaceId, quayId },
29-
refetchQueries: ['GetMapStops', 'getStopPlaceDetails', 'GetStopDetails'],
29+
refetchQueries: [
30+
'GetMapStops',
31+
'getStopPlaceDetails',
32+
'GetStopDetails',
33+
],
3034
awaitRefetchQueries: true,
3135
}),
3236
[deleteQuay],

0 commit comments

Comments
 (0)