Skip to content

Commit

Permalink
Add support for importing Codemeta v3.0 (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
hjonin authored May 6, 2024
1 parent bb4b28c commit 9bf79ad
Show file tree
Hide file tree
Showing 7 changed files with 339 additions and 14 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ a codemeta.json file

This tool was initially prepared for the [FORCE19 Hackathon](https://github.com/force11/force11-rda-scidwg/tree/master/hackathon/FORCE2019).

**NB:** codemeta v2.0 is generated by default, but v3.0 (v2.0 compatible) can be generated via a dedicated button.

## Code contributions.

Expand All @@ -61,8 +62,7 @@ Chromium/Google Chrome, Edge, Safari). Check [Caniuse](https://caniuse.com/)
for availability of features for these browsers.

To keep the architecture simple, we serve javascript files directly to
browsers, without a compiler or transpiler; and do not use third-party
dependencies for now.
browsers, without a compiler or transpiler.

### Running local changes

Expand Down
97 changes: 97 additions & 0 deletions cypress/integration/basics.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,4 +264,101 @@ describe('JSON Import', function() {
cy.get('#name').should('have.value', 'My Test Software');
});

it('imports properties introduced in codemeta v3.0', function() {
cy.get('#codemetaText').then((elem) =>
elem.text(JSON.stringify({
"@context": "https://w3id.org/codemeta/3.0",
"type": "SoftwareSourceCode",
"name": "My Test Software",
"continuousIntegration": "https://test-ci.org/my-software",
"isSourceCodeOf": "Bigger Application",
"review": {
"type": "Review",
"reviewAspect": "Some software aspect",
"reviewBody": "Some review"
}
}))
);
cy.get('#importCodemeta').click();

cy.get('#contIntegration').should('have.value', 'https://test-ci.org/my-software');
cy.get('#isSourceCodeOf').should('have.value', 'Bigger Application');
cy.get('#reviewAspect').should('have.value', 'Some software aspect');
cy.get('#reviewBody').should('have.value', 'Some review');
});

it('imports codemeta v2.0 properties from document with v3.0 context', function() {
cy.get('#codemetaText').then((elem) =>
elem.text(JSON.stringify({
"@context": "https://w3id.org/codemeta/3.0",
"type": "SoftwareSourceCode",
"name": "My Test Software",
"codemeta:contIntegration": {
"id": "https://test-ci.org/my-software"
}
}))
);
cy.get('#importCodemeta').click();

cy.get('#contIntegration').should('have.value', 'https://test-ci.org/my-software');
});

it('imports codemeta v3.0 properties from document with v2.0 context', function() {
cy.get('#codemetaText').then((elem) =>
elem.text(JSON.stringify({
"@context": "https://doi.org/10.5063/schema/codemeta-2.0",
"type": "SoftwareSourceCode",
"name": "My Test Software",
"codemeta:continuousIntegration": {
"id": "https://test-ci.org/my-software"
},
"codemeta:isSourceCodeOf": {
"id": "Bigger Application"
},
"schema:review": {
"type": "schema:Review",
"schema:reviewAspect": "Some software aspect",
"schema:reviewBody": "Some review"
}
}))
);
cy.get('#importCodemeta').click();

cy.get('#contIntegration').should('have.value', 'https://test-ci.org/my-software');
cy.get('#isSourceCodeOf').should('have.value', 'Bigger Application');
cy.get('#reviewAspect').should('have.value', 'Some software aspect');
cy.get('#reviewBody').should('have.value', 'Some review');
});

it('imports newest version property when it is duplicate in multiple version context', function() {
cy.get('#codemetaText').then((elem) =>
elem.text(JSON.stringify({
"@context": "https://doi.org/10.5063/schema/codemeta-2.0",
"type": "SoftwareSourceCode",
"name": "My Test Software",
"contIntegration": "https://test-ci1.org/my-software",
"codemeta:continuousIntegration": {
"id": "https://test-ci2.org/my-software"
},
}))
);
cy.get('#importCodemeta').click();

cy.get('#contIntegration').should('have.value', 'https://test-ci2.org/my-software');

cy.get('#codemetaText').then((elem) =>
elem.text(JSON.stringify({
"@context": "https://doi.org/10.5063/schema/codemeta-3.0",
"type": "SoftwareSourceCode",
"name": "My Test Software",
"continuousIntegration": "https://test-ci1.org/my-software",
"codemeta:contIntegration": {
"id": "https://test-ci2.org/my-software"
},
}))
);
cy.get('#importCodemeta').click();

cy.get('#contIntegration').should('have.value', 'https://test-ci1.org/my-software');
});
});
168 changes: 166 additions & 2 deletions cypress/integration/persons.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ describe('One full author', function() {
});
});

it('can be imported', function() {
it('can be imported even if there is also a role-less author', function() {
cy.get('#codemetaText').then((elem) =>
elem.text(JSON.stringify({
"@context": "https://doi.org/10.5063/schema/codemeta-2.0",
Expand Down Expand Up @@ -578,7 +578,82 @@ describe('One author with a role', function () {
});

it('can be imported', function () {
// TODO
cy.get('#codemetaText').then((elem) =>
elem.text(JSON.stringify({
"@context": "https://w3id.org/codemeta/3.0",
"type": "SoftwareSourceCode",
"name": "My Test Software",
"author": [
{
"type": "Person",
"givenName": "Jane"
},
{
"type": "Role",
"schema:author": {
"type": "Person",
"givenName": "Jane"
},
"roleName": "Developer",
"startDate": "2024-03-04",
"endDate": "2024-04-03"
}
]
}))
);
cy.get('#importCodemeta').click();

cy.get('#author_nb').should('have.value', '1');
cy.get('#author_1_givenName').should('have.value', 'Jane');
cy.get('#author_1_roleName_0').should('have.value', 'Developer');
cy.get('#author_1_startDate_0').should('have.value', '2024-03-04');
cy.get('#author_1_endDate_0').should('have.value', '2024-04-03');
});

it('can be imported when there is a second one, and they are merged', function () {
cy.get('#codemetaText').then((elem) =>
elem.text(JSON.stringify({
"@context": "https://w3id.org/codemeta/3.0",
"type": "SoftwareSourceCode",
"name": "My Test Software",
"author": [
{
"type": "Person",
"givenName": "Jane"
},
{
"type": "Role",
"schema:author": {
"type": "Person",
"givenName": "Jane"
},
"roleName": "Maintainer",
"startDate": "2024-04-04",
"endDate": "2024-05-05"
},
{
"type": "Role",
"schema:author": {
"type": "Person",
"givenName": "Jane"
},
"roleName": "Developer",
"startDate": "2024-03-04",
"endDate": "2024-04-03"
}
]
}))
);
cy.get('#importCodemeta').click();

cy.get('#author_nb').should('have.value', '1');
cy.get('#author_1_givenName').should('have.value', 'Jane');
cy.get('#author_1_roleName_0').should('have.value', 'Maintainer');
cy.get('#author_1_startDate_0').should('have.value', '2024-04-04');
cy.get('#author_1_endDate_0').should('have.value', '2024-05-05');
cy.get('#author_1_roleName_1').should('have.value', 'Developer');
cy.get('#author_1_startDate_1').should('have.value', '2024-03-04');
cy.get('#author_1_endDate_1').should('have.value', '2024-04-03');
});
});

Expand Down Expand Up @@ -683,4 +758,93 @@ describe('Multiple authors', function () {
]
});
});

it('who both have roles can be imported', function () {
cy.get('#codemetaText').then((elem) =>
elem.text(JSON.stringify({
"@context": "https://w3id.org/codemeta/3.0",
"type": "SoftwareSourceCode",
"name": "My Test Software",
"author": [
{
"type": "Person",
"givenName": "Jane"
},
{
"type": "Role",
"schema:author": {
"type": "Person",
"givenName": "Jane"
},
"roleName": "Developer",
"startDate": "2024-03-04",
"endDate": "2024-04-03"
},
{
"type": "Person",
"givenName": "Joe"
},
{
"type": "Role",
"schema:author": {
"type": "Person",
"givenName": "Joe"
},
"roleName": "Maintainer",
"startDate": "2024-04-04",
"endDate": "2024-05-05"
}
]
}))
);
cy.get('#importCodemeta').click();

cy.get('#author_nb').should('have.value', '2');
cy.get('#author_1_givenName').should('have.value', 'Jane');
cy.get('#author_1_roleName_0').should('have.value', 'Developer');
cy.get('#author_1_startDate_0').should('have.value', '2024-03-04');
cy.get('#author_1_endDate_0').should('have.value', '2024-04-03');
cy.get('#author_2_givenName').should('have.value', 'Joe');
cy.get('#author_2_roleName_0').should('have.value', 'Maintainer');
cy.get('#author_2_startDate_0').should('have.value', '2024-04-04');
cy.get('#author_2_endDate_0').should('have.value', '2024-05-05');
});

it('whose one has a role and the other not can be imported', function () {
cy.get('#codemetaText').then((elem) =>
elem.text(JSON.stringify({
"@context": "https://w3id.org/codemeta/3.0",
"type": "SoftwareSourceCode",
"name": "My Test Software",
"author": [
{
"type": "Person",
"givenName": "Jane"
},
{
"type": "Role",
"schema:author": {
"type": "Person",
"givenName": "Jane"
},
"roleName": "Developer",
"startDate": "2024-03-04",
"endDate": "2024-04-03"
},
{
"type": "Person",
"givenName": "Joe"
}
]
}))
);
cy.get('#importCodemeta').click();

cy.get('#author_nb').should('have.value', '2');
cy.get('#author_1_givenName').should('have.value', 'Jane');
cy.get('#author_1_roleName_0').should('have.value', 'Developer');
cy.get('#author_1_startDate_0').should('have.value', '2024-03-04');
cy.get('#author_1_endDate_0').should('have.value', '2024-04-03');
cy.get('#author_2_givenName').should('have.value', 'Joe');
});
});
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</head>
<body>
<header>
<h1>CodeMeta generator v3.0</h1><!-- Generate codemeta v2.0 by default for now, allow v3.0 generation by clicking -->
<h1>CodeMeta generator v3.0</h1>
</header>

<main>
Expand Down
Loading

0 comments on commit 9bf79ad

Please sign in to comment.