koel/cypress/integration/song-editing.spec.ts

87 lines
3 KiB
TypeScript
Raw Normal View History

context('Song Editing', { scrollBehavior: false }, () => {
2021-01-02 14:33:32 +00:00
beforeEach(() => {
2021-05-23 11:42:18 +00:00
cy.intercept('/api/**/info', {
2022-04-26 09:46:31 +00:00
fixture: 'song-info.get.200.json'
2021-01-02 14:33:32 +00:00
})
cy.$login()
cy.$clickSidebarItem('All Songs')
})
it('edits a song', () => {
cy.intercept('PUT', '/api/songs', {
fixture: 'songs.put.200.json'
})
2022-04-26 09:46:31 +00:00
cy.get('#songsWrapper .song-item:first-child').rightclick()
cy.findByTestId('song-context-menu').within(() => cy.findByText('Edit').click())
2021-01-02 14:33:32 +00:00
cy.findByTestId('edit-song-form').within(() => {
['artist', 'album', 'is_compilation', 'track'].forEach(selector => {
cy.get(`[name=${selector}]`).should('be.visible')
})
2021-01-02 14:33:32 +00:00
cy.get('[name=title]').clear().type('New Title')
cy.findByTestId('edit-song-lyrics-tab').click()
cy.get('textarea[name=lyrics]')
.should('be.visible')
.and('contain.value', 'Sample song lyrics')
.clear()
.type('New lyrics{enter}Supports multiline.')
cy.get('button[type=submit]').click()
})
cy.findByText('Updated 1 song.').should('be.visible')
cy.findByTestId('edit-song-form').should('not.exist')
2022-04-26 09:46:31 +00:00
cy.get('#songsWrapper .song-item:first-child .title').should('have.text', 'New Title')
2021-01-02 14:33:32 +00:00
})
it('cancels editing', () => {
2022-04-26 09:46:31 +00:00
cy.get('#songsWrapper .song-item:first-child').rightclick()
cy.findByTestId('song-context-menu').within(() => cy.findByText('Edit').click())
2021-01-02 14:33:32 +00:00
cy.$findInTestId('edit-song-form .btn-cancel').click()
cy.findByTestId('edit-song-form').should('not.exist')
})
it('edits multiple songs', () => {
cy.intercept('PUT', '/api/songs', {
fixture: 'songs-multiple.put.200.json'
})
cy.get('#songsWrapper').within(() => {
cy.$selectSongRange(1, 3).rightclick()
})
cy.findByTestId('song-context-menu').within(() => cy.findByText('Edit').click())
cy.findByTestId('edit-song-form').within(() => {
['title', 'track'].forEach(selector => {
cy.get(`[name=${selector}]`).should('not.exist')
})
cy.get('textarea[name=lyrics]').should('not.exist')
;['3 songs selected', 'Mixed Albums'].forEach(text => cy.findByText(text).should('be.visible'))
cy.get('[name=album]').invoke('attr', 'placeholder').should('contain', 'No change')
// Test the typeahead/auto-complete feature
cy.get('[name=album]').type('A')
cy.findByText('Abstract').click()
cy.get('[name=album]').should('contain.value', 'Abstract')
cy.get('[name=album]').type('{downArrow}{downArrow}{downArrow}{downArrow}{enter}')
cy.get('[name=album]').should('contain.value', 'The Wall')
cy.get('button[type=submit]').click()
})
cy.findByText('Updated 3 songs.').should('be.visible')
cy.findByTestId('edit-song-form').should('not.exist')
2022-04-26 09:46:31 +00:00
cy.get('#songsWrapper .song-item:nth-child(1) .album').should('have.text', 'The Wall')
cy.get('#songsWrapper .song-item:nth-child(2) .album').should('have.text', 'The Wall')
cy.get('#songsWrapper .song-item:nth-child(3) .album').should('have.text', 'The Wall')
})
})