feat(test): add e2e Favorites tests

This commit is contained in:
Phan An 2021-01-01 14:31:53 +01:00
parent 18d5a77fa6
commit 5fb1d6aa75
10 changed files with 132 additions and 338 deletions

View file

@ -468,81 +468,6 @@
}
],
"interactions": [
{
"song_id": "6d66b9c4c967ad2d27b32974adc482a6",
"liked": false,
"play_count": 3450
},
{
"song_id": "29e2deb6e0ba21784a45aabf71b6bb25",
"liked": false,
"play_count": 3134
},
{
"song_id": "44b395ba4e760f149b542aafc0451534",
"liked": false,
"play_count": 3046
},
{
"song_id": "b8e26d5c822c43edfbf056c5840af700",
"liked": false,
"play_count": 3086
},
{
"song_id": "1a4c590a6ea550d243328b5e26dced2b",
"liked": false,
"play_count": 3215
},
{
"song_id": "49bcc0e4346df1a13f57d3a7ccd09a00",
"liked": true,
"play_count": 16065
},
{
"song_id": "b6fb60327d38f9e09e565849a267c06f",
"liked": true,
"play_count": 3495
},
{
"song_id": "2a16e2477b3c6a292b89c68d94a7fc85",
"liked": false,
"play_count": 50143
},
{
"song_id": "c780bf93374edcbac4b5df762b6b8c2c",
"liked": false,
"play_count": 2459
},
{
"song_id": "14680f3ffef690f8521200e82f9ebb30",
"liked": false,
"play_count": 19532
},
{
"song_id": "f33affed478896835bbd1df6235b2e12",
"liked": false,
"play_count": 3814
},
{
"song_id": "b38fc5cbb0fd41ee8ff512adcc8b07f0",
"liked": true,
"play_count": 3863
},
{
"song_id": "ffb3bce333e6a5e0561097d85ef4ae6b",
"liked": true,
"play_count": 2598
},
{
"song_id": "2e59423cd94c809fbd5639b6745fce37",
"liked": false,
"play_count": 4425
},
{
"song_id": "2e8f1fadf1544522b1cd4efb97adedf8",
"liked": false,
"play_count": 2978
},
{
"song_id": "7ed14ff6778a7f2d332503cefb0d5f62",
"liked": true,
@ -553,90 +478,10 @@
"liked": true,
"play_count": 10788
},
{
"song_id": "2625510a2ed87d758010f6bac14fb622",
"liked": true,
"play_count": 5336
},
{
"song_id": "ea5a1b1dc6da09e9eefb452fb7b36727",
"liked": false,
"play_count": 2721
},
{
"song_id": "307aa9124cc7f223a8e64ba19f90c196",
"liked": true,
"play_count": 8997
},
{
"song_id": "1326f8a4fc90843f07ef550c54cd88f9",
"liked": false,
"play_count": 5629
},
{
"song_id": "312efc46c3ef5a09f625870d83321f11",
"liked": false,
"play_count": 2904
},
{
"song_id": "03bebf17f54e2afc7c0513fb1d931009",
"liked": false,
"play_count": 6376
},
{
"song_id": "d14b6dc2acfbc2ac8ffd7781c4657645",
"liked": true,
"play_count": 4388
},
{
"song_id": "fef0c2ea06ab75368923b1983b4ede52",
"liked": false,
"play_count": 4788
},
{
"song_id": "af651d9c5e27dae14e1d7822663cc8a5",
"liked": true,
"play_count": 6479
},
{
"song_id": "17ffc7188449c6e937e4600677414032",
"liked": true,
"play_count": 8200
},
{
"song_id": "60a3f37eaa83e7cb8508f7513ae46bf7",
"liked": true,
"play_count": 2670
},
{
"song_id": "7e1769e4713d68fb77739bf01e346f37",
"liked": false,
"play_count": 2640
},
{
"song_id": "81d48670ee43f7eee30fc6c1f01d7ba8",
"liked": true,
"play_count": 4376
},
{
"song_id": "51c6a0573b7fc82854afd48059da0c21",
"liked": false,
"play_count": 2690
},
{
"song_id": "4cf008da0ad2349a5b8aaeb037f306bf",
"liked": true,
"play_count": 3200
},
{
"song_id": "d0bfd0f2f1d7e5ddcb9b141897d577e5",
"liked": false,
"play_count": 2465
},
{
"song_id": "79bdde00e9c9b34bffe06fd4026f9551",
"liked": false,
"play_count": 4247
}
],
"recentlyPlayed": [

View file

@ -468,81 +468,6 @@
}
],
"interactions": [
{
"song_id": "6d66b9c4c967ad2d27b32974adc482a6",
"liked": false,
"play_count": 3450
},
{
"song_id": "29e2deb6e0ba21784a45aabf71b6bb25",
"liked": false,
"play_count": 3134
},
{
"song_id": "44b395ba4e760f149b542aafc0451534",
"liked": false,
"play_count": 3046
},
{
"song_id": "b8e26d5c822c43edfbf056c5840af700",
"liked": false,
"play_count": 3086
},
{
"song_id": "1a4c590a6ea550d243328b5e26dced2b",
"liked": false,
"play_count": 3215
},
{
"song_id": "49bcc0e4346df1a13f57d3a7ccd09a00",
"liked": true,
"play_count": 16065
},
{
"song_id": "b6fb60327d38f9e09e565849a267c06f",
"liked": true,
"play_count": 3495
},
{
"song_id": "2a16e2477b3c6a292b89c68d94a7fc85",
"liked": false,
"play_count": 50143
},
{
"song_id": "c780bf93374edcbac4b5df762b6b8c2c",
"liked": false,
"play_count": 2459
},
{
"song_id": "14680f3ffef690f8521200e82f9ebb30",
"liked": false,
"play_count": 19532
},
{
"song_id": "f33affed478896835bbd1df6235b2e12",
"liked": false,
"play_count": 3814
},
{
"song_id": "b38fc5cbb0fd41ee8ff512adcc8b07f0",
"liked": true,
"play_count": 3863
},
{
"song_id": "ffb3bce333e6a5e0561097d85ef4ae6b",
"liked": true,
"play_count": 2598
},
{
"song_id": "2e59423cd94c809fbd5639b6745fce37",
"liked": false,
"play_count": 4425
},
{
"song_id": "2e8f1fadf1544522b1cd4efb97adedf8",
"liked": false,
"play_count": 2978
},
{
"song_id": "7ed14ff6778a7f2d332503cefb0d5f62",
"liked": true,
@ -553,90 +478,10 @@
"liked": true,
"play_count": 10788
},
{
"song_id": "2625510a2ed87d758010f6bac14fb622",
"liked": true,
"play_count": 5336
},
{
"song_id": "ea5a1b1dc6da09e9eefb452fb7b36727",
"liked": false,
"play_count": 2721
},
{
"song_id": "307aa9124cc7f223a8e64ba19f90c196",
"liked": true,
"play_count": 8997
},
{
"song_id": "1326f8a4fc90843f07ef550c54cd88f9",
"liked": false,
"play_count": 5629
},
{
"song_id": "312efc46c3ef5a09f625870d83321f11",
"liked": false,
"play_count": 2904
},
{
"song_id": "03bebf17f54e2afc7c0513fb1d931009",
"liked": false,
"play_count": 6376
},
{
"song_id": "d14b6dc2acfbc2ac8ffd7781c4657645",
"liked": true,
"play_count": 4388
},
{
"song_id": "fef0c2ea06ab75368923b1983b4ede52",
"liked": false,
"play_count": 4788
},
{
"song_id": "af651d9c5e27dae14e1d7822663cc8a5",
"liked": true,
"play_count": 6479
},
{
"song_id": "17ffc7188449c6e937e4600677414032",
"liked": true,
"play_count": 8200
},
{
"song_id": "60a3f37eaa83e7cb8508f7513ae46bf7",
"liked": true,
"play_count": 2670
},
{
"song_id": "7e1769e4713d68fb77739bf01e346f37",
"liked": false,
"play_count": 2640
},
{
"song_id": "81d48670ee43f7eee30fc6c1f01d7ba8",
"liked": true,
"play_count": 4376
},
{
"song_id": "51c6a0573b7fc82854afd48059da0c21",
"liked": false,
"play_count": 2690
},
{
"song_id": "4cf008da0ad2349a5b8aaeb037f306bf",
"liked": true,
"play_count": 3200
},
{
"song_id": "d0bfd0f2f1d7e5ddcb9b141897d577e5",
"liked": false,
"play_count": 2465
},
{
"song_id": "79bdde00e9c9b34bffe06fd4026f9551",
"liked": false,
"play_count": 4247
}
],
"recentlyPlayed": [

View file

@ -0,0 +1,19 @@
{
"song_id": "03bebf17f54e2afc7c0513fb1d931009",
"liked": true,
"song": {
"id": "03bebf17f54e2afc7c0513fb1d931009",
"album_id": 5,
"artist_id": 3,
"title": "Instinct",
"length": 204.11,
"track": null,
"disc": 1,
"created_at": "2019-08-24 18:03:35",
"artist": {
"id": 3,
"name": "The Band",
"image": null
}
}
}

View file

@ -0,0 +1,95 @@
context('Favorites', () => {
beforeEach(() => {
cy.$login()
})
function assertFavoriteCount (count: number) {
cy.$clickSidebarItem('Favorites')
cy.get('#favoritesWrapper').within(() => cy.get('tr.song-item').should('have.length', count))
}
it('loads the list of favorites', () => {
cy.$clickSidebarItem('Favorites')
cy.get('#favoritesWrapper')
.within(() => {
cy.findByText('Songs You Love').should('be.visible')
cy.findByText('Download All').should('be.visible')
cy.get('tr.song-item').should('have.length', 3)
.each(row => {
cy.wrap(row)
.get('[data-test=btn-like-liked]')
.should('be.visible')
})
})
})
it('adds a favorite song from Like button', () => {
cy.intercept('POST', '/api/interaction/like', {
fixture: 'like.post.200.json'
})
cy.$clickSidebarItem('All Songs')
cy.get('#songsWrapper')
.within(() => {
cy.get('tr.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'))
})
assertFavoriteCount(4)
})
it('adds a favorite song from Add To dropdown', () => {
cy.intercept('POST', '/api/interaction/like', {
fixture: 'like.post.200.json'
})
cy.$clickSidebarItem('All Songs')
cy.get('#songsWrapper')
.within(() => {
cy.get('tr.song-item:first-child').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')
})
assertFavoriteCount(4)
})
it('deletes a favorite with Unlike button', () => {
cy.intercept('POST', '/api/interaction/like', {})
cy.$clickSidebarItem('Favorites')
cy.get('#favoritesWrapper')
.within(() => {
cy.get('tr.song-item:first-child')
.should('contain.text', 'November')
.within(() => cy.get('[data-test=like-btn]').click())
cy.get('tr.song-item').should('have.length', 2)
cy.get('tr.song-item:first-child').should('not.contain.text', 'November')
})
})
it('deletes a favorite with Backspace key', () => {
cy.intercept('POST', '/api/interaction/like', {})
cy.$clickSidebarItem('Favorites')
cy.get('#favoritesWrapper')
.within(() => {
cy.get('tr.song-item:first-child')
.should('contain.text', 'November')
.click()
.type('{backspace}')
cy.get('tr.song-item').should('have.length', 2)
cy.get('tr.song-item:first-child').should('not.contain.text', 'November')
})
})
})

View file

@ -8,12 +8,12 @@ context('Home Screen', () => {
it('renders', () => {
cy.get('.screen-header').should('be.visible')
cy.$each([
['.top-song-list', 7],
['.top-song-list', 3],
['.recent-song-list', 7],
['.recently-added-album-list', 6],
['.recently-added-song-list', 10],
['.top-artist-list', 1],
['.top-album-list', 6]
['.top-album-list', 3]
], (selector: string, itemCount: number) => {
cy.get(selector)
.should('exist')

View file

@ -1,15 +1,12 @@
context('Playlists', () => {
beforeEach(() => cy.$login())
it('displays a playlist when sidebar menu item is clicked', () => {
cy.intercept('GET', '/api/playlist/1/songs', {
fixture: 'playlist-songs.get.200.json'
})
cy.$login()
cy.get('#sidebar')
.findByText('Simple Playlist')
.as('menuItem')
.click()
cy.$clickSidebarItem('Simple Playlist')
cy.get('#playlistWrapper').within(() => {
cy.get('.heading-wrapper')
@ -32,12 +29,7 @@ context('Playlists', () => {
cy.intercept('DELETE', '/api/playlist/1', {})
cy.$login()
cy.get('#sidebar')
.findByText('Simple Playlist')
.as('menuItem')
.click()
cy.$clickSidebarItem('Simple Playlist').as('menuItem')
cy.get('#playlistWrapper .btn-delete-playlist')
.click()
@ -54,8 +46,6 @@ context('Playlists', () => {
cy.intercept('DELETE', '/api/playlist/2', {})
cy.$login()
cy.get('#sidebar')
.findByText('Smart Playlist')
.as('menuItem')
@ -75,7 +65,6 @@ context('Playlists', () => {
fixture: 'playlist.post.200.json'
})
cy.$login()
cy.findByTestId('sidebar-create-playlist-btn').click()
cy.findByTestId('playlist-context-menu-create-simple').click()
@ -142,7 +131,6 @@ context('Playlists', () => {
fixture: 'playlist-songs.get.200.json'
})
cy.$login()
cy.findByTestId('sidebar-create-playlist-btn').click()
cy.findByTestId('playlist-context-menu-create-smart').click()
@ -216,8 +204,6 @@ context('Playlists', () => {
cy.intercept('PUT', '/api/playlist/2', {})
cy.$login()
cy.get('#sidebar')
.findByText('Smart Playlist')
.rightclick()

View file

@ -18,11 +18,8 @@ context('Sidebar Functionalities', () => {
]
function assertMenuItem (text: string, url: string) {
cy.get('#sidebar')
.findByText(text)
.click()
.url()
.should('contain', url)
cy.$clickSidebarItem(text)
cy.url().should('contain', url)
}
it('contains menu items', () => {

View file

@ -30,3 +30,9 @@ Cypress.Commands.add('$findInTestId', (selector: string) => {
return cy.findByTestId(testId.trim()).find(rest.join(' '))
})
Cypress.Commands.add('$clickSidebarItem', (sidebarItemText: string): Chainable<JQuery> => {
return cy.get('#sidebar')
.findByText(sidebarItemText)
.click()
})

5
cypress/types.d.ts vendored
View file

@ -1,9 +1,10 @@
declare namespace Cypress {
interface Chainable {
$login(redirectTo?: string): Chainable
$loginAsNonAdmin(redirectTo?: string): Chainable
$login(redirectTo?: string): Chainable<AUTWindow>
$loginAsNonAdmin(redirectTo?: string): Chainable<AUTWindow>
$each(dataset: Array<Array<any>>, callback: Function): void
$confirm(): void
$clickSidebarItem(sidebarItemText: string): Chainable<JQuery>
/**
* Support finding an element within an element identified with a test ID.

@ -1 +1 @@
Subproject commit f9ba863c2741058a799b81a0886d39adebb7489c
Subproject commit 1d933de3e80d7212b630429b9d7e98947797d372