Skip to content

Commit

Permalink
Adding some Cypress E2E tests.
Browse files Browse the repository at this point in the history
They might prove useful in the coming migrations. Or unmaintainable. We'll see.
  • Loading branch information
The4thLaw committed Mar 11, 2024
1 parent 564f861 commit 686a80e
Show file tree
Hide file tree
Showing 12 changed files with 2,310 additions and 8 deletions.
7 changes: 7 additions & 0 deletions source/demyo-vue-frontend/cypress.config.mjs
@@ -0,0 +1,7 @@
import { defineConfig } from 'cypress'

export default defineConfig({
e2e: {
baseUrl: 'http://127.0.0.1:1607'
}
})
10 changes: 10 additions & 0 deletions source/demyo-vue-frontend/cypress/.eslintrc.js
@@ -0,0 +1,10 @@
module.exports = {
env: {
mocha: true
},

extends: [
'plugin:cypress/recommended'
],

}
6 changes: 6 additions & 0 deletions source/demyo-vue-frontend/cypress/e2e/001-Home_page.cy.js
@@ -0,0 +1,6 @@
describe('Home page', () => {
it('Show the home page', () => {
cy.visit('/')
cy.assertTitle('Home')
})
})
25 changes: 25 additions & 0 deletions source/demyo-vue-frontend/cypress/e2e/002-Series.cy.js
@@ -0,0 +1,25 @@
describe('Series', () => {
it('Create a series', () => {
// Create the series
cy.visit('/series/new')
cy.getInputByLabel('Name').type('Sample series')
cy.get('button[type="submit"]').click()

// Ensure the page was reloaded
cy.url().should('match', /series\/\d+\/view/)
// Ensure that the encoded data is correct
cy.assertTitle('Sample series')
cy.contains('This series is ongoing').should('exist')
})

it('Deletes an empty series', () => {
cy.visit('/series/2/view')
cy.openQuickTasks()
cy.contains('Delete this series').click()
cy.get('.v-dialog .v-btn.accent').click()
cy.url().should('match', /series$/)
cy.contains('Empty series').should('not.exist')
})

// TODO: https://github.com/The4thLaw/demyo/issues/93
})
33 changes: 33 additions & 0 deletions source/demyo-vue-frontend/cypress/e2e/003-Albums.cy.js
@@ -0,0 +1,33 @@
describe('Albums', () => {
// See https://github.com/The4thLaw/demyo/issues/6
it('Show 0-numbered albums', () => {
cy.visit('/albums/2/view')
cy.contains('0 - Album with number 0').should('exist')
})

// See https://github.com/The4thLaw/demyo/issues/16
it('Show authors when there is only an inker', () => {
cy.visit('/albums/3/view')
cy.contains('Sample Inker').should('exist')
})

// See https://github.com/The4thLaw/demyo/issues/16
it('Show authors when there is only a translator', () => {
cy.visit('/albums/4/view')
cy.contains('Sample Translator').should('exist')
})

// See https://github.com/The4thLaw/demyo/issues/77
it('Show an error message when creating without a publisher', () => {
cy.visit('/albums/new')
cy.get('.v-btn.accent').click()
cy.contains('Publisher').parents('.v-input').contains('This field cannot be empty')
})

// See https://github.com/The4thLaw/demyo/issues/88
it('Prevents deletion of an album with a derivative', () => {
cy.visit('/albums/1/view')
cy.openQuickTasks()
cy.contains('Delete this album').should('not.exist')
})
})
16 changes: 16 additions & 0 deletions source/demyo-vue-frontend/cypress/e2e/004-Authors.cy.js
@@ -0,0 +1,16 @@
describe('Authors', () => {
it('Create an author', () => {
// Create the author
cy.visit('/authors/new')
cy.getInputByLabel('First name').type('John')
cy.getInputByLabel('Name').type('Doe')
cy.get('button[type="submit"]').click()

// Ensure the page was reloaded
cy.url().should('match', /authors\/\d+\/view/)
// Ensure that the encoded data is correct
cy.assertTitle('John Doe')
cy.contains('You have no albums by this author').should('exist')
cy.contains('You have no derivatives by this author').should('exist')
})
})
9 changes: 9 additions & 0 deletions source/demyo-vue-frontend/cypress/e2e/006-Tags.cy.js
@@ -0,0 +1,9 @@
describe('Tags', () => {
it('List the tags', () => {
cy.visit('/tags')
// Tags should be listed without error
cy.get('.d-Tag').should('have.length', 1)
// The SF tag should have one occurrence
cy.contains('science-fiction').find('.d-Tag__count').should('have.text', '1')
})
})
Binary file not shown.
41 changes: 41 additions & 0 deletions source/demyo-vue-frontend/cypress/support/commands.js
@@ -0,0 +1,41 @@
Cypress.Commands.add('initDatabase', () => {
return cy.fixture('demyo-cypress-data-set.dea', 'binary')
.then(binary => Cypress.Blob.binaryStringToBlob(binary))
.then(blob => {
var formdata = new FormData()
formdata.append('importFile', blob, 'demyo-cypress.dea')

cy.request({
url: '/api/manage/import',
method: 'POST',
headers: {
'Content-Type': 'multipart/form-data'
},
body: formdata
}).its('status').should('be.equal', 200)
})
})

Cypress.Commands.add('selectReader', () => {
return cy.request({
method: 'GET',
url: '/api/readers/1'
})
.then(resp => {
console.log('Cypress reader is', resp.body)
window.localStorage.setItem('currentReader', JSON.stringify(resp.body))
})
})

Cypress.Commands.add('getInputByLabel', (label) => {
return cy.contains(label).parents('.v-input').find('input')
})

Cypress.Commands.add('openQuickTasks', () => {
cy.get('.v-app-bar i.mdi-dots-vertical').click()
})

Cypress.Commands.add('assertTitle', (title) => {
cy.title().should('include', title)
cy.get('.v-toolbar__title').should('have.text', title)
})
13 changes: 13 additions & 0 deletions source/demyo-vue-frontend/cypress/support/e2e.js
@@ -0,0 +1,13 @@
// This file is processed and oaded automatically before all test files.
//
// This is a great place to put global configuration and behavior that modifies Cypress.

import './commands'

before(() => {
cy.initDatabase().then(() => {
cy.selectReader()
})
})

// TODO: https://github.com/The4thLaw/demyo/issues/20

0 comments on commit 686a80e

Please sign in to comment.