Skip to content

Commit f87dcb5

Browse files
committed
pkp/pkp-lib#7191 Split submission creation commands into pieces; fix author data
1 parent 2c7cc28 commit f87dcb5

20 files changed

+124
-336
lines changed

cypress/support/commands.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*
88
*/
99

10+
import Api from '../../lib/pkp/cypress/support/api.js';
1011
import '../../lib/pkp/cypress/support/commands';
1112

1213
Cypress.Commands.add('addCategory', (categoryName, categoryPath) => {
@@ -24,3 +25,51 @@ Cypress.Commands.add('isInIssue', (submissionTitle, issueTitle) => {
2425
cy.get('a:contains("' + issueTitle + '")').click();
2526
cy.get('a:contains("' + submissionTitle + '")');
2627
});
28+
29+
Cypress.Commands.add('addSubmissionGalleys', (files) => {
30+
files.forEach(file => {
31+
cy.get('a:contains("Add File")').click();
32+
cy.wait(2000); // Avoid occasional failure due to form init taking time
33+
cy.get('div.pkp_modal_panel').then($modalDiv => {
34+
cy.wait(3000);
35+
$modalDiv.find('div.header:contains("Add File")');
36+
cy.get('div.pkp_modal_panel input[id^="label-"]').type('PDF', {delay: 0});
37+
cy.get('div.pkp_modal_panel button:contains("Save")').click();
38+
cy.wait(2000); // Avoid occasional failure due to form init taking time
39+
});
40+
cy.get('select[id=genreId]').select(file.genre);
41+
cy.fixture(file.file, 'base64').then(fileContent => {
42+
cy.get('input[type=file]').attachFile(
43+
{fileContent, 'filePath': file.fileName, 'mimeType': 'application/pdf', 'encoding': 'base64'}
44+
);
45+
});
46+
cy.get('#continueButton').click();
47+
cy.wait(2000);
48+
for (const field in file.metadata) {
49+
cy.get('input[id^="' + Cypress.$.escapeSelector(field) + '"]:visible,textarea[id^="' + Cypress.$.escapeSelector(field) + '"]').type(file.metadata[field], {delay: 0});
50+
cy.get('input[id^="language"').click({force: true}); // Close multilingual and datepicker pop-overs
51+
}
52+
cy.get('#continueButton').click();
53+
cy.get('#continueButton').click();
54+
});
55+
});
56+
57+
Cypress.Commands.add('createSubmissionWithApi', (data, csrfToken) => {
58+
const api = new Api(Cypress.env('baseUrl') + '/index.php/publicknowledge/api/v1');
59+
60+
return cy.beginSubmissionWithApi(api, data, csrfToken)
61+
.putMetadataWithApi(data, csrfToken)
62+
.get('@submissionId').then((submissionId) => {
63+
if (typeof data.files === 'undefined' || !data.files.length) {
64+
return;
65+
}
66+
cy.visit('/index.php/publicknowledge/submission?id=' + submissionId);
67+
68+
// Must use the UI to upload files until we upgrade Cypress
69+
// to 7.4.0 or higher.
70+
// @see https://github.com/cypress-io/cypress/issues/1647
71+
cy.addSubmissionGalleys(data.files);
72+
})
73+
.addSubmissionAuthorsWithApi(api, data, csrfToken);
74+
});
75+

cypress/tests/data/60-content/CcorinoSubmission.spec.js

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,6 @@ describe('Data suite: Ccorino', function() {
2323
authorNames: ['Carla Corino'],
2424
sectionId: 1,
2525
assignedAuthorNames: ['Carla Corino'],
26-
authors: [
27-
{
28-
givenName: 'Carla',
29-
familyName: 'Corino',
30-
31-
country: 'Italy',
32-
affiliation: 'University of Bologna'
33-
}
34-
],
3526
files: [
3627
{
3728
'file': 'dummy.pdf',
@@ -52,19 +43,13 @@ describe('Data suite: Ccorino', function() {
5243
'country': 'Italy'
5344
});
5445

55-
// Go to page where CSRF token is available
56-
cy.visit('/index.php/publicknowledge/user/profile');
57-
58-
let csrfToken = '';
46+
cy.getCsrfToken();
5947
cy.window()
60-
.then((win) => {
61-
csrfToken = win.pkp.currentUser.csrfToken;
62-
})
6348
.then(() => {
64-
return cy.createSubmissionWithApi(submission, csrfToken);
49+
return cy.createSubmissionWithApi(submission, this.csrfToken);
6550
})
66-
.then(xhr => {
67-
return cy.submitSubmissionWithApi(submission.id, csrfToken);
51+
.then(() => {
52+
return cy.submitSubmissionWithApi(submission.id, this.csrfToken);
6853
});
6954
});
7055
})

cypress/tests/data/60-content/CkwantesSubmission.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ describe('Data suite: Ckwantes', function() {
8686
// Upload files and set file genres
8787
cy.get('h2').contains('Upload Files');
8888
cy.get('h2').contains('Files');
89-
cy.uploadSubmissionFiles(submission.files);
89+
cy.addSubmissionGalleys(submission.files);
9090

9191
cy.get('.submissionWizard__footer button').contains('Continue').click();
9292

cypress/tests/data/60-content/CmontgomerieSubmission.spec.js

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,14 @@ describe('Data suite: Cmontgomerie', function() {
2424
authorNames: ['Craig Montgomerie', 'Mark Irvine'],
2525
sectionId: 1,
2626
assignedAuthorNames: ['Craig Montgomerie'],
27-
authors: [
27+
additionalAuthors: [
2828
{
29-
givenName: 'Craig',
30-
familyName: 'Montgomerie',
31-
32-
country: 'Canada',
33-
affiliation: 'University of Alberta'
34-
},
35-
{
36-
givenName: 'Mark',
37-
familyName: 'Irvine',
38-
country: 'Canada',
39-
affiliation: 'University of Victoria',
40-
29+
givenName: {en_US: 'Mark'},
30+
familyName: {en_US: 'Irvine'},
31+
country: 'CA',
32+
affiliation: {en_US: 'University of Victoria'},
33+
34+
userGroupId: Cypress.env('authorUserGroupId')
4135
}
4236
],
4337
files: [
@@ -70,19 +64,13 @@ describe('Data suite: Cmontgomerie', function() {
7064
'country': 'Canada'
7165
});
7266

73-
// Go to page where CSRF token is available
74-
cy.visit('/index.php/publicknowledge/user/profile');
75-
76-
let csrfToken = '';
67+
cy.getCsrfToken();
7768
cy.window()
78-
.then((win) => {
79-
csrfToken = win.pkp.currentUser.csrfToken;
80-
})
8169
.then(() => {
82-
return cy.createSubmissionWithApi(submission, csrfToken);
70+
return cy.createSubmissionWithApi(submission, this.csrfToken);
8371
})
8472
.then(xhr => {
85-
return cy.submitSubmissionWithApi(submission.id, csrfToken);
73+
return cy.submitSubmissionWithApi(submission.id, this.csrfToken);
8674
});
8775

8876
cy.logout();

cypress/tests/data/60-content/DdioufSubmission.spec.js

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,6 @@ describe('Data suite: Ddiouf', function() {
2323
authorNames: ['Diaga Diouf'],
2424
sectionId: 1,
2525
assignedAuthorNames: ['Diaga Diouf'],
26-
authors: [
27-
{
28-
givenName: 'Diaga',
29-
familyName: 'Diouf',
30-
31-
country: 'Egypt',
32-
affiliation: 'Alexandria University'
33-
}
34-
],
3526
files: [
3627
{
3728
'file': 'dummy.pdf',
@@ -52,19 +43,13 @@ describe('Data suite: Ddiouf', function() {
5243
'country': 'Egypt',
5344
});
5445

55-
// Go to page where CSRF token is available
56-
cy.visit('/index.php/publicknowledge/user/profile');
57-
58-
let csrfToken = '';
46+
cy.getCsrfToken();
5947
cy.window()
60-
.then((win) => {
61-
csrfToken = win.pkp.currentUser.csrfToken;
62-
})
6348
.then(() => {
64-
return cy.createSubmissionWithApi(submission, csrfToken);
49+
return cy.createSubmissionWithApi(submission, this.csrfToken);
6550
})
6651
.then(xhr => {
67-
return cy.submitSubmissionWithApi(submission.id, csrfToken);
52+
return cy.submitSubmissionWithApi(submission.id, this.csrfToken);
6853
});
6954
});
7055

cypress/tests/data/60-content/DphillipsSubmission.spec.js

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,6 @@ describe('Data suite: Dphillips', function() {
2323
authorNames: ['Dana Phillips'],
2424
sectionId: 1,
2525
assignedAuthorNames: ['Dana Phillips'],
26-
authors: [
27-
{
28-
givenName: 'Dana',
29-
familyName: 'Phillips',
30-
31-
country: 'Canada',
32-
affiliation: 'University of Toronto'
33-
}
34-
],
3526
files: [
3627
{
3728
'file': 'dummy.pdf',
@@ -52,19 +43,13 @@ describe('Data suite: Dphillips', function() {
5243
'country': 'Canada',
5344
});
5445

55-
// Go to page where CSRF token is available
56-
cy.visit('/index.php/publicknowledge/user/profile');
57-
58-
let csrfToken = '';
46+
cy.getCsrfToken();
5947
cy.window()
60-
.then((win) => {
61-
csrfToken = win.pkp.currentUser.csrfToken;
62-
})
6348
.then(() => {
64-
return cy.createSubmissionWithApi(submission, csrfToken);
49+
return cy.createSubmissionWithApi(submission, this.csrfToken);
6550
})
6651
.then(xhr => {
67-
return cy.submitSubmissionWithApi(submission.id, csrfToken);
52+
return cy.submitSubmissionWithApi(submission.id, this.csrfToken);
6853
});
6954

7055
cy.logout();

cypress/tests/data/60-content/DsokoloffSubmission.spec.js

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,6 @@ describe('Data suite: Dsokoloff', function() {
2323
authorNames: ['Domatilia Sokoloff'],
2424
sectionId: 1,
2525
assignedAuthorNames: ['Domatilia Sokoloff'],
26-
authors: [
27-
{
28-
givenName: 'Domatilia',
29-
familyName: 'Sokoloff',
30-
31-
country: 'Ireland',
32-
affiliation: 'University College Cork'
33-
}
34-
],
3526
files: [
3627
{
3728
'file': 'dummy.pdf',
@@ -57,19 +48,13 @@ describe('Data suite: Dsokoloff', function() {
5748
'country': 'Ireland',
5849
});
5950

60-
// Go to page where CSRF token is available
61-
cy.visit('/index.php/publicknowledge/user/profile');
62-
63-
let csrfToken = '';
51+
cy.getCsrfToken();
6452
cy.window()
65-
.then((win) => {
66-
csrfToken = win.pkp.currentUser.csrfToken;
67-
})
6853
.then(() => {
69-
return cy.createSubmissionWithApi(submission, csrfToken);
54+
return cy.createSubmissionWithApi(submission, this.csrfToken);
7055
})
7156
.then(xhr => {
72-
return cy.submitSubmissionWithApi(submission.id, csrfToken);
57+
return cy.submitSubmissionWithApi(submission.id, this.csrfToken);
7358
});
7459

7560
cy.logout();

cypress/tests/data/60-content/EostromSubmission.spec.js

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,14 @@ describe('Data suite: Eostrom', function() {
2323
authorNames: ['Elinor Ostrom'],
2424
sectionId: 1,
2525
assignedAuthorNames: ['Elinor Ostrom'],
26-
authors: [
26+
additionalAuthors: [
2727
{
28-
givenName: 'Elinor',
29-
familyName: 'Ostrom',
30-
31-
country: 'United States',
32-
affiliation: 'Indiana University'
33-
},
34-
{
35-
givenName: 'Frank',
36-
familyName: 'van Laerhoven',
28+
givenName: {en_US: 'Frank'},
29+
familyName: {en_US: 'van Laerhoven'},
30+
country: 'US',
31+
affiliation: {en_US: 'Indiana University'},
3732
38-
country: 'United States',
39-
affiliation: 'Indiana University'
33+
userGroupId: Cypress.env('authorUserGroupId')
4034
}
4135
],
4236
files: [
@@ -65,19 +59,13 @@ describe('Data suite: Eostrom', function() {
6559
'country': 'United States',
6660
});
6761

68-
// Go to page where CSRF token is available
69-
cy.visit('/index.php/publicknowledge/user/profile');
70-
71-
let csrfToken = '';
62+
cy.getCsrfToken();
7263
cy.window()
73-
.then((win) => {
74-
csrfToken = win.pkp.currentUser.csrfToken;
75-
})
7664
.then(() => {
77-
return cy.createSubmissionWithApi(submission, csrfToken);
65+
return cy.createSubmissionWithApi(submission, this.csrfToken);
7866
})
7967
.then(xhr => {
80-
return cy.submitSubmissionWithApi(submission.id, csrfToken);
68+
return cy.submitSubmissionWithApi(submission.id, this.csrfToken);
8169
});
8270

8371
cy.logout();

cypress/tests/data/60-content/FpaglieriSubmission.spec.js

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,6 @@ describe('Data suite: Fpaglieri', function() {
2323
authorNames: ['Fabio Paglieri'],
2424
sectionId: 1,
2525
assignedAuthorNames: ['Fabio Paglieri'],
26-
authors: [
27-
{
28-
givenName: 'Fabio',
29-
familyName: 'Paglieri',
30-
31-
country: 'Italy',
32-
affiliation: 'University of Rome'
33-
}
34-
],
3526
files: [
3627
{
3728
'file': 'dummy.pdf',
@@ -52,19 +43,13 @@ describe('Data suite: Fpaglieri', function() {
5243
'country': 'Italy',
5344
});
5445

55-
// Go to page where CSRF token is available
56-
cy.visit('/index.php/publicknowledge/user/profile');
57-
58-
let csrfToken = '';
46+
cy.getCsrfToken();
5947
cy.window()
60-
.then((win) => {
61-
csrfToken = win.pkp.currentUser.csrfToken;
62-
})
6348
.then(() => {
64-
return cy.createSubmissionWithApi(submission, csrfToken);
49+
return cy.createSubmissionWithApi(submission, this.csrfToken);
6550
})
6651
.then(xhr => {
67-
return cy.submitSubmissionWithApi(submission.id, csrfToken);
52+
return cy.submitSubmissionWithApi(submission.id, this.csrfToken);
6853
});
6954

7055
cy.logout();

0 commit comments

Comments
 (0)