Skip to content

Commit

Permalink
fix(e2e): fix e2e tests in dh and editor
Browse files Browse the repository at this point in the history
  • Loading branch information
cmoinier committed Nov 28, 2023
1 parent 8c497f9 commit 1a4de41
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 25 deletions.
2 changes: 1 addition & 1 deletion apps/datahub-e2e/src/e2e/datasetDetailPage.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 5 additions & 4 deletions apps/datahub-e2e/src/e2e/home.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -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 ')
})
Expand Down
10 changes: 5 additions & 5 deletions apps/metadata-editor-e2e/src/e2e/dashboard.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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')
Expand All @@ -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',
Expand All @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion apps/metadata-editor-e2e/src/e2e/my-org.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
31 changes: 17 additions & 14 deletions apps/metadata-editor-e2e/src/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,32 @@
declare namespace Cypress {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
interface Chainable<Subject> {
// 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('/')
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
</div>
<div
class="text-right col-start-3 row-start-4 sm:absolute sm:col-start-2 sm:row-start-1 sm:top-[-1.125em] sm:right-[0.4em]"
data-cy="recordFav"
>
<ng-container
[ngTemplateOutlet]="favoriteTemplate"
Expand Down

0 comments on commit 1a4de41

Please sign in to comment.