From 8aa222ec84e9a7a427443dc6c808d96651055445 Mon Sep 17 00:00:00 2001 From: Pyry Koivisto Date: Mon, 16 Sep 2024 13:12:14 +0300 Subject: [PATCH] AKR(Frontend): Fix Cypress tests targeting meeting page [deploy] --- .../integration/clerk/meeting_dates.spec.ts | 27 ++++++++++--------- .../support/page-objects/meetingDatesPage.ts | 15 +++++++++-- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/frontend/packages/akr/src/tests/cypress/integration/clerk/meeting_dates.spec.ts b/frontend/packages/akr/src/tests/cypress/integration/clerk/meeting_dates.spec.ts index 7f1f73e1d..0f8aa56c1 100644 --- a/frontend/packages/akr/src/tests/cypress/integration/clerk/meeting_dates.spec.ts +++ b/frontend/packages/akr/src/tests/cypress/integration/clerk/meeting_dates.spec.ts @@ -13,8 +13,7 @@ const meetingDateToAdd = { version: 0, date: '2030-10-04', }; -const meetingDateToBeDeleted = 5; - +const meetingDateToBeDeleted = { id: 5, dateLabel: '18.11.2021' }; beforeEach(() => { cy.fixture('meeting_dates_10.json').then((dates) => { meetingDates = dates; @@ -93,7 +92,8 @@ describe('MeetingDatesPage', () => { }); it('should open a confirmation dialog when row delete icon is clicked, and do no changes if user backs out', () => { - onMeetingDatesPage.clickDeleteRowIcon(1); + onMeetingDatesPage.filterByStatus(MeetingDateStatus.Passed); + onMeetingDatesPage.deleteMeetingDate(meetingDateToBeDeleted.dateLabel); onDialog.expectText('Haluatko varmasti poistaa kokouspäivän?'); onDialog.clickButtonByText('Takaisin'); @@ -102,19 +102,18 @@ describe('MeetingDatesPage', () => { }); it('should open a confirmation dialog when row delete icon is clicked, and delete the selected meeting date if user confirms', () => { - const newMeetingDates = meetingDates.filter( - (m) => m.id !== meetingDateToBeDeleted, - ); - - cy.intercept('GET', APIEndpoints.MeetingDate, [...newMeetingDates]); onMeetingDatesPage.filterByStatus(MeetingDateStatus.Passed); - onMeetingDatesPage.clickDeleteRowIcon(1); + onMeetingDatesPage.deleteMeetingDate(meetingDateToBeDeleted.dateLabel); cy.intercept( 'DELETE', - `${APIEndpoints.MeetingDate}/${meetingDateToBeDeleted}`, + `${APIEndpoints.MeetingDate}/${meetingDateToBeDeleted.id}`, {}, ).as('delete'); + const newMeetingDates = meetingDates.filter( + (m) => m.id !== meetingDateToBeDeleted.id, + ); + cy.intercept('GET', APIEndpoints.MeetingDate, [...newMeetingDates]); onDialog.clickButtonByText('Kyllä'); @@ -123,16 +122,18 @@ describe('MeetingDatesPage', () => { onMeetingDatesPage.expectTotalMeetingDatesCount(9); onMeetingDatesPage.expectSelectedMeetingDatesCount(5); - onToast.expectText('Kokouspäivä 18.11.2021 poistettu'); + onToast.expectText( + `Kokouspäivä ${meetingDateToBeDeleted.dateLabel} poistettu`, + ); }); it('should show an error toast if meeting date is chosen to be deleted, but an API error occurs', () => { onMeetingDatesPage.filterByStatus(MeetingDateStatus.Passed); - onMeetingDatesPage.clickDeleteRowIcon(1); + onMeetingDatesPage.deleteMeetingDate(meetingDateToBeDeleted.dateLabel); cy.intercept( 'DELETE', - `${APIEndpoints.MeetingDate}/${meetingDateToBeDeleted}`, + `${APIEndpoints.MeetingDate}/${meetingDateToBeDeleted.id}`, createAPIErrorResponse(APIError.MeetingDateDeleteHasAuthorisations), ).as('deleteWithError'); onDialog.clickButtonByText('Kyllä'); diff --git a/frontend/packages/akr/src/tests/cypress/support/page-objects/meetingDatesPage.ts b/frontend/packages/akr/src/tests/cypress/support/page-objects/meetingDatesPage.ts index 765fd38e2..6125cc65c 100644 --- a/frontend/packages/akr/src/tests/cypress/support/page-objects/meetingDatesPage.ts +++ b/frontend/packages/akr/src/tests/cypress/support/page-objects/meetingDatesPage.ts @@ -9,6 +9,12 @@ class MeetingDatesPage { addButton: () => cy.findByTestId('meeting-dates-page__add-btn'), tableRow: (i: number) => cy.get('.meeting-dates__listing > tbody > tr').eq(i), + meetingDateRow: (date: string) => + cy + .get('.meeting-dates__listing > tbody > tr') + .contains(date) + .first() + .parentsUntil('tr'), }; expectTotalMeetingDatesCount(count: number) { @@ -39,8 +45,13 @@ class MeetingDatesPage { this.elements.addButton().should('be.visible').click(); } - clickDeleteRowIcon(i: number) { - this.elements.tableRow(i).find('button').should('be.visible').click(); + deleteMeetingDate(date: string) { + this.elements + .meetingDateRow(date) + .siblings() + .find('button') + .should('be.visible') + .click(); } }