|
| 1 | +const passingCffFiles = ['passing-basic.yml', 'passing-full.yml'] |
| 2 | +const badCffFiles = ['authors', 'cff-version', 'date-released', 'identifiers', 'type'] |
| 3 | + |
| 4 | +describe('On the update screen', () => { |
| 5 | + beforeEach(() => { |
| 6 | + cy.visit('/update') |
| 7 | + }) |
| 8 | + describe('Should parse passing files correctly', () => { |
| 9 | + passingCffFiles.forEach((fileName) => { |
| 10 | + it(`file ${fileName}`, () => { |
| 11 | + cy.readFile(`cypress/e2e/yaml-examples/${fileName}`, 'binary', { timeout: 400 }) |
| 12 | + .then((str) => { |
| 13 | + cy.dataCy('input-existing-cff') |
| 14 | + .invoke('val', str) |
| 15 | + .trigger('input') |
| 16 | + cy.dataCy('btn-parse') |
| 17 | + .click() |
| 18 | + cy.dataCy('text-validation-msg') |
| 19 | + .should('include.text', 'Parsed CFF successfully') |
| 20 | + cy.dataCy('btn-start') |
| 21 | + .click() |
| 22 | + cy.url().should('include', '/start') |
| 23 | + cy.dataCy('ta-cff-preview') |
| 24 | + .should('include.value', str) |
| 25 | + }) |
| 26 | + }) |
| 27 | + }) |
| 28 | + }) |
| 29 | + |
| 30 | + describe('Should sanitize salvageable files', () => { |
| 31 | + badCffFiles.forEach((fileName) => { |
| 32 | + it(`file bad-${fileName}.yml`, () => { |
| 33 | + cy.readFile(`cypress/e2e/yaml-examples/bad-${fileName}.yml`, 'binary', { timeout: 400 }) |
| 34 | + .then((str) => { |
| 35 | + cy.dataCy('input-existing-cff') |
| 36 | + .invoke('val', str) |
| 37 | + .trigger('input') |
| 38 | + cy.dataCy('btn-parse') |
| 39 | + .click() |
| 40 | + cy.dataCy('text-validation-msg') |
| 41 | + .should('include.text', 'Parsed CFF successfully') |
| 42 | + }) |
| 43 | + cy.readFile(`cypress/e2e/yaml-examples/warning-${fileName}.txt`, 'binary', { timeout: 400 }) |
| 44 | + .then((str: string) => { |
| 45 | + str.split('\n').forEach((line) => { |
| 46 | + cy.dataCy('text-validation-msg') |
| 47 | + .should('include.text', line) |
| 48 | + }) |
| 49 | + }) |
| 50 | + cy.readFile(`cypress/e2e/yaml-examples/clean-${fileName}.yml`, 'binary', { timeout: 400 }) |
| 51 | + .then((str) => { |
| 52 | + cy.dataCy('btn-start') |
| 53 | + .click() |
| 54 | + cy.url().should('include', '/start') |
| 55 | + cy.dataCy('ta-cff-preview') |
| 56 | + .should('include.value', str) |
| 57 | + }) |
| 58 | + }) |
| 59 | + }) |
| 60 | + }) |
| 61 | + |
| 62 | + describe('Catch the following errors', () => { |
| 63 | + it('should error for empty input', () => { |
| 64 | + ['', '# nothing'].forEach((str) => { |
| 65 | + cy.dataCy('input-existing-cff') |
| 66 | + .invoke('val', str) |
| 67 | + .trigger('input') |
| 68 | + cy.dataCy('btn-parse') |
| 69 | + .click() |
| 70 | + cy.dataCy('text-validation-msg') |
| 71 | + .should('include.text', 'Error: CFF is empty.') |
| 72 | + }) |
| 73 | + }) |
| 74 | + it('should error for list instead of map', () => { |
| 75 | + cy.dataCy('input-existing-cff') |
| 76 | + .invoke('val', '- a: 1') |
| 77 | + .trigger('input') |
| 78 | + cy.dataCy('btn-parse') |
| 79 | + .click() |
| 80 | + cy.dataCy('text-validation-msg') |
| 81 | + .should('include.text', 'Error: CFF is invalid. It should be a YAML map.') |
| 82 | + }) |
| 83 | + it('should error for string instead of map', () => { |
| 84 | + cy.dataCy('input-existing-cff') |
| 85 | + .invoke('val', 'bad') |
| 86 | + .trigger('input') |
| 87 | + cy.dataCy('btn-parse') |
| 88 | + .click() |
| 89 | + cy.dataCy('text-validation-msg') |
| 90 | + .should('include.text', 'Error: CFF is invalid. It should be a YAML map.') |
| 91 | + }) |
| 92 | + it('should error for general invalid YAML', () => { |
| 93 | + ['y : :', 'title: Software: the return'].forEach((str) => { |
| 94 | + cy.dataCy('input-existing-cff') |
| 95 | + .invoke('val', str) |
| 96 | + .trigger('input') |
| 97 | + cy.dataCy('btn-parse') |
| 98 | + .click() |
| 99 | + cy.dataCy('text-validation-msg') |
| 100 | + .should('include.text', 'Error: could not parse CFF because of the following YAML error:') |
| 101 | + }) |
| 102 | + }) |
| 103 | + }) |
| 104 | + |
| 105 | + it('should warn when fields are passed to extra', () => { |
| 106 | + cy.dataCy('input-existing-cff') |
| 107 | + .invoke('val', 'extra: field') |
| 108 | + .trigger('input') |
| 109 | + cy.dataCy('btn-parse') |
| 110 | + .click() |
| 111 | + cy.dataCy('text-validation-msg') |
| 112 | + .should('include.text', "Property 'extra' was not identified as a basic field, so it was passed as an extra cff field") |
| 113 | + }) |
| 114 | +}) |
0 commit comments