Skip to content

Commit

Permalink
feat: imrove e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
f-necas committed Aug 29, 2023
1 parent 0bae712 commit b191cb8
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 39 deletions.
82 changes: 45 additions & 37 deletions apps/metadata-editor-e2e/src/e2e/home.cy.ts
Original file line number Diff line number Diff line change
@@ -1,54 +1,62 @@
describe('header', () => {
const fakeUser = {
username: 'user',
password: 'Abcde12!',
email: '[email protected]',
name: 'Homer',
surname: 'Simpson',
}
const fakeUser = {
username: 'user',
password: 'Abcde12!',
email: '[email protected]',
name: 'Homer',
surname: 'Simpson',
}

before(() => {
cy.visit('/geonetwork')
cy.get('.cookie-warning-actions').find('button').eq(0).click()
cy.scrollTo('top')
cy.loginGN('admin', 'admin', false)
cy.get('a[title="Admin console"]').click()
cy.get('.fa-group').click()
cy.get('#gn-btn-user-add').click()
cy.get('#username').type(fakeUser.username)
cy.get('#gn-user-password').type(fakeUser.password)
cy.get('#gn-user-password2').type(fakeUser.password)
cy.get('[name="name"]').type(fakeUser.name)
cy.get('[name="surname"]').type(fakeUser.surname)
cy.get('[name="email"]').type(fakeUser.email)
cy.get('.fa-save').click()
})
const gnBaseUrl = 'http://localhost:8080/geonetwork/srv/eng/'

describe('avatar', () => {
describe('display avatar for user without gravatar hash', () => {
it('should display placeholder url', () => {
cy.loginGN('admin', 'admin', false)
cy.visit(`${gnBaseUrl}admin.console#/organization`)
cy.get('#gn-btn-user-add').click()
cy.get('#username').type(fakeUser.username)
cy.get('#gn-user-password').type(fakeUser.password)
cy.get('#gn-user-password2').type(fakeUser.password)
cy.get('[name="name"]').type(fakeUser.name)
cy.get('[name="surname"]').type(fakeUser.surname)
cy.get('[name="email"]').type(fakeUser.email)
cy.get('.fa-save').click()

cy.visit(`${gnBaseUrl}admin.console#/settings`)
cy.get('[id="system/users/identicon"]').type('{selectAll}{del}')
cy.get('#gn-btn-settings-save').click()

describe('general display', () => {
it('should display the correct placeholder and profile picture', () => {
cy.visit('/')
cy.get('gn-ui-avatar')
.children('img')
.should('have.attr', 'src')
.should('eq', 'https://www.gravatar.com/avatar/?d=mp')
cy.signOutGN()
})
it('should display monsterid', () => {
cy.loginGN('admin', 'admin', false)
cy.visit(`${gnBaseUrl}admin.console#/settings`)
cy.get('[id="system/users/identicon"]').type(
'{selectAll}gravatar:monsterid'
)
cy.get('#gn-btn-settings-save').click()

cy.visit('/')
cy.get('gn-ui-avatar')
.children('img')
.should('have.attr', 'src')
.should('eq', 'https://www.gravatar.com/avatar/?d=monsterid')
})
})
describe('display avatar for user with hash', () => {
it('should display the correct profile picture', () => {
cy.loginGN(fakeUser.username, fakeUser.password)
cy.get('gn-ui-avatar')
.children('img')
.should('have.attr', 'src')
.should(
'eq',
'https://www.gravatar.com/avatar/09abd59eb5653a7183ba812b8261f48b?d=mp'
'https://www.gravatar.com/avatar/09abd59eb5653a7183ba812b8261f48b?d=monsterid'
)
cy.signOutGN()

cy.get('a[title="Admin console"]').click()
cy.get('.fa-gear').click()
cy.get('[id="system/users/identicon"]').type(
'{selectAll}gravatar:monsteridc'
)
cy.get('#gn-btn-settings-save').click()
cy.visit('/')
})
})
})
11 changes: 9 additions & 2 deletions apps/metadata-editor-e2e/src/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@ declare namespace Cypress {
Cypress.Commands.add(
'loginGN',
(username: string, password: string, redirect = true) => {
cy.visit('/geonetwork')
cy.visit('http://localhost:8080/geonetwork/srv/eng/catalog.search#/home')
cy.get('.cookie-warning-actions').then(($cookie) => {
if ($cookie.is(':visible')) {
$cookie.find('button').eq(0).click()
cy.scrollTo('top')
}
})
cy.wait(250)

Check failure on line 36 in apps/metadata-editor-e2e/src/support/commands.ts

View workflow job for this annotation

GitHub Actions / Format check, lint, unit tests

Do not wait for arbitrary time periods
cy.get('li.signin-dropdown').click()
cy.get('#inputUsername').type(username)
cy.get('#inputPassword').type(password)
Expand All @@ -36,7 +43,7 @@ Cypress.Commands.add(
)

Cypress.Commands.add('signOutGN', () => {
cy.visit('/geonetwork')
cy.visit('http://localhost:8080/geonetwork/srv/eng/catalog.search#/home')
cy.get('a[title="User details"]').click()
cy.get('a[title="Sign out"]').click()
})
Expand Down

0 comments on commit b191cb8

Please sign in to comment.