Skip to content

Commit

Permalink
e2e: rewrite submission tests
Browse files Browse the repository at this point in the history
  • Loading branch information
karolina-siemieniuk-morawska committed Aug 30, 2023
1 parent a38b42b commit 3fb6fad
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 87 deletions.
40 changes: 6 additions & 34 deletions e2e/cypress/e2e/authors.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ describe('Author Submission', () => {
});
});

it.skip('submits a new author', () => {
it('submits a new author', () => {
cy.login('cataloger');

const formData = {
given_name: 'Diego',
family_name: 'Martínez Santos',
Expand All @@ -88,45 +89,16 @@ describe('Author Submission', () => {
},
],
};
const expectedMetadata = {
name: {
preferred_name: 'Diego Martínez',
value: 'Martínez Santos, Diego',
name_variants: ['Santos, Diego Martinez'],
},
acquisition_source: {
email: 'cataloger@inspirehep.net',
method: 'submitter',
},
arxiv_categories: ['hep-ex', 'hep-ph'],
email_addresses: [
{ value: 'diego@martinez.ch', current: true },
{ value: 'private@martinez.ch', hidden: true },
],
status: 'retired',
positions: [
{
curated_relation: false,
current: true,
institution: 'CERN',
start_date: '2015',
},
],
advisors: [
{
curated_relation: false,
name: 'Urhan, Harun',
},
],
};
const expectedWorkflow = {
_workflow: { data_type: 'authors' },
};

cy.visit('/submissions/authors');
cy.testSubmission({
collection: 'authors',
formData,
expectedMetadata,
formData,
collection: 'authors',
submissionType: 'workflow'
}).then((newWorkflow) => {
cy.wrap(newWorkflow).should('like', expectedWorkflow);
});
Expand Down
1 change: 0 additions & 1 deletion e2e/cypress/e2e/conferences.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ describe('Conference Submission', () => {
});

it.skip('warns about already existing conference during selected dates [conferences/1794610]', () => {
const startDate = moment('2021-08-30');
cy.visit('/submissions/conferences');
cy.registerRoute();
cy.fillForm({
Expand Down
74 changes: 22 additions & 52 deletions e2e/cypress/support/commands/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,18 @@ Cypress.Commands.add('selectLiteratureDocType', (docType) => {
.should('be.hidden'); // wait for dropdown menu to be closed before proceeding further.
});

Cypress.Commands.add('testWorkflow', () => {
cy.get('.ant-alert-message').should(
'have.text',
'Successfully submitted, thank you! Your submission will be visible upon approval from the INSPIRE team.'
);
});
Cypress.Commands.add('testRecord', (expectedMetadata) => {});
Cypress.Commands.add('testEditor', (expectedMetadata) => {cy.get('.btn .navbar-btn .btn-success')});

Cypress.Commands.add(
'testSubmission',
({ expectedMetadata, formData, collection }) => {
({ expectedMetadata, formData, collection, submissionType }) => {
const route = `/submissions/${collection}`;
const apiRoute = `/api${route}`;

Expand All @@ -25,57 +34,18 @@ Cypress.Commands.add(
method: 'POST',
});
cy.submitForm(formData);
return cy
.waitForRoute(apiRoute)
.then((xhr) => {
const mapIdToRequest = () => {
if (xhr.response.body.pid_value) {
return {
status: cy
.wrap(xhr)
.its('response.statusCode')
.should('equal', 201),
request: cy.requestRecord({
collection,
recordId: xhr.response.body.pid_value,
}),
};
} else if (xhr.response.body.control_number) {
return {
status: cy
.wrap(xhr)
.its('response.statusCode')
.should('equal', 201),
request: cy.requestEditor({
collection,
recordId: xhr.response.body.control_number,
}),
};
} else {
return {
status: cy
.wrap(xhr)
.its('response.statusCode')
.should('equal', 200),
request: cy
.requestWorkflow(
{workflowId: xhr.response.body.workflow_object_id}
)
.its('body'),
};
}
};
mapIdToRequest().status;
return mapIdToRequest().request;
})
.then((recordOrWorkflow) => {
const metadata = recordOrWorkflow.metadata;

if (!REDIRECT_TO_EDITOR.includes(collection)) {
expect(metadata).like(expectedMetadata);
return recordOrWorkflow;
}
});
return cy.waitForRoute(apiRoute).then(() => {
if (submissionType === 'workflow') {
cy.testWorkflow();
}
if (submissionType === 'record') {
cy.testRecord(expectedMetadata);
}
if (submissionType === 'editor') {
cy.testEditor(expectedMetadata);
}
return null;
});
}
);

Expand Down

0 comments on commit 3fb6fad

Please sign in to comment.