feat(test): add e2e tests for Home

This commit is contained in:
Phan An 2020-12-30 19:44:47 +01:00
parent 9740bf8d12
commit dc180064be
5 changed files with 39 additions and 5 deletions

View file

@ -1,5 +1,3 @@
/// <reference types="cypress" />
context('Authentication', () => {
const submitLoginForm = () => {
cy.get('[type=email]').type('admin@koel.test')
@ -35,7 +33,7 @@ context('Authentication', () => {
it('logs out', () => {
cy.intercept('DELETE', '/api/me', {})
cy.$login('/')
cy.$login()
cy.findByTestId('btn-logout').click()
cy.findByTestId('login-form').should('be.visible')
})

View file

@ -0,0 +1,31 @@
context('Home Screen', () => {
beforeEach(() => {
cy.clock()
cy.$login()
cy.tick(1)
})
it('renders', () => {
cy.get('.screen-header').should('be.visible')
cy.$each([
['.top-song-list', 7],
['.recent-song-list', 7],
['.recently-added-album-list', 6],
['.recently-added-song-list', 10],
['.top-artist-list', 1],
['.top-album-list', 6]
], (selector: string, itemCount: number) => {
cy.get(selector)
.should('exist')
.find('li')
.should('have.length', itemCount)
})
})
it('has a link to view all recently-played songs', () => {
cy.findByTestId('home-view-all-recently-played-btn')
.click()
.url()
.should('contain', '/#!/recently-played')
})
})

View file

@ -11,3 +11,7 @@ Cypress.Commands.add('$login', (redirectTo = '/'): Chainable<AUTWindow> => {
return cy.visit(redirectTo)
})
Cypress.Commands.add('$each', (dataset: Array<Array<any>>, callback: Function) => {
dataset.forEach(args => callback(...args))
})

3
cypress/types.d.ts vendored
View file

@ -2,6 +2,7 @@
declare namespace Cypress {
interface Chainable {
$login(redirectTo: string): Chainable
$login(redirectTo?: string): Chainable
$each(dataset: Array<Array<any>>, callback: Function): void
}
}

@ -1 +1 @@
Subproject commit 9571bb50bb9cb15e943a7586e505d53247b298b5
Subproject commit d8a122ab08535b920616f098838a7139adb7e2e9