Skip to content

Commit

Permalink
Fix test independence
Browse files Browse the repository at this point in the history
  • Loading branch information
Murderlon committed Apr 26, 2022
1 parent c3119a9 commit 3921e9a
Showing 1 changed file with 27 additions and 24 deletions.
51 changes: 27 additions & 24 deletions e2e/cypress/integration/dashboard-tus.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ type Tus = BaseTus & {
requests: { isPaused: boolean }
}

// NOTE: we have to use different files to upload per test
// because we are uploading to https://tusd.tusdemo.net,
// constantly uploading the same images gives a different cached result (or something).
describe('Dashboard with Tus', () => {
beforeEach(() => {
cy.visit('/dashboard-tus')
Expand All @@ -13,6 +16,29 @@ describe('Dashboard with Tus', () => {
cy.intercept('http://localhost:3020/search/unsplash/*').as('unsplash')
})

it('should emit `error` and `upload-error` events on failed POST request', () => {
cy.get('@file-input').attachFile(['images/traffic.jpg'])

const error = cy.spy()
const uploadError = cy.spy()
cy.window().then(({ uppy }) => {
uppy.on('upload-error', uploadError)
uppy.on('error', error)
})

cy.get('.uppy-StatusBar-actionBtn--upload').click()

cy.intercept(
{ method: 'POST', pathname: '/files', times: 1 },
{ statusCode: 401, body: { code: 401, message: 'Expired JWT Token' } },
).as('post')

cy.wait('@post').then(() => {
expect(error).to.be.called
expect(uploadError).to.be.called
})
})

it('should upload cat image successfully', () => {
cy.get('@file-input').attachFile('images/cat.jpg')
cy.get('.uppy-StatusBar-actionBtn--upload').click()
Expand All @@ -23,7 +49,7 @@ describe('Dashboard with Tus', () => {
})

it('should start exponential backoff when receiving HTTP 429', () => {
cy.get('@file-input').attachFile(['images/cat.jpg', 'images/traffic.jpg'])
cy.get('@file-input').attachFile(['images/baboon.png'])
cy.get('.uppy-StatusBar-actionBtn--upload').click()

cy.intercept(
Expand All @@ -40,29 +66,6 @@ describe('Dashboard with Tus', () => {
})
})

it('should emit `error` and `upload-error` events on failed POST request', () => {
cy.get('@file-input').attachFile(['images/cat.jpg', 'images/traffic.jpg'])

const error = cy.spy()
const uploadError = cy.spy()
cy.window().then(({ uppy }) => {
uppy.on('upload-error', uploadError)
uppy.on('error', error)
})

cy.get('.uppy-StatusBar-actionBtn--upload').click()

cy.intercept(
{ method: 'POST', pathname: '/files', times: 1 },
{ statusCode: 401, body: { code: 401, message: 'Expired JWT Token' } },
).as('patch')

cy.wait('@patch').then(() => {
expect(error).to.be.called
expect(uploadError).to.be.called
})
})

it('should upload remote image with URL plugin', () => {
cy.get('[data-cy="Url"]').click()
cy.get('.uppy-Url-input').type('https://via.placeholder.com/600x400')
Expand Down

0 comments on commit 3921e9a

Please sign in to comment.