2020-12-30 00:30:32 +00:00
|
|
|
import '@testing-library/cypress/add-commands'
|
2021-01-02 15:22:31 +00:00
|
|
|
import scrollBehaviorOptions = Cypress.scrollBehaviorOptions
|
2020-12-30 10:11:59 +00:00
|
|
|
|
2022-04-26 12:48:42 +00:00
|
|
|
Cypress.Commands.add('$login', (options: Partial<LoginOptions> = {}) => {
|
2020-12-30 10:11:59 +00:00
|
|
|
window.localStorage.setItem('api-token', 'mock-token')
|
|
|
|
|
2021-01-03 15:21:36 +00:00
|
|
|
const mergedOptions = Object.assign({
|
|
|
|
asAdmin: true,
|
|
|
|
useiTunes: true,
|
|
|
|
useYouTube: true,
|
|
|
|
useLastfm: true,
|
|
|
|
allowDownload: true,
|
|
|
|
supportsTranscoding: true
|
|
|
|
}, options) as LoginOptions
|
|
|
|
|
|
|
|
cy.fixture(mergedOptions.asAdmin ? 'data.get.200.json' : 'data-non-admin.get.200.json').then(data => {
|
|
|
|
delete mergedOptions.asAdmin
|
2020-12-30 10:11:59 +00:00
|
|
|
|
2022-04-27 22:23:05 +00:00
|
|
|
cy.intercept('/api/data', {
|
2021-01-03 15:21:36 +00:00
|
|
|
statusCode: 200,
|
|
|
|
body: Object.assign(data, mergedOptions)
|
|
|
|
})
|
2021-05-23 11:42:18 +00:00
|
|
|
}).as('fetchData')
|
2020-12-30 19:28:39 +00:00
|
|
|
|
2021-05-23 11:42:18 +00:00
|
|
|
const win = cy.visit('/')
|
|
|
|
cy.wait('@fetchData')
|
|
|
|
|
|
|
|
return win
|
2021-01-03 15:21:36 +00:00
|
|
|
})
|
|
|
|
|
2022-04-26 12:48:42 +00:00
|
|
|
Cypress.Commands.add('$loginAsNonAdmin', (options: Partial<LoginOptions> = {}) => {
|
2021-01-03 15:21:36 +00:00
|
|
|
options.asAdmin = false
|
|
|
|
return cy.$login(options)
|
|
|
|
})
|
2020-12-30 18:44:47 +00:00
|
|
|
|
2021-01-03 18:50:55 +00:00
|
|
|
Cypress.Commands.add('$each', (dataset: Array<Array<any>>, callback: (...args) => void) => {
|
2020-12-30 18:44:47 +00:00
|
|
|
dataset.forEach(args => callback(...args))
|
|
|
|
})
|
2020-12-30 22:37:41 +00:00
|
|
|
|
2021-01-03 15:21:36 +00:00
|
|
|
Cypress.Commands.add('$confirm', () => cy.get('.alertify .ok').click())
|
2020-12-31 19:01:09 +00:00
|
|
|
|
|
|
|
Cypress.Commands.add('$findInTestId', (selector: string) => {
|
|
|
|
const [testId, ...rest] = selector.split(' ')
|
|
|
|
|
|
|
|
return cy.findByTestId(testId.trim()).find(rest.join(' '))
|
|
|
|
})
|
2021-01-01 13:31:53 +00:00
|
|
|
|
2022-04-27 21:43:00 +00:00
|
|
|
Cypress.Commands.add('$clickSidebarItem', (text: string) => cy.get('#sidebar').findByText(text).click())
|
2021-01-01 19:53:58 +00:00
|
|
|
|
|
|
|
Cypress.Commands.add('$mockPlayback', () => {
|
2022-04-26 09:46:31 +00:00
|
|
|
cy.intercept('/play/**?api_token=mock-token', {
|
2022-04-26 13:40:20 +00:00
|
|
|
fixture: 'sample.mp3,null'
|
2021-01-01 19:53:58 +00:00
|
|
|
})
|
|
|
|
|
2022-04-26 09:46:31 +00:00
|
|
|
cy.intercept('/api/album/**/thumbnail', {
|
2021-01-01 19:53:58 +00:00
|
|
|
fixture: 'album-thumbnail.get.200.json'
|
|
|
|
})
|
|
|
|
|
2022-04-26 09:46:31 +00:00
|
|
|
cy.intercept('/api/song/**/info', {
|
|
|
|
fixture: 'song-info.get.200.json'
|
2021-01-01 19:53:58 +00:00
|
|
|
})
|
|
|
|
})
|
2021-01-02 11:58:46 +00:00
|
|
|
|
2021-01-04 18:10:12 +00:00
|
|
|
Cypress.Commands.add('$shuffleSeveralSongs', (count = 3) => {
|
2021-01-02 11:58:46 +00:00
|
|
|
cy.$mockPlayback()
|
|
|
|
cy.$clickSidebarItem('All Songs')
|
|
|
|
|
|
|
|
cy.get('#songsWrapper').within(() => {
|
2022-04-27 21:43:00 +00:00
|
|
|
cy.$getSongRowAt(0).click()
|
|
|
|
cy.$getSongRowAt(count - 1).click({ shiftKey: true })
|
2021-01-02 11:58:46 +00:00
|
|
|
|
2022-05-10 23:01:48 +00:00
|
|
|
cy.get('.screen-header [data-testid=btn-shuffle-selected]').click()
|
2021-01-02 11:58:46 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
Cypress.Commands.add('$assertPlaylistSongCount', (name: string, count: number) => {
|
|
|
|
cy.$clickSidebarItem(name)
|
2022-04-26 09:46:31 +00:00
|
|
|
cy.get('#playlistWrapper .song-item').should('have.length', count)
|
2021-01-02 11:58:46 +00:00
|
|
|
cy.go('back')
|
|
|
|
})
|
|
|
|
|
|
|
|
Cypress.Commands.add('$assertFavoriteSongCount', (count: number) => {
|
|
|
|
cy.$clickSidebarItem('Favorites')
|
2022-04-26 09:46:31 +00:00
|
|
|
cy.get('#favoritesWrapper').within(() => cy.get('.song-item').should('have.length', count))
|
2021-01-02 11:58:46 +00:00
|
|
|
cy.go('back')
|
|
|
|
})
|
2021-01-02 15:22:31 +00:00
|
|
|
|
|
|
|
Cypress.Commands.add(
|
|
|
|
'$selectSongRange',
|
2022-04-26 12:48:42 +00:00
|
|
|
(start: number, end: number, scrollBehavior: scrollBehaviorOptions = false) => {
|
2022-04-27 21:43:00 +00:00
|
|
|
cy.$getSongRowAt(start).click()
|
|
|
|
return cy.$getSongRowAt(end).click({
|
2021-01-02 15:22:31 +00:00
|
|
|
scrollBehavior,
|
|
|
|
shiftKey: true
|
|
|
|
})
|
|
|
|
})
|
2021-01-02 22:18:55 +00:00
|
|
|
|
|
|
|
Cypress.Commands.add('$assertPlaying', () => {
|
|
|
|
cy.findByTestId('pause-btn').should('exist')
|
|
|
|
cy.findByTestId('play-btn').should('not.exist')
|
2022-05-13 12:40:04 +00:00
|
|
|
cy.$findInTestId('other-controls [data-testid=soundbars]').should('be.visible')
|
2021-01-02 22:18:55 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
Cypress.Commands.add('$assertNotPlaying', () => {
|
|
|
|
cy.findByTestId('pause-btn').should('not.exist')
|
|
|
|
cy.findByTestId('play-btn').should('exist')
|
2022-05-13 12:40:04 +00:00
|
|
|
cy.$findInTestId('other-controls [data-testid=soundbars]').should('not.exist')
|
2021-01-02 22:18:55 +00:00
|
|
|
})
|
2021-01-03 15:54:06 +00:00
|
|
|
|
2021-01-03 16:24:35 +00:00
|
|
|
Cypress.Commands.add('$assertSidebarItemActive', (text: string) => {
|
2022-04-27 21:43:00 +00:00
|
|
|
cy.get('#sidebar').findByText(text).should('have.class', 'active')
|
2021-01-03 15:54:06 +00:00
|
|
|
})
|
2022-04-26 12:48:42 +00:00
|
|
|
|
2022-04-27 21:43:00 +00:00
|
|
|
Cypress.Commands.add('$getSongRows', () => cy.get('.song-item').as('rows'))
|
|
|
|
Cypress.Commands.add('$getSongRowAt', (position: number) => cy.$getSongRows().eq(position))
|