fix: favorite integration tests

This commit is contained in:
Phan An 2022-04-26 15:48:42 +03:00
parent c2426c1f20
commit a1b5432c03
No known key found for this signature in database
GPG key ID: A81E4477F0BB6FDC
4 changed files with 35 additions and 40 deletions

View file

@ -8,12 +8,9 @@ context('Favorites', { scrollBehavior: false }, () => {
.within(() => {
cy.findByText('Songs You Love').should('be.visible')
cy.findByText('Download All').should('be.visible')
cy.get('.song-item').should('have.length', 3)
.each(row => {
cy.wrap(row)
.get('[data-test=btn-like-liked]')
.should('be.visible')
})
cy.$getVisibleSongRows().should('have.length', 3)
.each(row => cy.wrap(row).get('[data-test=btn-like-liked]').should('be.visible'))
})
})
@ -26,10 +23,11 @@ context('Favorites', { scrollBehavior: false }, () => {
cy.get('#songsWrapper')
.within(() => {
cy.get('.song-item:first-child [data-test=like-btn]')
.within(() => cy.get('[data-test=btn-like-unliked]').should('be.visible'))
.click()
.within(() => cy.get('[data-test=btn-like-liked]').should('be.visible'))
cy.$getVisibleSongRows().first().within(() => {
cy.get('[data-test=like-btn]')
.within(() => cy.get('[data-test=btn-like-unliked]').should('be.visible')).click()
.within(() => cy.get('[data-test=btn-like-liked]').should('be.visible'))
})
})
cy.$assertFavoriteSongCount(4)
@ -44,12 +42,10 @@ context('Favorites', { scrollBehavior: false }, () => {
cy.get('#songsWrapper')
.within(() => {
cy.get('.song-item:first-child').click()
cy.$getVisibleSongRows().first().click()
cy.get('[data-test=add-to-btn]').click()
cy.get('[data-test=add-to-menu]')
.should('be.visible')
.within(() => cy.findByText('Favorites').click())
.should('not.be.visible')
cy.get('[data-test=add-to-menu]').should('be.visible')
.within(() => cy.findByText('Favorites').click()).should('not.be.visible')
})
cy.$assertFavoriteSongCount(4)
@ -61,12 +57,12 @@ context('Favorites', { scrollBehavior: false }, () => {
cy.get('#favoritesWrapper')
.within(() => {
cy.get('.song-item:first-child')
.should('contain.text', 'November')
cy.$getVisibleSongRows().should('have.length', 3)
.first().should('contain.text', 'November')
.within(() => cy.get('[data-test=like-btn]').click())
cy.get('.song-item').should('have.length', 2)
cy.get('.song-item:first-child').should('not.contain.text', 'November')
cy.$getVisibleSongRows().should('have.length', 2)
.first().should('not.contain.text', 'November')
})
})
@ -76,13 +72,12 @@ context('Favorites', { scrollBehavior: false }, () => {
cy.get('#favoritesWrapper')
.within(() => {
cy.get('.song-item:first-child')
.should('contain.text', 'November')
.click()
.type('{backspace}')
cy.$getVisibleSongRows().should('have.length', 3)
.first().should('contain.text', 'November')
.click().type('{backspace}')
cy.get('.song-item').should('have.length', 2)
cy.get('.song-item:first-child').should('not.contain.text', 'November')
cy.$getVisibleSongRows().should('have.length', 2)
.first().should('not.contain.text', 'November')
})
})
})

View file

@ -3,7 +3,7 @@ import 'cypress-file-upload'
import Chainable = Cypress.Chainable
import scrollBehaviorOptions = Cypress.scrollBehaviorOptions
Cypress.Commands.add('$login', (options: Partial<LoginOptions> = {}): Chainable<Cypress.AUTWindow> => {
Cypress.Commands.add('$login', (options: Partial<LoginOptions> = {}) => {
window.localStorage.setItem('api-token', 'mock-token')
const mergedOptions = Object.assign({
@ -30,7 +30,7 @@ Cypress.Commands.add('$login', (options: Partial<LoginOptions> = {}): Chainable<
return win
})
Cypress.Commands.add('$loginAsNonAdmin', (options: Partial<LoginOptions> = {}): Chainable<Cypress.AUTWindow> => {
Cypress.Commands.add('$loginAsNonAdmin', (options: Partial<LoginOptions> = {}) => {
options.asAdmin = false
return cy.$login(options)
})
@ -47,7 +47,7 @@ Cypress.Commands.add('$findInTestId', (selector: string) => {
return cy.findByTestId(testId.trim()).find(rest.join(' '))
})
Cypress.Commands.add('$clickSidebarItem', (sidebarItemText: string): Chainable<JQuery> => {
Cypress.Commands.add('$clickSidebarItem', (sidebarItemText: string) => {
return cy.get('#sidebar')
.findByText(sidebarItemText)
.click()
@ -72,10 +72,8 @@ Cypress.Commands.add('$shuffleSeveralSongs', (count = 3) => {
cy.$clickSidebarItem('All Songs')
cy.get('#songsWrapper').within(() => {
cy.get('.vue-recycle-scroller__item-view:first-child .song-item').click()
cy.get(`.vue-recycle-scroller__item-view:nth-child(${count}) .song-item`).click({
shiftKey: true
})
cy.$getVisibleSongRows().first().click()
cy.$getVisibleSongRows().eq(count - 1).click({ shiftKey: true })
cy.get('.screen-header [data-test=btn-shuffle-selected]').click()
})
@ -95,9 +93,9 @@ Cypress.Commands.add('$assertFavoriteSongCount', (count: number) => {
Cypress.Commands.add(
'$selectSongRange',
(start: number, end: number, scrollBehavior: scrollBehaviorOptions = false): Chainable<JQuery> => {
cy.get(`.vue-recycle-scroller__item-view:nth-child(${start}) .song-item`).click()
return cy.get(`.vue-recycle-scroller__item-view:nth-child(${end}) .song-item`).click({
(start: number, end: number, scrollBehavior: scrollBehaviorOptions = false) => {
cy.$getVisibleSongRows().eq(start - 1).click()
return cy.$getVisibleSongRows().eq(end - 1).click({
scrollBehavior,
shiftKey: true
})
@ -120,3 +118,5 @@ Cypress.Commands.add('$assertSidebarItemActive', (text: string) => {
.findByText(text)
.should('have.class', 'active')
})
Cypress.Commands.add('$getVisibleSongRows', () => cy.get('.vue-recycle-scroller__item-view:visible').as('rows'))

View file

@ -16,8 +16,6 @@
// Import commands.js using ES2015 syntax:
import './commands'
Cypress.on('uncaught:exception', () => {
// returning false here prevents Cypress from failing the test
// @see https://docs.cypress.io/api/events/catalog-of-events#Uncaught-Exceptions
return false
})
// returning false here prevents Cypress from failing the test
// @see https://docs.cypress.io/api/events/catalog-of-events#Uncaught-Exceptions
Cypress.on('uncaught:exception', () => false)

2
cypress/types.d.ts vendored
View file

@ -26,6 +26,8 @@ declare namespace Cypress {
*/
$shuffleSeveralSongs(count?: number): void
$getVisibleSongRows(): Chainable<JQuery>
$assertPlaylistSongCount(name: string, count: number): void
$assertFavoriteSongCount(count: number): void
$selectSongRange(start: number, end: number, scrollBehavior?: scrollBehaviorOptions): Chainable<JQuery>