From 1a4de41739ec63ae7a99bdb8850721eb1e9cf0ee Mon Sep 17 00:00:00 2001 From: Camille Moinier Date: Tue, 28 Nov 2023 11:11:52 +0100 Subject: [PATCH] fix(e2e): fix e2e tests in dh and editor --- .../src/e2e/datasetDetailPage.cy.ts | 2 +- apps/datahub-e2e/src/e2e/home.cy.ts | 9 +++--- .../src/e2e/dashboard.cy.ts | 10 +++--- apps/metadata-editor-e2e/src/e2e/my-org.cy.ts | 2 +- .../src/support/commands.ts | 31 ++++++++++--------- .../record-preview-row.component.html | 1 + 6 files changed, 30 insertions(+), 25 deletions(-) diff --git a/apps/datahub-e2e/src/e2e/datasetDetailPage.cy.ts b/apps/datahub-e2e/src/e2e/datasetDetailPage.cy.ts index d2ebe0edd2..0a0c695e94 100644 --- a/apps/datahub-e2e/src/e2e/datasetDetailPage.cy.ts +++ b/apps/datahub-e2e/src/e2e/datasetDetailPage.cy.ts @@ -385,7 +385,7 @@ describe('dataset pages', () => { }) }) it('displays the full list after clicking two times on one filter', () => { - cy.get('gn-ui-data-downloads') + cy.get('datahub-record-downloads') .find('gn-ui-button') .children('button') .eq(1) diff --git a/apps/datahub-e2e/src/e2e/home.cy.ts b/apps/datahub-e2e/src/e2e/home.cy.ts index 12952662a2..46883d3de6 100644 --- a/apps/datahub-e2e/src/e2e/home.cy.ts +++ b/apps/datahub-e2e/src/e2e/home.cy.ts @@ -22,8 +22,7 @@ describe('header', () => { cy.get('[data-cy="addMoreBtn"]').should('be.visible') }) it('should display the orga and dataset link buttons', () => { - cy.get('[ng-reflect-title="datasets"]').should('be.visible') - cy.get('[ng-reflect-title="organisations"]').should('be.visible') + cy.get('gn-ui-figure').should('have.length', 2) }) describe('news feed display', () => { @@ -35,12 +34,14 @@ describe('header', () => { describe('link buttons display', () => { it('datasets : should display the icon', () => { - cy.get('[ng-reflect-title="datasets"]') + cy.get('gn-ui-figure') + .eq(0) .find('mat-icon') .should('have.text', ' folder_open ') }) it('organisations : should display the icon', () => { - cy.get('[ng-reflect-title="organisations"]') + cy.get('gn-ui-figure') + .eq(1) .find('mat-icon') .should('have.text', ' corporate_fare ') }) diff --git a/apps/metadata-editor-e2e/src/e2e/dashboard.cy.ts b/apps/metadata-editor-e2e/src/e2e/dashboard.cy.ts index 14a5261f2e..3c5bc66df5 100644 --- a/apps/metadata-editor-e2e/src/e2e/dashboard.cy.ts +++ b/apps/metadata-editor-e2e/src/e2e/dashboard.cy.ts @@ -42,7 +42,7 @@ describe('dashboard', () => { cy.visit('/records/all') cy.get('gn-ui-record-table') .find('.record-table-col') - .first() + .eq(1) .invoke('text') .then((list) => { originalFirstItem = list.trim() @@ -52,7 +52,7 @@ describe('dashboard', () => { // cy.wait(500) cy.get('gn-ui-record-table') .find('.record-table-col') - .first() + .eq(1) .invoke('text') .then((list) => { newFirstItem = list.trim() @@ -71,7 +71,7 @@ describe('dashboard', () => { cy.visit('/records/all') cy.get('gn-ui-record-table') .find('.record-table-col') - .get('[type="checkbox"]') + .get('gn-ui-checkbox') .eq(2) .click() cy.get('.selected-records').contains('1 selected') @@ -81,7 +81,7 @@ describe('dashboard', () => { cy.visit('/records/all') cy.get('gn-ui-record-table') .find('.record-table-col') - .get('mat-checkbox.mat-primary') + .get('gn-ui-checkbox') .each(($checkbox) => cy.wrap($checkbox).click()) cy.get('.records-information').should( 'not.have.descendants', @@ -93,7 +93,7 @@ describe('dashboard', () => { cy.visit('/records/all') cy.get('gn-ui-record-table') .find('.record-table-col') - .get('mat-checkbox.mat-primary') + .get('gn-ui-checkbox') .first() .click() cy.get('.selected-records').contains('12 selected') diff --git a/apps/metadata-editor-e2e/src/e2e/my-org.cy.ts b/apps/metadata-editor-e2e/src/e2e/my-org.cy.ts index 620a5b5fff..5d93e32ec0 100644 --- a/apps/metadata-editor-e2e/src/e2e/my-org.cy.ts +++ b/apps/metadata-editor-e2e/src/e2e/my-org.cy.ts @@ -3,7 +3,7 @@ describe('my-org', () => { cy.loginGN('barbie', 'p4ssworD_', false) cy.intercept({ method: 'GET', - url: 'http://localhost:4200/geonetwork/srv/api/userselections/0/101', + url: '/geonetwork/srv/api/userselections/0/101', }).as('dataGetFirst') cy.visit(`/records/my-org`) cy.get('md-editor-dashboard-menu').find('a').first().click() diff --git a/apps/metadata-editor-e2e/src/support/commands.ts b/apps/metadata-editor-e2e/src/support/commands.ts index 85cc534619..fa04f99e13 100644 --- a/apps/metadata-editor-e2e/src/support/commands.ts +++ b/apps/metadata-editor-e2e/src/support/commands.ts @@ -13,29 +13,32 @@ declare namespace Cypress { // eslint-disable-next-line @typescript-eslint/no-unused-vars interface Chainable { - // login(email: string, password: string): void loginGN(username: string, password: string, redirect?: boolean): void signOutGN(): void } } -// -// -- This is a parent command -- -/*Cypress.Commands.add('login', (email, password) => { - console.log('Custom command example: Login', email, password) -})*/ Cypress.Commands.add( 'loginGN', (username: string, password: string, redirect = true) => { - Cypress.on('uncaught:exception', (err) => { - if (err.message.includes('Jsonix')) return false - if (err.message.includes('postMessage')) return false + // first request to get the XSRF cookie + cy.request({ + method: 'GET', + url: '/geonetwork/srv/api/me', + headers: { + Accept: 'application/json, text/plain, */*', + }, + }) + cy.getCookie('XSRF-TOKEN').then((xsrfTokenCookie) => { + cy.request({ + method: 'POST', + url: '/geonetwork/signin', + body: `username=${username}&password=${password}&_csrf=${xsrfTokenCookie.value}`, + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + }, + }) }) - - cy.visit('/geonetwork/srv/eng/catalog.signin?debug') // this will point to a 404 - cy.get('#inputUsername').type(username, { force: true }) - cy.get('#inputPassword').type(password, { force: true }) - cy.get('[name="gnSigninForm"]').submit() if (redirect) cy.visit('/') } ) diff --git a/libs/ui/search/src/lib/record-preview-row/record-preview-row.component.html b/libs/ui/search/src/lib/record-preview-row/record-preview-row.component.html index 4506863177..432dfe6b26 100644 --- a/libs/ui/search/src/lib/record-preview-row/record-preview-row.component.html +++ b/libs/ui/search/src/lib/record-preview-row/record-preview-row.component.html @@ -67,6 +67,7 @@