Cypress-IDs and prettier for tests (#1634)

* Add cy.getById method and run prettier

Signed-off-by: Erik Michelson <github@erik.michelson.eu>
This commit is contained in:
Erik Michelson 2021-11-19 18:04:04 +01:00 committed by GitHub
parent 8a8bacc0aa
commit d725b65140
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
53 changed files with 758 additions and 1203 deletions

View file

@ -11,12 +11,12 @@ describe('History', () => {
})
it('Cards', () => {
cy.get('div.card').should('be.visible')
cy.getById('history-card').should('be.visible')
})
it('Table', () => {
cy.get('[data-cypress-id="history-mode-table"]').click()
cy.get('[data-cypress-id="history-table"]').should('be.visible')
cy.getById('history-mode-table').click()
cy.getById('history-table').should('be.visible')
})
})
@ -39,13 +39,13 @@ describe('History', () => {
})
it('in table view', () => {
cy.get('[data-cypress-id="history-mode-table"]').click()
cy.get('[data-cypress-id="history-table"]').should('be.visible')
cy.get('[data-cypress-id="history-entry-title"]').contains('Features')
cy.getById('history-mode-table').click()
cy.getById('history-table').should('be.visible')
cy.getById('history-entry-title').contains('Features')
})
it('in cards view', () => {
cy.get('[data-cypress-id="history-entry-title"]').contains('Features')
cy.getById('history-entry-title').contains('Features')
})
})
describe('is untitled when not empty', () => {
@ -66,13 +66,13 @@ describe('History', () => {
})
it('in table view', () => {
cy.get('[data-cypress-id="history-mode-table"]').click()
cy.get('[data-cypress-id="history-table"]').should('be.visible')
cy.get('[data-cypress-id="history-entry-title"]').contains('Untitled')
cy.getById('history-mode-table').click()
cy.getById('history-table').should('be.visible')
cy.getById('history-entry-title').contains('Untitled')
})
it('in cards view', () => {
cy.get('[data-cypress-id="history-entry-title"]').contains('Untitled')
cy.getById('history-entry-title').contains('Untitled')
})
})
})
@ -90,15 +90,15 @@ describe('History', () => {
})
it('Cards', () => {
cy.get('div.card').should('be.visible')
cy.get('.history-pin.btn').first().as('pin-button')
cy.getById('history-card').should('be.visible')
cy.getById('history-entry-pin-button').first().as('pin-button')
cy.get('@pin-button').should('have.class', 'pinned').click()
cy.get('@pin-button').should('not.have.class', 'pinned')
})
it('Table', () => {
cy.get('i.fa-table').click()
cy.get('.history-pin.btn').first().as('pin-button')
cy.getById('history-mode-table').click()
cy.getById('history-entry-pin-button').first().as('pin-button')
cy.get('@pin-button').should('have.class', 'pinned').click()
cy.get('@pin-button').should('not.have.class', 'pinned')
})
@ -112,15 +112,15 @@ describe('History', () => {
})
it('Cards', () => {
cy.get('div.card').should('be.visible')
cy.get('.fa-thumb-tack').first().click()
cy.get('.notifications-area .toast').should('be.visible')
cy.getById('history-card').should('be.visible')
cy.getById('history-entry-pin-button').first().click()
cy.getById('notification-toast').should('be.visible')
})
it('Table', () => {
cy.get('i.fa-table').click()
cy.get('.fa-thumb-tack').first().click()
cy.get('.notifications-area .toast').should('be.visible')
cy.getById('history-mode-table').click()
cy.getById('history-entry-pin-button').first().click()
cy.getById('notification-toast').should('be.visible')
})
})
})
@ -136,43 +136,37 @@ describe('History', () => {
})
it('works with valid file', () => {
cy.get('[data-cypress-id="import-history-file-button"]').click()
cy.get('[data-cypress-id="import-history-file-input"]').attachFile({
cy.getById('import-history-file-button').click()
cy.getById('import-history-file-input').attachFile({
filePath: 'history.json',
mimeType: 'application/json'
})
cy.get('[data-cypress-id="history-entry-title"]')
.should('have.length', 1)
.contains('cy-Test')
cy.getById('history-entry-title').should('have.length', 1).contains('cy-Test')
})
it('fails on invalid file', () => {
cy.get('[data-cypress-id="import-history-file-button"]').click()
cy.get('[data-cypress-id="import-history-file-input"]').attachFile({
cy.getById('import-history-file-button').click()
cy.getById('import-history-file-input').attachFile({
filePath: 'history.json.license',
mimeType: 'text/plain'
})
cy.get('[data-cypress-id="notification-toast"]').should('be.visible')
cy.getById('notification-toast').should('be.visible')
})
it('works when selecting two files with the same name', () => {
cy.get('[data-cypress-id="import-history-file-button"]').click()
cy.get('[data-cypress-id="import-history-file-input"]').attachFile({
cy.getById('import-history-file-button').click()
cy.getById('import-history-file-input').attachFile({
filePath: 'history.json',
mimeType: 'application/json'
})
cy.get('[data-cypress-id="history-entry-title"]')
.should('have.length', 1)
.contains('cy-Test')
cy.get('[data-cypress-id="import-history-file-button"]').click()
cy.get('[data-cypress-id="import-history-file-input"]').attachFile({
cy.getById('history-entry-title').should('have.length', 1).contains('cy-Test')
cy.getById('import-history-file-button').click()
cy.getById('import-history-file-input').attachFile({
filePath: 'history-2.json',
fileName: 'history.json',
mimeType: 'application/json'
})
cy.get('[data-cypress-id="history-entry-title"]')
.should('have.length', 2)
.contains('cy-Test2')
cy.getById('history-entry-title').should('have.length', 2).contains('cy-Test2')
})
})
})