Fix file input field accepting a filename only once (#1547)

This commit is contained in:
Erik Michelson 2021-10-24 22:46:39 +02:00 committed by GitHub
parent 9118c8310b
commit 3591c90f9f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 130 additions and 37 deletions

View file

@ -5,7 +5,6 @@
*/
describe('History', () => {
describe('History Mode', () => {
beforeEach(() => {
cy.visit('/history')
@ -125,4 +124,55 @@ describe('History', () => {
})
})
})
describe('Import', () => {
beforeEach(() => {
cy.clearLocalStorage('history')
cy.intercept('GET', '/mock-backend/api/private/me/history', {
body: []
})
cy.visit('/history')
cy.logout()
})
it('works with valid file', () => {
cy.get('[data-cypress-id="import-history-file-button"]').click()
cy.get('[data-cypress-id="import-history-file-input"]').attachFile({
filePath: 'history.json',
mimeType: 'application/json'
})
cy.get('[data-cypress-id="history-entry-title"]')
.should('have.length', 1)
.contains('cy-Test')
})
it('fails on invalid file', () => {
cy.get('[data-cypress-id="import-history-file-button"]').click()
cy.get('[data-cypress-id="import-history-file-input"]').attachFile({
filePath: 'history.json.license',
mimeType: 'text/plain'
})
cy.get('[data-cypress-id="notification-toast"]').should('be.visible')
})
it('works when selecting two files with the same name', () => {
cy.get('[data-cypress-id="import-history-file-button"]').click()
cy.get('[data-cypress-id="import-history-file-input"]').attachFile({
filePath: 'history.json',
mimeType: 'application/json'
})
cy.get('[data-cypress-id="history-entry-title"]')
.should('have.length', 1)
.contains('cy-Test')
cy.get('[data-cypress-id="import-history-file-button"]').click()
cy.get('[data-cypress-id="import-history-file-input"]').attachFile({
filePath: 'history-2.json',
fileName: 'history.json',
mimeType: 'application/json'
})
cy.get('[data-cypress-id="history-entry-title"]')
.should('have.length', 2)
.contains('cy-Test2')
})
})
})