Skip to content

Commit

Permalink
Merge pull request #1 from asmecher/i7191_submission_wizard
Browse files Browse the repository at this point in the history
pkp/pkp-lib#7191 Reimplement aclark submission for API-based process
  • Loading branch information
NateWr authored Nov 23, 2022
2 parents 830a3e4 + 553e8bc commit 474959a
Show file tree
Hide file tree
Showing 21 changed files with 1,489 additions and 405 deletions.
4 changes: 2 additions & 2 deletions controllers/grid/settings/series/form/SeriesForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function ($path) use ($form, $pressId) {
));
}

public function getSeries(): Series
public function getSeries(): ?Series
{
return $this->section;
}
Expand Down Expand Up @@ -197,7 +197,7 @@ public function fetch($request, $template = null, $display = false)

$templateMgr->assign([
'allCategories' => $allCategories,
'selectedCategories' => $this->getData('categories')->values()->all(),
'selectedCategories' => $this->getData('categories')?->values()?->all() ?? [],
]);

return parent::fetch($request, $template, $display);
Expand Down
4 changes: 3 additions & 1 deletion cypress.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
"contextAcronyms": {
"en_US": "PKP"
},
"defaultGenre": "Book Manuscript"
"defaultGenre": "Book Manuscript",
"authorUserGroupId": 13,
"volumeEditorUserGroupId": 14
},
"integrationFolder": "cypress/tests",
"pluginsFile": "lib/pkp/cypress/plugins/index.js",
Expand Down
67 changes: 67 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*
*/

import Api from '../../lib/pkp/cypress/support/api.js';
import '../../lib/pkp/cypress/support/commands';

Cypress.Commands.add('addToCatalog', function() {
Expand All @@ -15,4 +16,70 @@ Cypress.Commands.add('addToCatalog', function() {
cy.get('div.pkpWorkflow__publishModal button:contains("Publish")').click();
});

Cypress.Commands.add('addChapters', (chapters) => {
chapters.forEach(chapter => {
cy.waitJQuery();
cy.get('a[id^="component-grid-users-chapter-chaptergrid-addChapter-button-"]:visible').click();
cy.wait(2000); // Avoid occasional failure due to form init taking time

// Contributors
chapter.contributors.forEach(contributor => {
cy.get('form[id="editChapterForm"] label:contains("' + Cypress.$.escapeSelector(contributor) + '")').click();
});

// Title/subtitle
cy.get('form[id="editChapterForm"] input[id^="title-en_US-"]').type(chapter.title, {delay: 0});
if ('subtitle' in chapter) {
cy.get('form[id="editChapterForm"] input[id^="subtitle-en_US-"]').type(chapter.subtitle, {delay: 0});
}
cy.get('div.pkp_modal_panel div:contains("Add Chapter")').click(); // FIXME: Resolve focus problem on title field

cy.flushNotifications();
cy.get('form[id="editChapterForm"] button:contains("Save")').click();
cy.get('div:contains("Your changes have been saved.")');
cy.waitJQuery();

// Files
if ('files' in chapter) {
cy.get('div[id="chaptersGridContainer"] a:contains("' + Cypress.$.escapeSelector(chapter.title) + '")').click();
chapter.files.forEach(file => {
cy.get('form[id="editChapterForm"] label:contains("' + Cypress.$.escapeSelector(file) + '")').click();
//cy.get('form[id="editChapterForm"] label:contains("' + Cypress.$.escapeSelector(chapter.title.substring(0, 40)) + '")').click();
});
cy.flushNotifications();
cy.get('form[id="editChapterForm"] button:contains("Save")').click();
cy.get('div:contains("Your changes have been saved.")');
}

cy.get('div[id^="component-grid-users-chapter-chaptergrid-"] a.pkp_linkaction_editChapter:contains("' + Cypress.$.escapeSelector(chapter.title) + '")');
});
});

Cypress.Commands.add('createSubmissionWithApi', (data, csrfToken) => {
const api = new Api(Cypress.env('baseUrl') + '/index.php/publicknowledge/api/v1');

return cy.beginSubmissionWithApi(api, data, csrfToken)
.putMetadataWithApi(data, csrfToken)
.get('@submissionId').then((submissionId) => {
if (typeof data.files === 'undefined' || !data.files.length) {
return;
}
cy.visit('/index.php/publicknowledge/submission?id=' + submissionId);

// Must use the UI to upload files until we upgrade Cypress
// to 7.4.0 or higher.
// @see https://github.com/cypress-io/cypress/issues/1647
cy.uploadSubmissionFiles(data.files);

})
.then(() => {
cy.get('.pkpButton--isPrimary').click();
cy.get('.pkpSteps__step__label--current span:contains("2")');
cy.get('.pkpButton--isPrimary').click();
cy.get('.pkpSteps__step__label--current span:contains("3")');
})
.addSubmissionAuthorsWithApi(api, data, csrfToken)
.addChapters(data.chapters);
});


3 changes: 3 additions & 0 deletions cypress/tests/data/50-CreateSeries.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,23 @@ describe('Data suite tests', function() {
cy.get('a[id^=component-grid-settings-series-seriesgrid-addSeries-button-]').click();
cy.wait(1000); // Avoid occasional failure due to form init taking time
cy.get('input[id^="title-en_US-"]').type('History');
cy.get('label').contains('Daniel Barnes').click();
cy.get('input[id^="path"]').type('his');
cy.get('form[id=seriesForm]').contains('Save').click();

// Create a new "Education" series
cy.get('a[id^=component-grid-settings-series-seriesgrid-addSeries-button-]').click();
cy.wait(1000); // Avoid occasional failure due to form init taking time
cy.get('input[id^="title-en_US-"]').type('Education');
cy.get('label').contains('Daniel Barnes').click();
cy.get('input[id^="path"]').type('ed');
cy.get('form[id=seriesForm]').contains('Save').click();

// Create a new "Psychology" series
cy.get('a[id^=component-grid-settings-series-seriesgrid-addSeries-button-]').click();
cy.wait(1000); // Avoid occasional failure due to form init taking time
cy.get('input[id^="title-en_US-"]').type('Psychology');
cy.get('label').contains('Daniel Barnes').click();
cy.get('input[id^="path"]').type('psy');
cy.get('form[id=seriesForm]').contains('Save').click();
});
Expand Down
80 changes: 61 additions & 19 deletions cypress/tests/data/60-content/AclarkSubmission.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,41 +11,83 @@
*/

describe('Data suite tests', function() {
it('Create a submission', function() {
cy.register({
'username': 'aclark',
'givenName': 'Arthur',
'familyName': 'Clark',
'affiliation': 'University of Calgary',
'country': 'Canada'
});

var submission = {
'type': 'monograph',
'title': 'The ABCs of Human Survival: A Paradigm for Global Citizenship',
'abstract': 'The ABCs of Human Survival examines the effect of militant nationalism and the lawlessness of powerful states on the well-being of individuals and local communities―and the essential role of global citizenship within that dynamic. Based on the analysis of world events, Dr. Arthur Clark presents militant nationalism as a pathological pattern of thinking that threatens our security, while emphasizing effective democracy and international law as indispensable frameworks for human protection.',
'submitterRole': 'Author',
'chapters': [
let submission;
before(function() {
const title = 'The ABCs of Human Survival: A Paradigm for Global Citizenship';
submission = {
id: 0,
prefix: '',
title: title,
subtitle: '',
abstract: 'The ABCs of Human Survival examines the effect of militant nationalism and the lawlessness of powerful states on the well-being of individuals and local communities―and the essential role of global citizenship within that dynamic. Based on the analysis of world events, Dr. Arthur Clark presents militant nationalism as a pathological pattern of thinking that threatens our security, while emphasizing effective democracy and international law as indispensable frameworks for human protection.',
shortAuthorString: 'Clark',
authorNames: ['Arthur Clark'],
sectionId: 1,
assignedAuthorNames: ['Arthur Clark'],
files: [
{
'file': 'dummy.pdf',
'fileName': 'chapter1.pdf',
'mimeType': 'application/pdf',
'genre': Cypress.env('defaultGenre')
},
{
'file': 'dummy.pdf',
'fileName': 'chapter2.pdf',
'mimeType': 'application/pdf',
'genre': Cypress.env('defaultGenre')
},
{
'file': 'dummy.pdf',
'fileName': 'chapter3.pdf',
'mimeType': 'application/pdf',
'genre': Cypress.env('defaultGenre')
}
],
chapters: [
{
'title': 'Choosing the Future',
'contributors': ['Arthur Clark']
'contributors': ['Arthur Clark'],
files: ['chapter1.pdf']
},
{
'title': 'Axioms',
'contributors': ['Arthur Clark']
'contributors': ['Arthur Clark'],
files: ['chapter2.pdf']
},
{
'title': 'Paradigm Shift',
'contributors': ['Arthur Clark']
'contributors': ['Arthur Clark'],
files: ['chapter3.pdf']
}
],
workType: 'monograph'
};
cy.createSubmission(submission);
});

it('Create a submission', function() {
cy.register({
'username': 'aclark',
'givenName': 'Arthur',
'familyName': 'Clark',
'affiliation': 'University of Calgary',
'country': 'Canada'
});

cy.getCsrfToken();
cy.window()
.then(() => {
return cy.createSubmissionWithApi(submission, this.csrfToken);
})
.then(xhr => {
return cy.submitSubmissionWithApi(submission.id, this.csrfToken);
});
cy.logout();

cy.findSubmissionAsEditor('dbarnes', null, 'Clark');
cy.clickDecision('Send to External Review');
cy.recordDecisionSendToReview('Send to External Review', ['Arthur Clark'], [submission.title]);
cy.recordDecisionSendToReview('Send to External Review', ['Arthur Clark'], ['chapter1.pdf', 'chapter2.pdf', 'chapter3.pdf']);
cy.isActiveStageTab('External Review');
cy.assignReviewer('Gonzalo Favio');
cy.clickDecision('Accept Submission');
Expand Down
Loading

0 comments on commit 474959a

Please sign in to comment.