Skip to content

Commit

Permalink
Add support for entity author
Browse files Browse the repository at this point in the history
  • Loading branch information
abelsiqueira committed Jul 31, 2023
1 parent 68165f4 commit 3378314
Show file tree
Hide file tree
Showing 21 changed files with 1,266 additions and 190 deletions.
9 changes: 8 additions & 1 deletion README.dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,18 @@ Here is the list of situations that can happen:
- If the input is not valid YAML, raise an error and don't proceed.
- If the input is not an object, raise an error and don't proceed. This includes vectors and strings.
- Keys at root level that are not part of the `cff` object are passed to `extraCffFields`. A warning is printed, but proceed.
- Keys at nested levels (e.g., authors) are ignored. A warning is printed, but proceed.
- If an author is not a Person nor Entity, print the infringing fields and drop the author.
- If an author does not have enough fields to check whether it is a Person or Entity (e.g., only orcid), then use Person.
- Keys at nested identifiers levels are ignored. A warning is printed but proceed.
- Radio values ('type' and 'identifiers/type') should be sanitized.
- If an old `cff-version` was present, warn that a newer version will be used.
- If no `cff-version` was found, no need to warn.
- 'date-released' should be sanitized so it is a 'yyyy-mm-dd' string, and not a Javascript date.
- Input validation is only done a posteriori, so don't check it during update.
- Special situations (such as `cff-version` and `type` above) should be handled explicitly and documented.
- If parsing is successful, give positive feedback.

Deprecated:

- Keys at nested levels (e.g., authors) are ignored. A warning is printed, but proceed.
- Deprecated because the author can be a Person or Entity. So to check that, we have to decide based on the fields what to check.
95 changes: 89 additions & 6 deletions cypress/e2e/errors.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('From a fixed app', () => {
cy.dataCy('input-title')
.type('A')
cy.visit('/authors')
cy.dataCy('btn-add-author')
cy.dataCy('btn-add-person')
.click()
cy.visit('/finish')
})
Expand Down Expand Up @@ -74,20 +74,20 @@ describe('From a fixed app', () => {
cy.checkThatAppValidityIs(false)
cy.dataCy('banner-error-messages')
.should('contain.text', 'Add at least one author')
cy.dataCy('btn-add-author')
cy.dataCy('btn-add-person')
.click()
cy.checkThatAppValidityIs(true)
})
it('should validate duplicate authors', () => {
cy.dataCy('btn-remove')
.click()
cy.dataCy('btn-add-author')
cy.dataCy('btn-add-person')
.click()
cy.dataCy('input-given-names')
.type('A')
cy.dataCy('btn-done')
.click()
cy.dataCy('btn-add-author')
cy.dataCy('btn-add-person')
.click()
cy.dataCy('input-given-names')
.type('A')
Expand All @@ -104,10 +104,34 @@ describe('From a fixed app', () => {
.click()
cy.checkThatAppValidityIs(true)
})
it('should validate authors\' fields', () => {
it('should validate person and entity being equal', () => {
cy.dataCy('input-email')
.type('[email protected]')
cy.dataCy('input-orcid')
.type('1234123412341234')
cy.dataCy('btn-done')
.click()
cy.dataCy('btn-add-entity')
.click()
cy.dataCy('input-email')
.type('[email protected]')
cy.dataCy('input-orcid')
.type('1234123412341234')
cy.dataCy('btn-done')
.click()

cy.dataCy('card-author0')
.should('have.class', 'red-border')
cy.dataCy('card-author1')
.should('have.class', 'red-border')
cy.checkThatAppValidityIs(false)
cy.dataCy('banner-error-messages')
.should('contain.text', 'There are duplicate authors')
})
it('should validate person\'s fields', () => {
cy.dataCy('btn-remove')
.click()
cy.dataCy('btn-add-author')
cy.dataCy('btn-add-person')
.click()
cy.dataCy('input-email')
.type('a')
Expand All @@ -128,6 +152,65 @@ describe('From a fixed app', () => {
.should('not.have.class', 'q-field--error')
cy.checkThatAppValidityIs(true)
})
it('should validate entity\'s fields', () => {
cy.dataCy('btn-remove')
.click()
cy.dataCy('btn-add-entity')
.click()
cy.dataCy('input-name')
.type('Entity name')

const fields = [
{ name: 'date-start', bad: '2021-01-0', fix: '1', checkInput: false },
{ name: 'date-end', bad: '2021-01-0', fix: '1', checkInput: false },
{ name: 'email', bad: 'a', fix: '@a.com', checkInput: true },
{ name: 'orcid', bad: '1', fix: '234123412341234', checkInput: true }
]
for (const field of fields) {
cy.dataCy(`input-${field.name}`)
.type(field.bad)
cy.checkThatInputValidityIs(false, field.name)
cy.checkThatAppValidityIs(false)
cy.dataCy(`input-${field.name}`)
.type(field.fix)
if (field.checkInput) {
cy.checkThatInputValidityIs(true, field.name)
} else {
cy.dataCy(`input-${field.name}`)
.parents('.q-field')
.should('not.have.class', 'q-field--error')
}
cy.checkThatAppValidityIs(true)
}
})
it('should error when it is inferrable that it is an entity without name', () => {
cy.dataCy('btn-remove')
.click()
cy.dataCy('btn-add-entity')
.click()

const fields = [
{ name: 'date-start', value: '2021-01-01' },
{ name: 'date-end', value: '2021-01-01' },
{ name: 'location', value: 'Here' }
]
for (const field of fields) {
cy.dataCy(`input-${field.name}`)
.type(field.value)

cy.checkThatInputValidityIs(false, 'name')
cy.checkThatAppValidityIs(false)
cy.dataCy('input-name')
.type('Fixed')
cy.checkThatInputValidityIs(true, 'name')
cy.checkThatAppValidityIs(true)

cy.dataCy('input-name')
.clear()
cy.dataCy(`input-${field.name}`)
.clear()
}
})
})

describe('On screen Identifiers', () => {
Expand Down
7 changes: 6 additions & 1 deletion cypress/e2e/info-dialog.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ const infoDialogs = [
{
screen: 'authors',
values: ['authors', 'given-names, name-particle, family-names, name-suffix', 'email', 'affiliation', 'orcid'],
before: () => { cy.dataCy('btn-add-author').click() }
before: () => { cy.dataCy('btn-add-person').click() }
},
{
screen: 'authors',
values: ['authors', 'name', 'address', 'city', 'country', 'post-code', 'location', 'region', 'alias', 'email', 'date-start', 'date-end', 'tel', 'fax', 'website', 'orcid'],
before: () => { cy.dataCy('btn-add-entity').click() }
},
{
screen: 'identifiers',
Expand Down
10 changes: 5 additions & 5 deletions cypress/e2e/navigation.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe('App navigation', () => {
.click()
cy.url()
.should('include', '/authors')
cy.dataCy('btn-add-author')
cy.dataCy('btn-add-person')
.click()
cy.dataCy('btn-next')
.should('not.be.disabled')
Expand All @@ -80,7 +80,7 @@ describe('App navigation', () => {
cy.dataCy('input-title')
.type('A')
cy.visit('/authors')
cy.dataCy('btn-add-author')
cy.dataCy('btn-add-person')
.click()
cy.dataCy('btn-download')
.should('not.be.disabled')
Expand All @@ -91,7 +91,7 @@ describe('App navigation', () => {
cy.dataCy('input-title')
.type('A')
cy.visit('/authors')
cy.dataCy('btn-add-author')
cy.dataCy('btn-add-person')
.click()
cy.dataCy('btn-next')
.click()
Expand All @@ -116,7 +116,7 @@ describe('App navigation', () => {
cy.dataCy('input-title')
.type('A')
cy.visit('/authors')
cy.dataCy('btn-add-author')
cy.dataCy('btn-add-person')
.click()
})
it(`should have ${stepNames.length + 1} steps on stepper`, () => {
Expand Down Expand Up @@ -194,7 +194,7 @@ describe('App navigation', () => {
it('should be possible to move authors around', () => {
cy.visit('/authors')
;['A', 'B', 'C'].forEach((givenName) => {
cy.dataCy('btn-add-author')
cy.dataCy('btn-add-person')
.click()
cy.dataCy('input-given-names')
.type('John')
Expand Down
63 changes: 58 additions & 5 deletions cypress/e2e/spec.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,22 @@ const fullValidCff = {
email: '[email protected]',
affiliation: 'UU',
orcid: 'https://orcid.org/1234-1234-1234-123X'
}, {
address: 'Some street',
alias: 'NLeSC',
city: 'Amsterdam',
country: 'NL',
'date-end': '2022-01-01',
'date-start': '2021-01-01',
email: '[email protected]',
fax: '+31 02 1234 1234',
location: 'Science Park',
name: 'Netherlands eScience Center',
orcid: 'https://orcid.org/1234-1234-1234-1234',
'post-code': '1234AM',
region: 'Oost',
tel: '+31 02 1234 5678',
website: 'https://nlesc.org'
}],
identifiers: [
{ type: 'doi', value: '10.1234/x', description: 'Some DOI' },
Expand All @@ -43,6 +59,8 @@ const fullValidCff = {
type: 'article'
}
}
const downloadsFolder = Cypress.config('downloadsFolder')
const cfffile = `${downloadsFolder}/CITATION.cff`

describe('Basic usage', () => {
it('is working for the minimum information', () => {
Expand All @@ -68,7 +86,7 @@ describe('Basic usage', () => {

// Author screen
cy.url().should('include', '/authors')
cy.dataCy('btn-add-author')
cy.dataCy('btn-add-person')
.click()
cy.dataCy('btn-done')
.click()
Expand Down Expand Up @@ -110,7 +128,7 @@ describe('Basic usage', () => {

// Author screen
cy.url().should('include', '/authors')
cy.dataCy('btn-add-author')
cy.dataCy('btn-add-person')
.click()
cy.dataCy('input-given-names')
.type('John')
Expand All @@ -128,6 +146,44 @@ describe('Basic usage', () => {
.type('123412341234123X')
cy.dataCy('btn-done')
.click()
cy.dataCy('btn-add-entity')
.click()
cy.dataCy('input-name')
.type('Netherlands eScience Center')
cy.dataCy('input-address')
.type('Some street')
cy.dataCy('input-city')
.type('Amsterdam')

cy.dataCy('select-country')
.first()
.type('NL')
.click()
.get('.q-item__label')
.eq(0)
.click()
cy.dataCy('input-post-code')
.type('1234AM')
cy.dataCy('input-location')
.type('Science Park')
cy.dataCy('input-region')
.type('Oost')
cy.dataCy('input-alias')
.type('NLeSC')
cy.dataCy('input-email')
.type('[email protected]')
cy.dataCy('input-date-start')
.type('2021-01-01')
cy.dataCy('input-date-end')
.type('2022-01-01')
cy.dataCy('input-tel')
.type('+31 02 1234 5678')
cy.dataCy('input-fax')
.type('+31 02 1234 1234')
cy.dataCy('input-website')
.type('https://nlesc.org')
cy.dataCy('input-orcid')
.type('1234123412341234')
cy.dataCy('btn-next')
.click()

Expand Down Expand Up @@ -242,9 +298,6 @@ describe('Basic usage', () => {
cy.dataCy('btn-download')
.click()

const downloadsFolder = Cypress.config('downloadsFolder')
const cfffile = `${downloadsFolder}/CITATION.cff`

cy.readFile(cfffile, 'binary', { timeout: 400 })
.then((str) => {
expect(yaml.load(str)).to.deep.equal(fullValidCff)
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/specific.cy.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
describe('Issue 637 - ORCID freeze', () => {
it('should work when writing a full ORCID with dashes', () => {
cy.visit('/authors')
cy.dataCy('btn-add-author')
cy.dataCy('btn-add-person')
.click()
cy.dataCy('input-orcid')
.type('1234-1234-1234-1234')
Expand Down
4 changes: 3 additions & 1 deletion cypress/e2e/yaml-examples/bad-authors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ message: >-
type: software
authors:
- given-names: John
family-name: Doe
family-names: Doe
- name: Bad
given-names: Bad
25 changes: 20 additions & 5 deletions cypress/e2e/yaml-examples/passing-full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,21 @@ authors:
email: [email protected]
affiliation: UU
orcid: 'https://orcid.org/1234-1234-1234-123X'
- address: Some street
alias: NLeSC
city: Amsterdam
country: NL
date-end: '2022-01-01'
date-start: '2021-01-01'
email: [email protected]
fax: +31 02 1234 1234
location: Science Park
name: Netherlands eScience Center
orcid: 'https://orcid.org/1234-1234-1234-1234'
post-code: 1234AM
region: Oost
tel: +31 02 1234 5678
website: 'https://nlesc.org'
identifiers:
- type: doi
value: 10.1234/x
Expand Down Expand Up @@ -37,8 +52,8 @@ commit: '123'
version: v1.2.3
date-released: '2022-01-01'
preferred-citation:
- authors:
- given-names: John
family-names: Doe
title: My Paper
type: article
authors:
- given-names: John
family-names: Doe
title: My Paper
type: article
2 changes: 1 addition & 1 deletion cypress/e2e/yaml-examples/warning-authors.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Property 'family-name: Doe' inside 'authors' was ignored. Check if the key is correct.
Could not add author. It is not a Person due to fields name and not an Entity due to fields given-names. Skipping
Loading

0 comments on commit 3378314

Please sign in to comment.