Skip to content

Commit

Permalink
Test switching view (#788)
Browse files Browse the repository at this point in the history
* Test deleting a single report

* Small improvements

* Have proper beforeEach

---------

Co-authored-by: Martijn Dirkse <[email protected]>
  • Loading branch information
mhdirkse and Martijn Dirkse authored Nov 26, 2024
1 parent 41a1d27 commit 0db7e91
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
20 changes: 14 additions & 6 deletions cypress/e2e/debug/deleteReports.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,26 @@ describe('About deleting reports', () => {
cy.createReport();
cy.createOtherReport();
cy.initializeApp();
cy.clearDatabaseStorage();
cy.get('[data-cy-change-view-dropdown]').select('White box');
});

afterEach(() => cy.resetApp());
afterEach(() => {
cy.get('[data-cy-change-view-dropdown]').select('White box');
cy.resetApp()
});

// Should not work with a log storage but should work with a crud storage.
// The system-under-test has to be fixed and then this test should
// be enabled again.
xit('Should delete a single report with the deleteSelected button', () => {
it('Should change view and delete a single report with the deleteSelected button', () => {
cy.get('[data-cy-change-view-dropdown]').select('Database storage');
cy.createReportInDatabaseStorage();
cy.refreshApp();
cy.assertDebugTableLength(1);
cy.createReportInDatabaseStorage();
cy.refreshApp();
cy.assertDebugTableLength(2);
cy.get('[data-cy-debug="selectOne"]').eq(0).click();
cy.get('[data-cy-debug="deleteSelected"]').click();
cy.getDebugTableRows().first().contains('Another simple report');
cy.assertDebugTableLength(1);
});

it ('Should delete all reports with the deleteAll button', () => {
Expand Down
18 changes: 18 additions & 0 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ declare global {

clearTestReports(): Chainable;

clearDatabaseStorage(): Chainable;

navigateToTestTabAndInterceptApiCall(): Chainable;

navigateToDebugTabAndInterceptApiCall(): Chainable;
Expand All @@ -34,6 +36,8 @@ declare global {

createOtherReport(): Chainable;

createReportInDatabaseStorage(): Chainable;

createRunningReport(): Chainable;

createReportWithLabelNull(): Chainable;
Expand Down Expand Up @@ -101,6 +105,12 @@ Cypress.Commands.add('clearTestReports' as keyof Chainable, (): void => {
});
});

Cypress.Commands.add('clearDatabaseStorage' as keyof Chainable, (): void => {
cy.get('[data-cy-change-view-dropdown]').select('Database storage');
cy.get('[data-cy-debug="deleteAll"]').click();
cy.get('[data-cy-delete-modal="confirm"]').click();
})

Cypress.Commands.add('navigateToTestTabAndInterceptApiCall' as keyof Chainable, (): void => {
navigateToTabAndInterceptApiCall('test');
});
Expand Down Expand Up @@ -130,6 +140,14 @@ Cypress.Commands.add('createOtherReport' as keyof Chainable, (): void => {
});
});

Cypress.Commands.add('createReportInDatabaseStorage' as keyof Chainable, (): void => {
// No cy.visit because then the API call can happen multiple times.
cy.request(`${Cypress.env('backendServer')}/index.jsp?createReport=Add%20report%20to%20database%20storage`).then((resp: Cypress.Response<ApiResponse>) => {
expect(resp.status).equal(200);
});
});


Cypress.Commands.add('createRunningReport' as keyof Chainable, (): void => {
cy.request(`${Cypress.env('backendServer')}/index.jsp?createReport=Waiting%20for%20thread%20to%20start`).then(
(resp: Cypress.Response<ApiResponse>): void => {
Expand Down

0 comments on commit 0db7e91

Please sign in to comment.