Skip to content

Commit

Permalink
AKR(Frontend): Fix Cypress tests targeting meeting page [deploy]
Browse files Browse the repository at this point in the history
  • Loading branch information
pkoivisto committed Sep 16, 2024
1 parent b5db7cd commit 8aa222e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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');
Expand All @@ -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ä');

Expand All @@ -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ä');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
}
}

Expand Down

0 comments on commit 8aa222e

Please sign in to comment.