2021-01-03 18:14:58 +00:00
|
|
|
context('Uploading', () => {
|
2022-04-28 09:00:20 +00:00
|
|
|
let interceptCounter = 0
|
|
|
|
|
2021-01-03 18:14:58 +00:00
|
|
|
beforeEach(() => {
|
|
|
|
cy.$login()
|
|
|
|
cy.$clickSidebarItem('Upload')
|
|
|
|
})
|
|
|
|
|
|
|
|
function assertResultsAddedToHomeScreen () {
|
|
|
|
cy.$clickSidebarItem('Home')
|
|
|
|
cy.get('.recently-added-album-list li:first-child .name').should('contain.text', 'Spectacular')
|
|
|
|
cy.get('.recently-added-album-list li:first-child .artist').should('contain.text', 'Hilary Hahn')
|
|
|
|
cy.get('.recently-added-song-list li:first-child')
|
|
|
|
.should('contain.text', 'Mendelssohn Violin Concerto in E minor, Op. 64')
|
|
|
|
}
|
|
|
|
|
2022-04-28 09:00:20 +00:00
|
|
|
function selectFixtureFile (fileName = 'sample.mp3') {
|
|
|
|
// Cypress caches fixtures and apparently has a bug where consecutive fixture files yield an empty "type"
|
|
|
|
// which will fail our "audio type filter" (i.e. the file will not be considered an audio file).
|
|
|
|
// As a workaround, we pad the fixture file name with slashes to invalidate the cache.
|
|
|
|
// https://github.com/cypress-io/cypress/issues/4716#issuecomment-558305553
|
|
|
|
cy.fixture(fileName.padStart(fileName.length + interceptCounter, '/')).as('file')
|
|
|
|
cy.get('[type=file]').selectFile('@file')
|
|
|
|
|
|
|
|
interceptCounter++
|
|
|
|
}
|
|
|
|
|
2021-01-03 18:14:58 +00:00
|
|
|
function executeFailedUpload () {
|
2021-05-23 11:42:18 +00:00
|
|
|
cy.intercept('POST', '/api/upload', {
|
|
|
|
statusCode: 413
|
2021-01-03 18:14:58 +00:00
|
|
|
}).as('failedUpload')
|
|
|
|
|
2022-04-28 09:00:20 +00:00
|
|
|
selectFixtureFile()
|
2022-05-10 23:01:48 +00:00
|
|
|
cy.findByTestId('upload-item').should('have.length', 1).and('be.visible')
|
2021-01-03 18:14:58 +00:00
|
|
|
cy.wait('@failedUpload')
|
|
|
|
|
2022-05-13 12:40:04 +00:00
|
|
|
cy.findByTestId('upload-item').should('have.length', 1).should('have.class', 'errored')
|
2021-01-03 18:14:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
it('uploads songs', () => {
|
|
|
|
cy.intercept('POST', '/api/upload', {
|
|
|
|
fixture: 'upload.post.200.json'
|
|
|
|
}).as('upload')
|
|
|
|
|
|
|
|
cy.get('#uploadWrapper').within(() => {
|
2022-04-28 09:00:20 +00:00
|
|
|
selectFixtureFile()
|
2022-05-10 23:01:48 +00:00
|
|
|
cy.findByTestId('upload-item').should('have.length', 1).and('be.visible')
|
2021-01-03 18:14:58 +00:00
|
|
|
|
|
|
|
cy.wait('@upload')
|
2022-05-10 23:01:48 +00:00
|
|
|
cy.findByTestId('upload-item').should('have.length', 0)
|
2021-01-03 18:14:58 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
assertResultsAddedToHomeScreen()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('allows retrying individual failed uploads', () => {
|
|
|
|
cy.get('#uploadWrapper').within(() => {
|
|
|
|
executeFailedUpload()
|
|
|
|
|
|
|
|
cy.intercept('POST', '/api/upload', {
|
|
|
|
fixture: 'upload.post.200.json'
|
|
|
|
}).as('successfulUpload')
|
|
|
|
|
2022-05-10 23:01:48 +00:00
|
|
|
cy.get('[data-testid=upload-item]:first-child').findByTitle('Retry').click()
|
2021-01-03 18:14:58 +00:00
|
|
|
cy.wait('@successfulUpload')
|
2022-05-10 23:01:48 +00:00
|
|
|
cy.findByTestId('upload-item').should('have.length', 0)
|
2021-01-03 18:14:58 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
assertResultsAddedToHomeScreen()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('allows retrying all failed uploads at once', () => {
|
|
|
|
cy.get('#uploadWrapper').within(() => {
|
|
|
|
executeFailedUpload()
|
|
|
|
|
|
|
|
cy.intercept('POST', '/api/upload', {
|
|
|
|
fixture: 'upload.post.200.json'
|
|
|
|
}).as('successfulUpload')
|
|
|
|
|
|
|
|
cy.findByTestId('upload-retry-all-btn').click()
|
|
|
|
cy.wait('@successfulUpload')
|
2022-05-10 23:01:48 +00:00
|
|
|
cy.findByTestId('upload-item').should('have.length', 0)
|
2021-01-03 18:14:58 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
assertResultsAddedToHomeScreen()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('allows removing individual failed uploads', () => {
|
|
|
|
cy.get('#uploadWrapper').within(() => {
|
|
|
|
executeFailedUpload()
|
2022-05-10 23:01:48 +00:00
|
|
|
cy.get('[data-testid=upload-item]:first-child').findByTitle('Remove').click()
|
|
|
|
cy.findByTestId('upload-item').should('have.length', 0)
|
2021-01-03 18:14:58 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('allows removing all failed uploads at once', () => {
|
|
|
|
cy.get('#uploadWrapper').within(() => {
|
|
|
|
executeFailedUpload()
|
|
|
|
cy.findByTestId('upload-remove-all-btn').click()
|
2022-05-10 23:01:48 +00:00
|
|
|
cy.findByTestId('upload-item').should('have.length', 0)
|
2021-01-03 18:14:58 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|