Skip to content

Commit eb437ad

Browse files
abelsiqueirac-martinez
authored andcommitted
Add screen to paste existing CFF and document rules for parsing
1 parent d226d64 commit eb437ad

27 files changed

+817
-30
lines changed

README.dev.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,3 +201,29 @@ Links to documentation or tutorials related to technologies/tools we use in the
201201
- [Jest](https://jestjs.io/): Testing framework to run unit tests and perform test assertions.
202202
- [ESLint](https://eslint.org/): To get constistent code style and prevent errors the industry standard linter ESLint is used.
203203
- [Majestic Web UI](https://github.com/Raathigesh/majestic): Web UI for unit tests using Jest
204+
205+
## User stories/Requirements
206+
207+
### Update existing CFF
208+
209+
Constraints:
210+
211+
- Files that were not created by cffinit should still be accepted. This implies that
212+
- Fields like `preferred-citation` should be handled.
213+
- Old valid files should be handled.
214+
- Ignore or fix small mistakes, to make the experience smoother.
215+
- Updating is like continuing from a finished state, so all screen should be marked as visited.
216+
217+
Here is the list of situations that can happen:
218+
219+
- If the input is not valid YAML, raise an error and don't proceed.
220+
- If the input is not an object, raise an error and don't proceed. This includes vectors and strings.
221+
- Keys at root level that are not part of the `cff` object are passed to `extraCffFields`. A warning is printed, but proceed.
222+
- Keys at nested levels (e.g., authors) are ignored. A warning is printed, but proceed.
223+
- Radio values ('type' and 'identifiers/type') should be sanitized.
224+
- If an old `cff-version` was present, warn that a newer version will be used.
225+
- If no `cff-version` was found, no need to warn.
226+
- 'date-released' should be sanitized so it is a 'yyyy-mm-dd' string, and not a Javascript date.
227+
- Input validation is only done a posteriori, so don't check it during update.
228+
- Special situations (such as `cff-version` and `type` above) should be handled explicitly and documented.
229+
- If parsing is successful, give positive feedback.

cypress/e2e/update.cy.ts

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
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+
})
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
cff-version: 1.2.0
2+
title: My title
3+
message: >-
4+
If you use this software, please cite it using the
5+
metadata from this file.
6+
type: software
7+
authors:
8+
- given-names: John
9+
family-name: Doe
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
cff-version: 0.0.1
2+
title: My title
3+
message: >-
4+
If you use this software, please cite it using the
5+
metadata from this file.
6+
type: software
7+
authors:
8+
- given-names: John
9+
family-names: Doe
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
cff-version: 1.2.0
2+
title: My title
3+
message: >-
4+
If you use this software, please cite it using the
5+
metadata from this file.
6+
type: software
7+
authors:
8+
- given-names: John
9+
family-names: Doe
10+
date-released: 2023-01-01
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
cff-version: 1.2.0
2+
title: My title
3+
message: >-
4+
If you use this software, please cite it using the
5+
metadata from this file.
6+
type: software
7+
authors:
8+
- given-names: John
9+
family-names: Doe
10+
identifiers:
11+
- tijpe: doi
12+
describtion: 1
13+
- type: dio
14+
description: 2
15+
- type: doi
16+
description: 3
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
cff-version: 1.2.0
2+
title: My title
3+
message: >-
4+
If you use this software, please cite it using the
5+
metadata from this file.
6+
type: potato
7+
authors:
8+
- given-names: John
9+
family-names: Doe
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
cff-version: 1.2.0
2+
title: My title
3+
message: >-
4+
If you use this software, please cite it using the
5+
metadata from this file.
6+
type: software
7+
authors:
8+
- given-names: John
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
cff-version: 1.2.0
2+
title: My title
3+
message: >-
4+
If you use this software, please cite it using the
5+
metadata from this file.
6+
type: software
7+
authors:
8+
- given-names: John
9+
family-names: Doe
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
cff-version: 1.2.0
2+
title: My title
3+
message: >-
4+
If you use this software, please cite it using the
5+
metadata from this file.
6+
type: software
7+
authors:
8+
- given-names: John
9+
family-names: Doe
10+
date-released: '2023-01-01'

0 commit comments

Comments
 (0)