From 2135a8faba5f9cde55f76631181f80b4c3933bfc Mon Sep 17 00:00:00 2001 From: Phan An Date: Mon, 4 Jan 2021 19:10:12 +0100 Subject: [PATCH] feat(test): add more e2e test for queue navigation --- cypress/integration/queuing.spec.ts | 50 +++++++++++++++++-- cypress/integration/song-context-menu.spec.ts | 2 +- cypress/support/commands.ts | 2 +- cypress/types.d.ts | 4 +- resources/assets | 2 +- 5 files changed, 52 insertions(+), 8 deletions(-) diff --git a/cypress/integration/queuing.spec.ts b/cypress/integration/queuing.spec.ts index d2fd58cd..7b4761e0 100644 --- a/cypress/integration/queuing.spec.ts +++ b/cypress/integration/queuing.spec.ts @@ -52,7 +52,7 @@ context('Queuing', { scrollBehavior: false }, () => { }) it('creates a queue from selected songs', () => { - cy.$queueSeveralSongs() + cy.$shuffleSeveralSongs() cy.get('#queueWrapper').within(() => { cy.get('tr.song-item').should('have.length', 3) @@ -61,7 +61,7 @@ context('Queuing', { scrollBehavior: false }, () => { }) it('deletes a song from queue', () => { - cy.$queueSeveralSongs() + cy.$shuffleSeveralSongs() cy.get('#queueWrapper').within(() => { cy.get('tr.song-item').should('have.length', 3) @@ -71,7 +71,7 @@ context('Queuing', { scrollBehavior: false }, () => { }) it('queues a song when plays it', () => { - cy.$queueSeveralSongs() + cy.$shuffleSeveralSongs() cy.$clickSidebarItem('All Songs') let songTitle @@ -94,4 +94,48 @@ context('Queuing', { scrollBehavior: false }, () => { cy.$assertPlaying() }) + + it('navigates through the queue', () => { + cy.$shuffleSeveralSongs() + cy.get('#queueWrapper tr.song-item:nth-child(1)').should('have.class', 'playing') + + cy.findByTestId('play-next-btn').click({ force: true }) + cy.get('#queueWrapper tr.song-item:nth-child(2)').should('have.class', 'playing') + cy.$assertPlaying() + + cy.findByTestId('play-prev-btn').click({ force: true }) + cy.get('#queueWrapper tr.song-item:nth-child(1)').should('have.class', 'playing') + cy.$assertPlaying() + }) + + it('stops playing if reaches end of queue in no-repeat mode', () => { + cy.$shuffleSeveralSongs() + cy.findByTestId('play-next-btn').click({ force: true }) + cy.findByTestId('play-next-btn').click({ force: true }) + cy.findByTestId('play-next-btn').click({ force: true }) + cy.$assertNotPlaying() + }) + + it('rotates if reaches end of queue in repeat-all mode', () => { + cy.findByTestId('repeat-mode-switch').click() + + cy.$shuffleSeveralSongs() + cy.findByTestId('play-next-btn').click({ force: true }) + cy.findByTestId('play-next-btn').click({ force: true }) + cy.findByTestId('play-next-btn').click({ force: true }) + + cy.get('#queueWrapper tr.song-item:nth-child(1)').should('have.class', 'playing') + cy.$assertPlaying() + }) + + it('still moves to next song in repeat-one mode', () => { + cy.findByTestId('repeat-mode-switch').click() + cy.findByTestId('repeat-mode-switch').click() + + cy.$shuffleSeveralSongs() + cy.findByTestId('play-next-btn').click({ force: true }) + + cy.get('#queueWrapper tr.song-item:nth-child(2)').should('have.class', 'playing') + cy.$assertPlaying() + }) }) diff --git a/cypress/integration/song-context-menu.spec.ts b/cypress/integration/song-context-menu.spec.ts index bb87c486..e69d5d55 100644 --- a/cypress/integration/song-context-menu.spec.ts +++ b/cypress/integration/song-context-menu.spec.ts @@ -69,7 +69,7 @@ context('Song Context Menu', { scrollBehavior: false }, () => { ]).forEach(config => { it(`queues a song to ${config.menuItem}`, () => { cy.$login() - cy.$queueSeveralSongs() + cy.$shuffleSeveralSongs() cy.$clickSidebarItem('All Songs') let songTitle diff --git a/cypress/support/commands.ts b/cypress/support/commands.ts index 63faa40b..626a44a2 100644 --- a/cypress/support/commands.ts +++ b/cypress/support/commands.ts @@ -64,7 +64,7 @@ Cypress.Commands.add('$mockPlayback', () => { }) }) -Cypress.Commands.add('$queueSeveralSongs', (count = 3) => { +Cypress.Commands.add('$shuffleSeveralSongs', (count = 3) => { cy.$mockPlayback() cy.$clickSidebarItem('All Songs') diff --git a/cypress/types.d.ts b/cypress/types.d.ts index 1991958c..7fe44f96 100644 --- a/cypress/types.d.ts +++ b/cypress/types.d.ts @@ -11,7 +11,7 @@ declare namespace Cypress { interface Chainable { $login(options?: Partial): Chainable $loginAsNonAdmin(options?: Partial): Chainable - $each(dataset: Array>, callback: Function): void + $each(dataset: Array>, callback: (...args) => void): void $confirm(): void $clickSidebarItem(sidebarItemText: string): Chainable @@ -24,7 +24,7 @@ declare namespace Cypress { * Queue several songs from the All Song screen. * @param count */ - $queueSeveralSongs(count?: number): void + $shuffleSeveralSongs(count?: number): void $assertPlaylistSongCount(name: string, count: number): void $assertFavoriteSongCount(count: number): void diff --git a/resources/assets b/resources/assets index d1ba4b2c..e603d05a 160000 --- a/resources/assets +++ b/resources/assets @@ -1 +1 @@ -Subproject commit d1ba4b2c17e9cfb81b1e0c00cd2464f5549ea85b +Subproject commit e603d05a170e219fd1d14747ecc05b466c438f8e