mirror of
https://github.com/koel/koel
synced 2025-02-17 13:58:28 +00:00
feat(test): add missing test for edit/download
This commit is contained in:
parent
baf0f0ffa4
commit
d56a69c449
4 changed files with 84 additions and 20 deletions
|
@ -38,4 +38,11 @@ context('Sidebar Functionalities', () => {
|
|||
.should('not.exist')
|
||||
})
|
||||
})
|
||||
|
||||
it.only('does not have a YouTube item if YouTube is not used', () => {
|
||||
cy.$login({ useYouTube: false })
|
||||
cy.get('#sidebar')
|
||||
.findByText('YouTube')
|
||||
.should('not.exist')
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,11 +1,8 @@
|
|||
context('Song Context Menu', { scrollBehavior: false }, () => {
|
||||
beforeEach(() => {
|
||||
cy.$login()
|
||||
cy.$clickSidebarItem('All Songs')
|
||||
})
|
||||
|
||||
it('plays a song via double-clicking', () => {
|
||||
cy.$mockPlayback()
|
||||
cy.$login()
|
||||
cy.$clickSidebarItem('All Songs')
|
||||
|
||||
cy.get('#songsWrapper').within(() => {
|
||||
cy.get('tr.song-item:first-child').dblclick()
|
||||
|
@ -17,6 +14,8 @@ context('Song Context Menu', { scrollBehavior: false }, () => {
|
|||
|
||||
it('plays and pauses a song via context menu', () => {
|
||||
cy.$mockPlayback()
|
||||
cy.$login()
|
||||
cy.$clickSidebarItem('All Songs')
|
||||
|
||||
cy.get('#songsWrapper').within(() => {
|
||||
cy.get('tr.song-item:first-child')
|
||||
|
@ -34,6 +33,9 @@ context('Song Context Menu', { scrollBehavior: false }, () => {
|
|||
})
|
||||
|
||||
it('goes to album', () => {
|
||||
cy.$login()
|
||||
cy.$clickSidebarItem('All Songs')
|
||||
|
||||
cy.get('#songsWrapper').within(() => cy.get('tr.song-item:first-child').rightclick())
|
||||
cy.findByTestId('song-context-menu').within(() => cy.findByText('Go to Album').click())
|
||||
|
||||
|
@ -46,6 +48,9 @@ context('Song Context Menu', { scrollBehavior: false }, () => {
|
|||
})
|
||||
|
||||
it('goes to artist', () => {
|
||||
cy.$login()
|
||||
cy.$clickSidebarItem('All Songs')
|
||||
|
||||
cy.get('#songsWrapper').within(() => cy.get('tr.song-item:first-child').rightclick())
|
||||
cy.findByTestId('song-context-menu').within(() => cy.findByText('Go to Artist').click())
|
||||
|
||||
|
@ -63,6 +68,7 @@ context('Song Context Menu', { scrollBehavior: false }, () => {
|
|||
{ menuItem: 'Top of Queue', queuedPosition: 1 }
|
||||
]).forEach(config => {
|
||||
it(`queues a song to ${config.menuItem}`, () => {
|
||||
cy.$login()
|
||||
cy.$queueSeveralSongs()
|
||||
cy.$clickSidebarItem('All Songs')
|
||||
|
||||
|
@ -101,6 +107,9 @@ context('Song Context Menu', { scrollBehavior: false }, () => {
|
|||
|
||||
cy.intercept('PUT', '/api/playlist/1/sync', {})
|
||||
|
||||
cy.$login()
|
||||
cy.$clickSidebarItem('All Songs')
|
||||
|
||||
cy.$assertPlaylistSongCount('Simple Playlist', 3)
|
||||
cy.get('#songsWrapper').within(() => {
|
||||
if (config.songCount > 1) {
|
||||
|
@ -121,6 +130,8 @@ context('Song Context Menu', { scrollBehavior: false }, () => {
|
|||
})
|
||||
|
||||
it('does not have smart playlists as target for adding songs', () => {
|
||||
cy.$login()
|
||||
cy.$clickSidebarItem('All Songs')
|
||||
cy.get('#songsWrapper').within(() => cy.get('tr.song-item:first-child').rightclick())
|
||||
|
||||
cy.findByTestId('song-context-menu')
|
||||
|
@ -135,6 +146,8 @@ context('Song Context Menu', { scrollBehavior: false }, () => {
|
|||
fixture: 'like.post.200.json'
|
||||
})
|
||||
|
||||
cy.$login()
|
||||
cy.$clickSidebarItem('All Songs')
|
||||
cy.$assertFavoriteSongCount(3)
|
||||
|
||||
cy.get('#songsWrapper').within(() => cy.get('tr.song-item:first-child').rightclick())
|
||||
|
@ -159,13 +172,35 @@ context('Song Context Menu', { scrollBehavior: false }, () => {
|
|||
it('downloads a song', () => {
|
||||
cy.intercept('/download/songs').as('download')
|
||||
|
||||
cy.$login()
|
||||
cy.$clickSidebarItem('All Songs')
|
||||
|
||||
cy.get('#songsWrapper').within(() => cy.get('tr.song-item:first-child').rightclick())
|
||||
cy.findByTestId('song-context-menu').within(() => cy.findByText('Download').click())
|
||||
|
||||
cy.wait('@download')
|
||||
})
|
||||
|
||||
it('does not have a Download item if download is not allowed', () => {
|
||||
cy.$login({ allowDownload: false })
|
||||
cy.$clickSidebarItem('All Songs')
|
||||
|
||||
cy.get('#songsWrapper').within(() => cy.get('tr.song-item:first-child').rightclick())
|
||||
cy.findByTestId('song-context-menu').within(() => cy.findByText('Download').should('not.exist'))
|
||||
})
|
||||
|
||||
it.only('does not have an Edit item if user is not an admin', () => {
|
||||
cy.$loginAsNonAdmin()
|
||||
cy.$clickSidebarItem('All Songs')
|
||||
|
||||
cy.get('#songsWrapper').within(() => cy.get('tr.song-item:first-child').rightclick())
|
||||
cy.findByTestId('song-context-menu').within(() => cy.findByText('Edit').should('not.exist'))
|
||||
})
|
||||
|
||||
it("copies a song's URL", () => {
|
||||
cy.$login()
|
||||
cy.$clickSidebarItem('All Songs')
|
||||
|
||||
cy.window().then(window => cy.spy(window.document, 'execCommand').as('copy'));
|
||||
cy.get('#songsWrapper').within(() => cy.get('tr.song-item:first-child').rightclick())
|
||||
cy.findByTestId('song-context-menu').within(() => cy.findByText('Copy Shareable URL').click())
|
||||
|
|
|
@ -1,30 +1,43 @@
|
|||
import '@testing-library/cypress/add-commands'
|
||||
import AUTWindow = Cypress.AUTWindow
|
||||
import Chainable = Cypress.Chainable
|
||||
import scrollBehaviorOptions = Cypress.scrollBehaviorOptions
|
||||
|
||||
function _login (dataFixture, redirectTo = '/'): Chainable<AUTWindow> {
|
||||
Cypress.Commands.add('$login', (options: Partial<LoginOptions> = {}): Chainable<Cypress.AUTWindow> => {
|
||||
window.localStorage.setItem('api-token', 'mock-token')
|
||||
|
||||
cy.intercept('api/data', {
|
||||
fixture: dataFixture
|
||||
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
|
||||
|
||||
console.log(Object.assign(data, mergedOptions))
|
||||
|
||||
cy.intercept('GET', 'api/data', {
|
||||
statusCode: 200,
|
||||
body: Object.assign(data, mergedOptions)
|
||||
})
|
||||
})
|
||||
|
||||
return cy.visit(redirectTo)
|
||||
}
|
||||
return cy.visit('/')
|
||||
})
|
||||
|
||||
Cypress.Commands.add('$login', (redirectTo = '/') => _login('data.get.200.json', redirectTo))
|
||||
|
||||
Cypress.Commands.add('$loginAsNonAdmin', (redirectTo = '/') => _login('data-non-admin.get.200.json', redirectTo))
|
||||
Cypress.Commands.add('$loginAsNonAdmin', (options: Partial<LoginOptions> = {}): Chainable<Cypress.AUTWindow> => {
|
||||
options.asAdmin = false
|
||||
return cy.$login(options)
|
||||
})
|
||||
|
||||
Cypress.Commands.add('$each', (dataset: Array<Array<any>>, callback: Function) => {
|
||||
dataset.forEach(args => callback(...args))
|
||||
})
|
||||
|
||||
Cypress.Commands.add('$confirm', () => {
|
||||
cy.get('.alertify .ok')
|
||||
.click()
|
||||
})
|
||||
Cypress.Commands.add('$confirm', () => cy.get('.alertify .ok').click())
|
||||
|
||||
Cypress.Commands.add('$findInTestId', (selector: string) => {
|
||||
const [testId, ...rest] = selector.split(' ')
|
||||
|
|
13
cypress/types.d.ts
vendored
13
cypress/types.d.ts
vendored
|
@ -1,7 +1,16 @@
|
|||
interface LoginOptions {
|
||||
asAdmin: boolean
|
||||
useiTunes: boolean
|
||||
useYouTube: boolean
|
||||
useLastfm: boolean
|
||||
allowDownload: boolean
|
||||
supportsTranscoding: false
|
||||
}
|
||||
|
||||
declare namespace Cypress {
|
||||
interface Chainable {
|
||||
$login(redirectTo?: string): Chainable<AUTWindow>
|
||||
$loginAsNonAdmin(redirectTo?: string): Chainable<AUTWindow>
|
||||
$login(options?: Partial<LoginOptions>): Chainable<AUTWindow>
|
||||
$loginAsNonAdmin(options?: Partial<LoginOptions>): Chainable<AUTWindow>
|
||||
$each(dataset: Array<Array<any>>, callback: Function): void
|
||||
$confirm(): void
|
||||
$clickSidebarItem(sidebarItemText: string): Chainable<JQuery>
|
||||
|
|
Loading…
Add table
Reference in a new issue