Skip to content

Commit

Permalink
fixed e2e test (#2472)
Browse files Browse the repository at this point in the history
* fixed e2e test
  • Loading branch information
adamhaeger authored Sep 20, 2024
1 parent d8cdb14 commit e96ea2b
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 86 deletions.
30 changes: 1 addition & 29 deletions test/e2e/integration/component-library/address.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,8 @@
import { fillInAddressAndVerify } from 'test/e2e/integration/component-library/utils/fillAddressAndVerify';
import { AppFrontend } from 'test/e2e/pageobjects/app-frontend';

const appFrontend = new AppFrontend();

export const fillInAddressAndVerify = (address: string, co: string, zip: string, houseNumber: string) => {
cy.gotoNavPage('Adresse');
cy.get('#address_address_AddressPage-Address').type(address);
cy.get('#address_care_of_AddressPage-Address').type(co);
cy.get('#address_zip_code_AddressPage-Address').type(zip);
cy.get('#address_house_number_AddressPage-Address').type(houseNumber);

// Verify Gateadresse (Street address)
cy.get('[data-testid="summary-single-value-component"]')
.eq(0)
.find('span.fds-paragraph')
.should('have.text', address);

// Verify C/O eller annan tilleggsadresse (C/O or additional address)
cy.get('[data-testid="summary-single-value-component"]').eq(1).find('span.fds-paragraph').should('have.text', co);

// Verify Postnr (Postal code)
cy.get('[data-testid="summary-single-value-component"]').eq(2).find('span.fds-paragraph').should('have.text', zip);

// Verify Poststad (City)
cy.get('[data-testid="summary-single-value-component"]').eq(3).find('span.fds-paragraph').should('have.text', 'OSLO');

// Verify Bustadnummer (House number)
cy.get('[data-testid="summary-single-value-component"]')
.eq(4)
.find('span.fds-paragraph')
.should('have.text', houseNumber);
};

describe('Address component', () => {
it('Should focus the correct element when navigating from an error', () => {
cy.startAppInstance(appFrontend.apps.componentLibrary, { authenticationLevel: '2' });
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/integration/component-library/dropdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe('Dropdown component', () => {
const testText = 'Moped';

cy.startAppInstance(appFrontend.apps.componentLibrary, { authenticationLevel: '2' });
cy.gotoNavPage('DropdownPage');
cy.gotoNavPage('Dropdown');
cy.get('#form-content-DropdownPage-RadioButtons').click();
cy.get('div[role="listbox"]').contains('span', testText).click();
cy.get('[data-testid="summary-single-value-component"]')
Expand Down
49 changes: 4 additions & 45 deletions test/e2e/integration/component-library/fileupload.ts
Original file line number Diff line number Diff line change
@@ -1,52 +1,11 @@
import {
uploadFileAndVerify,
uploadFileWithTagAndVerify,
} from 'test/e2e/integration/component-library/utils/uploadFileAndVerify';
import { AppFrontend } from 'test/e2e/pageobjects/app-frontend';

const appFrontend = new AppFrontend();

const makeTestFile = (fileName: string) => ({
fileName,
mimeType: 'application/pdf',
lastModified: Date.now(),
contents: Cypress.Buffer.from('hello world'),
});

export const uploadFileAndVerify = (fileName: string) => {
cy.gotoNavPage('FileUploadPage');
cy.get('[data-componenttype="FileUpload"]').first().should('be.visible');

cy.get('[data-componenttype="FileUpload"]')
.first()
.find('input[type="file"]')
.selectFile(makeTestFile(fileName), { force: true });

cy.get('[data-testid="file-upload-table-summary"]').first().should('be.visible');
cy.get('[data-testid="file-upload-table-summary"]')
.first()
.find('tr')
.find('td')
.contains('td', 'uploadThis.pdf')
.should('exist');
};

export const uploadFileWithTagAndVerify = (fileName: string, fileType: string) => {
cy.gotoNavPage('FileUploadPage');
cy.get('[data-componenttype="FileUploadWithTag"]').first().should('be.visible');
cy.get('[data-componenttype="FileUploadWithTag"]')
.first()
.find('input[type="file"]')
.selectFile(makeTestFile(fileName), { force: true });
cy.contains('label', 'Filtype').click();
cy.get('div[role="listbox"]').contains('span', fileType).click();
cy.get('input[id^="attachment-tag-dropdown-"]').should(($input) => {
expect($input.val()).to.eq(fileType);
});
cy.get('button[id^=attachment-save-tag-button]').click();

cy.get('[data-testid="tagFile-summary"]').first().should('be.visible');
cy.get('[data-testid="tagFile-summary"]').first().find('tr').find('td').contains('td', fileName).should('exist');

cy.get('[data-testid="tagFile-summary"]').first().find('tr').find('td').contains('td', fileType).should('exist');
};

describe('FileUpload summary test', () => {
beforeEach(() => {
cy.startAppInstance(appFrontend.apps.componentLibrary, { authenticationLevel: '2' });
Expand Down
7 changes: 1 addition & 6 deletions test/e2e/integration/component-library/input.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import { fillInInputAndVerify } from 'test/e2e/integration/component-library/utils/inputAndVerify';
import { AppFrontend } from 'test/e2e/pageobjects/app-frontend';

const appFrontend = new AppFrontend();

export const fillInInputAndVerify = (text: string) => {
cy.gotoNavPage('Kort svar');
cy.get('#InputPage-Input').type(text);
cy.get('[data-testid="summary-single-value-component"]').eq(0).find('span.fds-paragraph').should('have.text', text);
};

describe('Input component', () => {
it('Renders the summary2 component with correct text', () => {
cy.startAppInstance(appFrontend.apps.componentLibrary, { authenticationLevel: '2' });
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/integration/component-library/multiple-select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const appFrontend = new AppFrontend();
describe('Multiple select component', () => {
it('Renders the summary2 component with correct text for MultipleSelext', () => {
cy.startAppInstance(appFrontend.apps.componentLibrary, { authenticationLevel: '2' });
cy.gotoNavPage('MultipleSelectPage');
cy.gotoNavPage('Flervalg');

// Define the text for the last three checkboxes

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { fillInAddressAndVerify } from 'test/e2e/integration/component-library/address';
import { uploadFileAndVerify, uploadFileWithTagAndVerify } from 'test/e2e/integration/component-library/fileupload';
import { fillInInputAndVerify } from 'test/e2e/integration/component-library/input';
import { fillInAddressAndVerify } from 'test/e2e/integration/component-library/utils/fillAddressAndVerify';
import { fillInInputAndVerify } from 'test/e2e/integration/component-library/utils/inputAndVerify';
import {
uploadFileAndVerify,
uploadFileWithTagAndVerify,
} from 'test/e2e/integration/component-library/utils/uploadFileAndVerify';
import { AppFrontend } from 'test/e2e/pageobjects/app-frontend';

const appFrontend = new AppFrontend();
Expand All @@ -23,7 +26,7 @@ describe('Render summary of previous task', () => {
uploadFileAndVerify(fileName);
uploadFileWithTagAndVerify(fileName, fileType);

cy.get('#navigation-menu').find('button').contains('15. Oppsummering 2.0').click();
cy.get('#navigation-menu').find('button').contains('16. Oppsummering 2.0').click();

cy.contains('button', 'Send inn').click();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
export const fillInAddressAndVerify = (address: string, co: string, zip: string, houseNumber: string) => {
cy.gotoNavPage('Adresse');
cy.get('#address_address_AddressPage-Address').type(address);
cy.get('#address_care_of_AddressPage-Address').type(co);
cy.get('#address_zip_code_AddressPage-Address').type(zip);
cy.get('#address_house_number_AddressPage-Address').type(houseNumber);

// Verify Gateadresse (Street address)
cy.get('[data-testid="summary-single-value-component"]')
.eq(0)
.find('span.fds-paragraph')
.should('have.text', address);

// Verify C/O eller annan tilleggsadresse (C/O or additional address)
cy.get('[data-testid="summary-single-value-component"]').eq(1).find('span.fds-paragraph').should('have.text', co);

// Verify Postnr (Postal code)
cy.get('[data-testid="summary-single-value-component"]').eq(2).find('span.fds-paragraph').should('have.text', zip);

// Verify Poststad (City)
cy.get('[data-testid="summary-single-value-component"]').eq(3).find('span.fds-paragraph').should('have.text', 'OSLO');

// Verify Bustadnummer (House number)
cy.get('[data-testid="summary-single-value-component"]')
.eq(4)
.find('span.fds-paragraph')
.should('have.text', houseNumber);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const fillInInputAndVerify = (text: string) => {
cy.gotoNavPage('Kort svar');
cy.get('#InputPage-Input').type(text);
cy.get('[data-testid="summary-single-value-component"]').eq(0).find('span.fds-paragraph').should('have.text', text);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
export const makeTestFile = (fileName: string) => ({
fileName,
mimeType: 'application/pdf',
lastModified: Date.now(),
contents: Cypress.Buffer.from('hello world'),
});

export const uploadFileAndVerify = (fileName: string) => {
cy.gotoNavPage('Filopplasting');
cy.get('[data-componenttype="FileUpload"]').first().should('be.visible');

cy.get('[data-componenttype="FileUpload"]')
.first()
.find('input[type="file"]')
.selectFile(makeTestFile(fileName), { force: true });

cy.get('[data-testid="file-upload-table-summary"]').first().should('be.visible');
cy.get('[data-testid="file-upload-table-summary"]')
.first()
.find('tr')
.find('td')
.contains('td', 'uploadThis.pdf')
.should('exist');
};

export const uploadFileWithTagAndVerify = (fileName: string, fileType: string) => {
cy.gotoNavPage('Filopplasting');
cy.get('[data-componenttype="FileUploadWithTag"]').first().should('be.visible');
cy.get('[data-componenttype="FileUploadWithTag"]')
.first()
.find('input[type="file"]')
.selectFile(makeTestFile(fileName), { force: true });
cy.contains('label', 'Filtype').click();
cy.get('div[role="listbox"]').contains('span', fileType).click();
cy.get('input[id^="attachment-tag-dropdown-"]').should(($input) => {
expect($input.val()).to.eq(fileType);
});
cy.get('button[id^=attachment-save-tag-button]').click();

cy.get('[data-testid="tagFile-summary"]').first().should('be.visible');
cy.get('[data-testid="tagFile-summary"]').first().find('tr').find('td').contains('td', fileName).should('exist');

cy.get('[data-testid="tagFile-summary"]').first().find('tr').find('td').contains('td', fileType).should('exist');
};

0 comments on commit e96ea2b

Please sign in to comment.