Skip to content

Commit

Permalink
#1532 - add e2e tests for DOI versioning
Browse files Browse the repository at this point in the history
  • Loading branch information
louise-davies committed May 3, 2024
1 parent 67a04c3 commit f2cbfb3
Show file tree
Hide file tree
Showing 9 changed files with 467 additions and 126 deletions.
35 changes: 33 additions & 2 deletions .github/workflows/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,36 @@ jobs:
ansible-playbook icat-ansible/icat_test_hosts.yml -i icat-ansible/hosts --vault-password-file icat-ansible/vault_pass.txt -vv
# Fixes on ICAT components needed for e2e tests
- name: Add anon user to rootUserNames
- name: Removing authenticator prefix for simple auth
run: |
awk -F" =" '/rootUserNames/{$2="= simple/root anon/anon";print;next}1' /home/runner/install/icat.server/run.properties > /home/runner/install/icat.server/run.properties.tmp
sed -i 's/mechanism = simple/!mechanism = simple/' /home/runner/install/authn.simple/run.properties
- name: Adding Chris481 user
run: |
sed -i '/user\.list/ s/$/ Chris481/' /home/runner/install/authn.simple/run.properties
- name: Adding Chris481 user password
run: |
echo "user.Chris481.password = pw" >> /home/runner/install/authn.simple/run.properties
- name: Reinstall authn.simple
run: |
cd /home/runner/install/authn.simple/ && ./setup -vv install
- name: Add anon, root (simple without prefix) and Chris481 users to rootUserNames
run: |
awk -F" =" '/rootUserNames/{$2="= root Chris481 anon/anon";print;next}1' /home/runner/install/icat.server/run.properties > /home/runner/install/icat.server/run.properties.tmp
- name: Apply rootUserNames change
run: |
mv -f /home/runner/install/icat.server/run.properties.tmp /home/runner/install/icat.server/run.properties
- name: Reinstall ICAT Server
run: |
cd /home/runner/install/icat.server/ && ./setup -vv install
- name: Add root (simple without prefix) to datagateway-download-api adminUserNames
run: |
awk -F" =" '/adminUserNames/{$2="= root";print;next}1' /home/runner/install/datagateway-download-api/run.properties > /home/runner/install/datagateway-download-api/run.properties.tmp
- name: Apply adminUserNames change
run: |
mv -f /home/runner/install/datagateway-download-api/run.properties.tmp /home/runner/install/datagateway-download-api/run.properties
- name: Reinstall datagateway-download-api
run: |
cd /home/runner/install/datagateway-download-api/ && python2 ./setup -vv install
- name: Checkout datagateway-api
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
Expand Down Expand Up @@ -166,6 +187,16 @@ jobs:
- name: Start API
run: cd datagateway-api/; nohup poetry run python -m datagateway_api.src.main > api-output.txt &

# DOI minter setup
- name: Adding 'User-defined' DataPublicationType (needed for DOI minting api)
run: cd datagateway-api/; poetry run python ../.github/add_doi_datapublicationtype.py

- name: 'Add password to env file'
run: echo DATACITE_PASSWORD=${{ secrets.DATACITE_PASSWORD }} >> ./.github/config.env

- name: Run minting api
run: docker run --env-file ./.github/config.env -p 8000:8000 --add-host host.docker.internal:host-gateway -d harbor.stfc.ac.uk/icat/doi-mint-api

# E2E tests
- name: Setup Node.js
uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4
Expand Down
Original file line number Diff line number Diff line change
@@ -1,115 +1,283 @@
export type MintResponse = Cypress.Response<{
concept: { doi: string; data_publication: string };
version: { doi: string; data_publication: string };
}>;

describe('DLS - Data Publication Landing', () => {
beforeEach(() => {
cy.login();
cy.visit('/browse/dataPublication/45');
cy.login(
{
username: 'Chris481',
password: 'pw',
mechanism: 'simple',
},
'Chris481'
);
cy.seedUserGeneratedDataPublication().as('dataPublication1');
cy.get('@dataPublication1')
.its('body.concept.data_publication')
.then((id) => cy.visit(`/browse/dataPublication/${id}`));
cy.seedDownloadCart(['datafile 550']);
});

afterEach(() => {
cy.get<MintResponse>('@dataPublication1').then((dp) => {
cy.clearUserGeneratedDataPublications([
dp.body.concept.data_publication,
dp.body.version.data_publication,
]);
});
cy.clearDownloadCart();
});

it('should load correctly', () => {
cy.title().should('equal', 'DataGateway DataView');
cy.get('#datagateway-dataview').should('be.visible');
cy.contains('Consider author watch hot someone.').should('be.visible');
cy.contains('Christina Kennedy').should('be.visible');
cy.contains('Test DOI title').should('be.visible');
cy.contains('Test DOI description').should('be.visible');
cy.contains('Thomas Chambers').should('be.visible');

cy.get<MintResponse>('@dataPublication1').then((dp) => {
cy.contains('a', dp.body.concept.doi);

cy.contains('a', dp.body.version.doi);
});
});

it('should be able to click tab to see content and it works like a normal table', () => {
cy.get('#datapublication-content-tab').first().click();

cy.get('[aria-rowcount="3"]').should('exist');
cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains('22');
cy.contains('Datafiles').click();

cy.get('[aria-rowcount="2"]').should('exist');
cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains('74');

// test sorting
cy.contains('Visit ID').click();
cy.contains('Visit ID').click();
cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains('65');
cy.contains('Name').click();
cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains('193');

// test filtering
cy.get('[aria-label="Filter by Visit ID"]').type('2');
cy.get('[aria-label="Filter by Name"]').type('7');
cy.get('[aria-rowcount="1"]').should('exist');
cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains('22');
cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains('74');
});

it('should be able to click tab to see content and switch between entity types', () => {
cy.get('#datapublication-content-tab').first().click();

cy.contains('Datasets').click();
cy.get('[aria-rowcount="0"]').should('exist');
cy.get('[aria-rowcount="1"]').should('exist');
cy.contains('Create Time').should('be.visible');
cy.contains('Location').should('not.exist');

cy.contains('Datafiles').click();
cy.get('[aria-rowcount="0"]').should('exist');
cy.get('[aria-rowcount="2"]').should('exist');
cy.contains('Location').should('be.visible');

cy.contains('Investigations').click();
cy.contains('Visit ID').should('be.visible');
cy.get('[aria-rowcount="3"]').should('exist');
cy.get('[aria-rowcount="0"]').should('exist');
});

it('should be able to click a DOI render the correct webpage ', () => {
cy.contains('a', '0-515-25376-6').should(
'have.attr',
'href',
'https://doi.org/0-515-25376-6'
);
it('should be able to click a DOI & it renders the correct webpage ', () => {
cy.get<MintResponse>('@dataPublication1').then((dp) => {
cy.contains('a', dp.body.concept.doi).should(
'have.attr',
'href',
`https://doi.org/${dp.body.concept.doi}`
);
});
});

it('should be able to use the citation formatter', () => {
cy.intercept('**/datapublications?*', [
{
id: 101224979,
pid: '10.5286/ISIS.E.RB1810842',
},
]);
cy.intercept('**/text/x-bibliography/10.5286/ISIS.E.RB1810842?*', [
'@misc{dr sabrina gaertner_mr vincent deguin_dr pierre ghesquiere_dr claire...}',
]);
it('should let the user edit their data publication', () => {
cy.get('[aria-label="Edit Data Publication"]').click();

cy.visit('/browseDataPublications/instrument/1/dataPublication/36');
cy.get('#datagateway-dataview').should('be.visible');
cy.contains('10.5286/ISIS.E.RB1810842').should('be.visible');
cy.get('[data-testid="citation-formatter-citation"]').contains(
'STFC ISIS Neutron and Muon Source, https://doi.org/10.5286/ISIS.E.RB1810842'
);
cy.contains('Generate DOI').should('be.visible');

// edit metadata
cy.contains('DOI Title')
.parent()
.find('input')
.as('titleInput')
.should('have.value', 'Test DOI title');
cy.contains('DOI Description')
.parent()
.find('textarea')
.first()
.as('descriptionInput')
.should('have.value', 'Test DOI description');

cy.get('@titleInput').clear();
cy.get('@titleInput').type('New DOI title');

cy.get('@descriptionInput').clear();
cy.get('@descriptionInput').type('New DOI description');

cy.contains('Username').parent().find('input').type('Michael222');
cy.contains('button', 'Add Creator').click();

// DOI from https://support.datacite.org/docs/testing-guide
cy.contains(/^DOI$/).parent().find('input').type('10.17596/w76y-4s92');
cy.contains('button', 'Add DOI').click();
cy.contains('label', 'Resource Type').parent().click();
cy.contains('Journal').click();
cy.contains('label', 'Relationship').parent().click();
cy.contains('IsCitedBy').click();

// edit content
cy.contains('Datafiles').click();
cy.get('[aria-label="Edit data"]').click();

cy.contains('Datafile 550').click();
cy.contains('>').click();

cy.contains('Datafile 193').click();
cy.contains('<').click();

cy.contains('Done').click();

cy.contains('button', 'Generate DOI').click();

cy.contains('Mint Confirmation').should('be.visible');
cy.contains('Mint was successful', { timeout: 10000 }).should('be.visible');
cy.contains('View Data Publication').click();

cy.get('#citation-formatter').click();
// check data is updated
cy.contains('New DOI title').should('be.visible');
cy.contains('New DOI description').should('be.visible');
cy.contains('Randy Beasley').should('be.visible');

cy.get('[data-testid="landing-dataPublication-pid-link"]')
.first()
.invoke('text')
.as('newVersionDOI');

// visit concept DOI and check it's updated there
cy.get('@dataPublication1')
.its('body.concept.data_publication')
.then((id) => cy.visit(`/browse/dataPublication/${id}`));

cy.contains('New DOI title').should('be.visible');
cy.contains('New DOI description').should('be.visible');
cy.contains('Randy Beasley').should('be.visible');

cy.get('@newVersionDOI').then((doi) => {
cy.contains('Latest Version DOI')
.parent()
.next()
.should('contain.text', doi);
});

cy.get(
'#version-panel-content [data-testid="landing-dataPublication-pid-link"]'
).should('have.length', 2);
});

it('should be able to use the citation formatters', () => {
cy.contains('Test DOI title').should('be.visible');

cy.get<MintResponse>('@dataPublication1').then((response) => {
cy.intercept(`**/text/x-bibliography/${response.body.concept.doi}?*`, [
'@misc{dr sabrina gaertner_mr vincent deguin_dr pierre ghesquiere_dr claire...}',
]);

cy.intercept(`**/text/x-bibliography/${response.body.version.doi}?*`, [
'@misc{dr alice barrett_mr charlie deguin_dr elizabeth francis_dr gary...}',
]);

cy.get(
'[data-testid="Latest-Version-Data-Citation-citation-formatter-citation"]'
)
.first()
.contains(
`STFC ISIS Neutron and Muon Source, https://doi.org/${response.body.version.doi}`
);
cy.get(
'[data-testid="Concept-Data-Citation-citation-formatter-citation"]'
)
.last()
.contains(
`STFC ISIS Neutron and Muon Source, https://doi.org/${response.body.concept.doi}`
);
});

cy.get('#Concept-Data-Citation-citation-formatter').click();
cy.get('[role="listbox"]')
.find('[role="option"]')
.should('have.length.gte', 2);

cy.get('[role="option"][data-value="bibtex"]').click();
cy.get('[data-testid="citation-formatter-citation"]').contains(
cy.get(
'[data-testid="Concept-Data-Citation-citation-formatter-citation"]'
).contains(
'@misc{dr sabrina gaertner_mr vincent deguin_dr pierre ghesquiere_dr claire'
);
cy.get('#citation-formatter-error-message').should('not.exist');
cy.get('#Concept-Data-Citation-citation-formatter-error-message').should(
'not.exist'
);

cy.get('#Latest-Version-Data-Citation-citation-formatter').click();
cy.get('[role="listbox"]')
.find('[role="option"]')
.should('have.length.gte', 2);

cy.get('[role="option"][data-value="bibtex"]').click();
cy.get(
'[data-testid="Latest-Version-Data-Citation-citation-formatter-citation"]'
).contains(
'@misc{dr alice barrett_mr charlie deguin_dr elizabeth francis_dr gary'
);
cy.get(
'#Latest-Version-Data-Citation-citation-formatter-error-message'
).should('not.exist');
});

it('citation formatter should give an error when there is a problem', () => {
cy.intercept('**/datapublications?*', [
{
id: 101224979,
pid: 'invaliddoi',
},
]);
cy.intercept('**/text/x-bibliography/invaliddoi?*', {
statusCode: 503,
it('citation formatters should give an error when there is a problem', () => {
cy.contains('Test DOI title').should('be.visible');

cy.get<MintResponse>('@dataPublication1').then((response) => {
cy.intercept(`**/text/x-bibliography/${response.body.concept.doi}?*`, {
statusCode: 503,
});

cy.intercept(`**/text/x-bibliography/${response.body.version.doi}?*`, {
statusCode: 503,
});

cy.get(
'[data-testid="Latest-Version-Data-Citation-citation-formatter-citation"]'
)
.first()
.contains(
`STFC ISIS Neutron and Muon Source, https://doi.org/${response.body.version.doi}`
);
cy.get(
'[data-testid="Concept-Data-Citation-citation-formatter-citation"]'
)
.last()
.contains(
`STFC ISIS Neutron and Muon Source, https://doi.org/${response.body.concept.doi}`
);
});
cy.visit('/browseDataPublications/instrument/1/dataPublication/36');
cy.get('#datagateway-dataview').should('be.visible');
cy.contains('invaliddoi').should('be.visible');

//Default citation
cy.get('[data-testid="citation-formatter-citation"]').contains(
'STFC ISIS Neutron and Muon Source, https://doi.org/invaliddoi'
);
cy.get('#Concept-Data-Citation-citation-formatter').click();
cy.get('[role="listbox"]')
.find('[role="option"]')
.should('have.length.gte', 2);

cy.get('[role="option"][data-value="chicago-author-date"]').click();
cy.get('#Concept-Data-Citation-citation-formatter-error-message', {
timeout: 10000,
}).should('exist');

cy.get('#citation-formatter').click();
cy.get('#Latest-Version-Data-Citation-citation-formatter').click();
cy.get('[role="listbox"]')
.find('[role="option"]')
.should('have.length.gte', 2);

cy.get('[role="option"][data-value="chicago-author-date"]').click();
cy.get('#citation-formatter-error-message', { timeout: 10000 }).should(
'exist'
);
cy.get('#Latest-Version-Data-Citation-citation-formatter-error-message', {
timeout: 10000,
}).should('exist');
});
});
Loading

0 comments on commit f2cbfb3

Please sign in to comment.