Skip to content

Commit

Permalink
E2E: Add tests for copying a Stop(Place)
Browse files Browse the repository at this point in the history
  • Loading branch information
Huulivoide committed Jan 14, 2025
1 parent 4ef138a commit feeb9f9
Show file tree
Hide file tree
Showing 11 changed files with 272 additions and 103 deletions.
2 changes: 1 addition & 1 deletion cypress/e2e/map/createStop.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ describe('Stop creation tests', () => {

// NOTE: After adding the name inputs to stop creation flow, this will fail and
// needs to be updated to the correct names
stopDetailsPage.names().shouldHaveText('T0001|-');
stopDetailsPage.titleRow.names().shouldHaveText('T0001|-');
},
);
});
138 changes: 108 additions & 30 deletions cypress/e2e/stop-registry/stopDetails.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
mapToGetInfrastructureLinksByExternalIdsQuery,
seedInfoSpots,
seedOrganisations,
seedTerminals,
stopPlaceH2003,
stopPlaceV1562,
} from '@hsl/jore4-test-db-manager';
Expand Down Expand Up @@ -150,7 +149,9 @@ describe('Stop details', () => {
insertToDbHelper(dbResources);
toast = new Toast();
cy.task<InsertedStopRegistryIds>('insertStopRegistryData', {
terminals: seedTerminals,
// Inserting the terminals here causes it's child stop H0003,
// to generate extra versions of it's quay, which breaks info spots.
// terminals: seedTerminals,
stopPlaces: stopPlaceData,
organisations: seedOrganisations,
infoSpots: seedInfoSpots,
Expand Down Expand Up @@ -317,33 +318,47 @@ describe('Stop details', () => {
});
};

const verifyInfoSpotJP1234568 = (expectedLocation: {
readonly lat: string;
readonly lon: string;
readonly stops: string;
}) => {
const infoSpotView = stopDetailsPage.infoSpots.viewCard;

infoSpotView
.getDescription()
.shouldHaveText('Ensimmäinen kerros, portaiden vieressä');
infoSpotView.getLabel().shouldHaveText('JP1234568');
infoSpotView.getInfoSpotType().shouldHaveText('Staattinen');
infoSpotView.getPurpose().shouldHaveText('Tiedotteet');
infoSpotView.getLatitude().shouldHaveText(expectedLocation.lat);
infoSpotView.getLongitude().shouldHaveText(expectedLocation.lon);
infoSpotView.getBacklight().shouldHaveText('Kyllä');
infoSpotView.getPosterPlaceSize().shouldHaveText('80x120cm');
infoSpotView
.getMaintenance()
.shouldHaveText('Huoltotietojen tekstit tähän...');
infoSpotView.getPosterSize().shouldHaveText('a4');
infoSpotView.getPosterLabel().shouldHaveText('PT1234');
infoSpotView.getPosterLines().shouldHaveText('1, 6, 17');
infoSpotView.getFloor().shouldHaveText('1');
infoSpotView.getRailInformation().shouldHaveText('7');
infoSpotView.getStops().shouldHaveText(expectedLocation.stops);
infoSpotView.getTerminals().shouldHaveText('-');
infoSpotView.getZoneLabel().shouldHaveText('A');

infoSpotView.getDisplayType().should('not.exist');
infoSpotView.getSpeechProperty().should('not.exist');
};

const verifyInitialInfoSpots = () => {
const infoSpotView = stopDetailsPage.infoSpots.viewCard;
infoSpotView.getNthSectionContainer(0).within(() => {
infoSpotView
.getDescription()
.shouldHaveText('Ensimmäinen kerros, portaiden vieressä');
infoSpotView.getLabel().shouldHaveText('JP1234568');
infoSpotView.getInfoSpotType().shouldHaveText('Staattinen');
infoSpotView.getPurpose().shouldHaveText('Tiedotteet');
infoSpotView.getLatitude().shouldHaveText('60.16490775039894');
infoSpotView.getLongitude().shouldHaveText('24.92904198486008');
infoSpotView.getBacklight().shouldHaveText('Kyllä');
infoSpotView.getPosterPlaceSize().shouldHaveText('80x120cm');
infoSpotView
.getMaintenance()
.shouldHaveText('Huoltotietojen tekstit tähän...');
infoSpotView.getPosterSize().shouldHaveText('a4');
infoSpotView.getPosterLabel().shouldHaveText('PT1234');
infoSpotView.getPosterLines().shouldHaveText('1, 6, 17');
infoSpotView.getFloor().shouldHaveText('1');
infoSpotView.getRailInformation().shouldHaveText('7');
infoSpotView.getStops().shouldHaveText('V1562');
infoSpotView.getTerminals().shouldHaveText('-');
infoSpotView.getZoneLabel().shouldHaveText('A');

infoSpotView.getDisplayType().should('not.exist');
infoSpotView.getSpeechProperty().should('not.exist');
verifyInfoSpotJP1234568({
lat: '60.16490775039894',
lon: '24.92904198486008',
stops: 'V1562',
});
});

infoSpotView.getNthSectionContainer(1).within(() => {
Expand Down Expand Up @@ -402,8 +417,8 @@ describe('Stop details', () => {
stopDetailsPage.visit('H2003');
stopDetailsPage.page().shouldBeVisible();

stopDetailsPage.label().shouldHaveText('H2003');
stopDetailsPage
stopDetailsPage.titleRow.label().shouldHaveText('H2003');
stopDetailsPage.titleRow
.names()
.shouldHaveText('Pohjoisesplanadi|Norraesplanaden');
stopDetailsPage.validityPeriod().should('contain', '20.3.2020-31.5.2050');
Expand Down Expand Up @@ -759,7 +774,7 @@ describe('Stop details', () => {
beforeEach(() => {
stopDetailsPage.visit('H2003');
stopDetailsPage.page().shouldBeVisible();
stopDetailsPage.label().shouldHaveText('H2003');
stopDetailsPage.titleRow.label().shouldHaveText('H2003');

stopDetailsPage.technicalFeaturesTabButton().click();
});
Expand Down Expand Up @@ -1564,7 +1579,7 @@ describe('Stop details', () => {

stopDetailsPage.visit('V1562');
stopDetailsPage.page().shouldBeVisible();
stopDetailsPage.label().shouldHaveText('V1562');
stopDetailsPage.titleRow.label().shouldHaveText('V1562');

stopDetailsPage.infoSpotsTabButton().click();

Expand Down Expand Up @@ -2243,6 +2258,69 @@ describe('Stop details', () => {
);
});

describe('version and copies', () => {
it('should create a copy', () => {
stopDetailsPage.visit('H2003');

stopDetailsPage.titleRow.actionsMenuButton().click();
stopDetailsPage.titleRow
.actionsMenuCopyButton()
.should('not.be.disabled')
.click();

const { copyModal } = stopDetailsPage;
copyModal
.modal()
.should('exist')
.within(() => {
copyModal
.names()
.should('contain.text', 'H2003')
.and('contain.text', 'Pohjoisesplanadi')
.and('contain.text', 'Norraesplanaden');

copyModal
.validity()
.should('contain.text', 'Perusversio')
.and('contain.text', '20.3.2020-31.5.2050');

const { form } = copyModal;
form.versionName().clearAndType('Uusi versio');
form.versionDescription().shouldBeDisabled();
form.priority.setPriority(Priority.Temporary);
form.validity.fillForm({ validityStartISODate: '2050-06-01' });
form.submitButton().click();
});

toast.expectSuccessToast('Uusi versio luotu Avataan uusi versio');
copyModal.modal().should('not.exist');
stopDetailsPage.loadingStopDetails().should('not.exist');

stopDetailsPage.validityPeriod().shouldHaveText('1.6.2050-');

verifyInitialBasicDetails();
verifyInitialLocationDetails();
verifyInitialSignageDetails();

stopDetailsPage.technicalFeaturesTabButton().click();
verifyInitialShelters();
verifyInitialMeasurements();
verifyInitialMaintenanceDetails();

stopDetailsPage.infoSpotsTabButton().click();

stopDetailsPage.infoSpots.viewCard
.getNthSectionContainer(0)
.within(() => {
verifyInfoSpotJP1234568({
lat: '60.166003223527824',
lon: '24.932072417514647',
stops: 'H2003',
});
});
});
});

// A regression test to ensure that our mutations don't eg. reset any fields they are not supposed to.
it('should keep stop place intact when submitting without actual changes', () => {
stopDetailsPage.visit('H2003');
Expand Down
18 changes: 10 additions & 8 deletions cypress/pageObjects/stop-registry/StopDetailsPage.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import {
BasicDetailsSection,
CreateCopyModal,
InfoSpotsSection,
LocationDetailsSection,
MaintenanceSection,
MeasurementsSection,
SheltersSection,
SignageDetailsSection,
TitleRow,
} from './stop-details';

export class StopDetailsPage {
Expand All @@ -23,6 +25,10 @@ export class StopDetailsPage {

maintenance = new MaintenanceSection();

titleRow = new TitleRow();

copyModal = new CreateCopyModal();

visit(label: string) {
cy.visit(`/stop-registry/stops/${label}`);
}
Expand All @@ -31,14 +37,6 @@ export class StopDetailsPage {
return cy.getByTestId('StopDetailsPage::page');
}

label() {
return cy.getByTestId('StopTitleRow::label');
}

names() {
return cy.getByTestId('StopTitleRow::names');
}

validityPeriod() {
return cy.getByTestId('StopDetailsPage::validityPeriod');
}
Expand Down Expand Up @@ -66,4 +64,8 @@ export class StopDetailsPage {
infoSpotsTabPanel() {
return cy.getByTestId('StopDetailsPage::infoSpotsTabPanel');
}

loadingStopDetails() {
return cy.getByTestId('StopDetailsPage::loadingStopDetails');
}
}
17 changes: 17 additions & 0 deletions cypress/pageObjects/stop-registry/stop-details/CreateCopyModal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { StopVersionForm } from './StopVersionForm';

export class CreateCopyModal {
form = new StopVersionForm();

modal() {
return cy.getByTestId('CopyStopModal::modal');
}

names() {
return cy.getByTestId('CopyStopModal::names');
}

validity() {
return cy.getByTestId('CopyStopModal::validity');
}
}
28 changes: 28 additions & 0 deletions cypress/pageObjects/stop-registry/stop-details/StopVersionForm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { PriorityForm } from '../../PriorityForm';
import { ValidityPeriodForm } from '../../ValidityPeriodForm';

export class StopVersionForm {
priority = new PriorityForm();

validity = new ValidityPeriodForm();

form() {
return cy.getByTestId('StopVersionForm::form');
}

versionName() {
return cy.getByTestId('StopVersionForm::versionName');
}

versionDescription() {
return cy.getByTestId('StopVersionForm::versionDescription');
}

submitButton() {
return cy.getByTestId('StopVersionForm::submitButton');
}

cancelButton() {
return cy.getByTestId('StopVersionForm::cancelButton');
}
}
25 changes: 25 additions & 0 deletions cypress/pageObjects/stop-registry/stop-details/TitleRow.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
export class TitleRow {
label() {
return cy.getByTestId('StopTitleRow::label');
}

names() {
return cy.getByTestId('StopTitleRow::names');
}

editValidityButton() {
return cy.getByTestId('StopTitleRow::editValidityButton');
}

openOnMapButton() {
return cy.getByTestId('StopTitleRow::StopTitleRow::openOnMapButton');
}

actionsMenuButton() {
return cy.getByTestId('StopTitleRow::extraActions::menu');
}

actionsMenuCopyButton() {
return cy.getByTestId('StopTitleRow::extraActions::copy');
}
}
2 changes: 2 additions & 0 deletions cypress/pageObjects/stop-registry/stop-details/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export * from './BasicDetailsForm';
export * from './BasicDetailsSection';
export * from './BasicDetailsViewCard';
export * from './CreateCopyModal';
export * from './InfoSpotSection';
export * from './InfoSpotsForm';
export * from './InfoSpotViewCard';
Expand All @@ -20,3 +21,4 @@ export * from './ShelterViewCard';
export * from './SignageDetailsForm';
export * from './SignageDetailsSection';
export * from './SignageDetailsViewCard';
export * from './TitleRow';
Loading

0 comments on commit feeb9f9

Please sign in to comment.