Skip to content

Commit c809ec7

Browse files
committed
Add screen to paste existing CFF and document rules for parsing
1 parent 1418dd6 commit c809ec7

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'
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
- type: other
12+
value: ''
13+
- type: other
14+
value: ''
15+
description: 2
16+
- type: doi
17+
value: ''
18+
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: software
7+
authors:
8+
- given-names: John
9+
family-names: Doe
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: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
cff-version: 1.2.0
2+
title: My Title
3+
message: New message
4+
type: dataset
5+
authors:
6+
- given-names: John
7+
name-particle: von
8+
family-names: Doe
9+
name-suffix: Sr.
10+
11+
affiliation: UU
12+
orcid: 'https://orcid.org/1234-1234-1234-123X'
13+
identifiers:
14+
- type: doi
15+
value: 10.1234/x
16+
description: Some DOI
17+
- type: url
18+
value: 'https://id'
19+
description: Some URL
20+
- type: swh
21+
value: 'swh:1:rev:0123456789abcdef0123456789abcdef01234567'
22+
description: Some SWH
23+
- type: other
24+
value: Other
25+
description: Some other thing
26+
repository-code: 'https://rc'
27+
url: 'https://url'
28+
repository: 'https://r'
29+
repository-artifact: 'https://ra'
30+
abstract: Lorem ipsum
31+
keywords:
32+
- kw0
33+
- kw1
34+
- kw2
35+
license: Apache-2.0
36+
commit: '123'
37+
version: v1.2.3
38+
date-released: '2022-01-01'
39+
preferred-citation:
40+
- authors:
41+
- given-names: John
42+
family-names: Doe
43+
title: My Paper
44+
type: article
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Property 'family-name: Doe' inside 'authors' was ignored. Check if the key is correct.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cff-version was updated to 1.2.0. This might led to some issues, so verify before downloading.

cypress/e2e/yaml-examples/warning-date-released.txt

Whitespace-only changes.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Property 'tijpe: doi' inside 'identifiers' was ignored. Check if the key is correct.
2+
Invalid value 'dio' for identifier type. Using 'other' instead.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Invalid type 'potato'. Using 'software' instead.

src/components/LayoutLanding.vue

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,34 @@
4242
</div>
4343
<div class="row justify-center items-center q-pt-md q-mb-xl">
4444
<div class="column items-center slide-up-animation">
45-
<div style="font-size: 1.2rem">
46-
Create your CITATION.cff now!
45+
<div
46+
class="q-mb-md"
47+
style="font-size: 1.2rem"
48+
>
49+
Create your CITATION.cff now, or start from an existing file!
50+
</div>
51+
<div class="justify-center q-gutter-md">
52+
<q-btn
53+
aria-label="Create your CITATION.cff file"
54+
class="start-button bg-primary"
55+
data-cy="btn-create"
56+
label="Create"
57+
icon="add"
58+
no-caps
59+
size="xl"
60+
to="/start"
61+
/>
62+
<q-btn
63+
aria-label="Update your CITATION.cff file"
64+
class="start-button bg-primary"
65+
data-cy="btn-update"
66+
label="Update"
67+
icon="edit"
68+
no-caps
69+
size="xl"
70+
to="/update"
71+
/>
4772
</div>
48-
<q-btn
49-
aria-label="Create your CITATION.cff file"
50-
class="start-button bg-primary"
51-
data-cy="btn-create"
52-
label="Create"
53-
icon="add"
54-
no-caps
55-
size="xl"
56-
to="/start"
57-
/>
5873
</div>
5974
</div>
6075
<span class="text-right text-black text-body1">

src/components/LayoutStepper.vue

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -169,19 +169,3 @@ export default defineComponent({
169169
}
170170
})
171171
</script>
172-
<style scoped>
173-
.skip-to-main-content-link {
174-
position: absolute;
175-
left: -9999px;
176-
z-index: 999;
177-
padding: 1em;
178-
background-color: black;
179-
color: white;
180-
opacity: 0;
181-
}
182-
.skip-to-main-content-link:focus {
183-
left: 50%;
184-
transform: translateX(-50%);
185-
opacity: 1;
186-
}
187-
</style>

0 commit comments

Comments
 (0)