From 91e97360213e36f7d2724aa46364487628795bbb Mon Sep 17 00:00:00 2001 From: Vitaliy Bezsheiko Date: Sun, 10 Jan 2021 20:10:59 +0200 Subject: [PATCH] #61 All Cypress tests --- .travis.yml | 34 ++++ cypress/tests/functional/Immersion.spec.js | 197 +++++++++++++++++++++ 2 files changed, 231 insertions(+) create mode 100644 .travis.yml create mode 100644 cypress/tests/functional/Immersion.spec.js diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..281f9a9 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,34 @@ +# @file +# .travis.yml - PKP Plugins Integration + +language: php + +addons: + apt: + update: true + +sudo: required + +php: + - 7.3 + - 7.4 +env: + - APPLICATION=ojs BRANCH=master TEST=mysql + - APPLICATION=ojs BRANCH=master TEST=pgsql + +install: + # Prepare OJS environment + - git clone -b ${BRANCH} https://github.com/pkp/${APPLICATION} ~/${APPLICATION} + - cd ~/${APPLICATION} + - git submodule update --init --recursive + - source lib/pkp/tools/travis/prepare-tests.sh + - lib/pkp/tools/travis/prepare-webserver.sh + # Build/install dependencies + - lib/pkp/tools/travis/install-composer-dependencies.sh + - npm i g -npm && npm install && npm run build + - ln -s ${TRAVIS_BUILD_DIR} ~/${APPLICATION}/plugins/themes/immersion + # Install OJS & prep data environment + - $(npm bin)/cypress run --spec "cypress/tests/data/*.spec.js,cypress/tests/data/60-content/VkarbasizaedSubmission.spec.js" + +script: + - $(npm bin)/cypress run --config integrationFolder=plugins/themes/immersion/cypress/tests/functional diff --git a/cypress/tests/functional/Immersion.spec.js b/cypress/tests/functional/Immersion.spec.js new file mode 100644 index 0000000..6b8b10c --- /dev/null +++ b/cypress/tests/functional/Immersion.spec.js @@ -0,0 +1,197 @@ +/** + * @file cypress/tests/functional/Immersion.spec.js + * + * Copyright (c) 2014-2020 Simon Fraser University + * Copyright (c) 2000-2020 John Willinsky + * Distributed under the GNU GPL v2. For full terms see the file docs/COPYING. + * + */ + +describe('Theme plugin tests', function() { + const journalPath = 'publicknowledge'; + const index = 'index.php'; + const path = '/' + index + '/' + journalPath; + + const date = new Date(); + const day = date.getDate() + ''; + const month = (function() { + let numericMonth = (date.getMonth() + 1) + ''; + if ([...numericMonth].length === 1) { + numericMonth = '0' + numericMonth; + } + return numericMonth; + })(); + const year = date.getFullYear() + ''; + + const user = { + 'givenName': 'John', + 'familyName': 'Debreenik', + 'username': 'jdebreenik', + 'country': 'UA', + 'affiliation': 'Lorem Ipsum University' + }; + + const journalDescription = 'Sed elementum ligula sit amet velit gravida fermentum. Ut mi risus, dapibus nec tincidunt eget, tincidunt eget nulla.'; + const categoryDescription = 'Maecenas imperdiet sodales ligula et tempor. Phasellus urna sem, efficitur sed nisi egestas, lacinia elementum quam.'; + + it('Enables and selects the theme', function() { + cy.login('admin', 'admin', 'publicknowledge'); + + cy.get('.app__nav a').contains('Website').click(); + cy.get('button[id="plugins-button"]').click(); + + // Find and enable the plugin + cy.get('input[id^="select-cell-immersionthemeplugin-enabled"]').click(); + cy.get('div:contains(\'The plugin "Immersion Theme" has been enabled.\')'); + cy.reload(); + + // Select the Classic theme + cy.get('button[id="appearance-button"]').click(); + cy.get('select[id="theme-themePluginPath-control"]').select('immersion'); + cy.get('#theme button').contains('Save').click(); + cy.get('#theme [role="status"]').contains('Saved'); + }); + + it('Visits front-end theme pages', function() { + cy.visit(' '); + cy.visit(path + '/issue/current'); + cy.visit(path + '/issue/archive'); + cy.visit(path + '/issue/view/1'); + cy.visit(path + '/article/view/1'); + cy.visit(path + '/article/view/1/1'); + cy.visit(path + '/about'); + cy.visit(path + '/about/editorialTeam'); + cy.visit(path + '/about/submissions'); + cy.visit(path + '/about/contact'); + cy.visit(path + '/about/privacy'); + cy.visit(path + '/information/readers'); + cy.visit(path + '/information/authors'); + cy.visit(path + '/information/librarians'); + cy.visit(path + '/search/authors'); + }); + + it('Checks theme options', function() { + cy.login('admin', 'admin', journalPath); + cy.visit(path + '/management/settings/website'); + cy.get('#appearance-button').click(); + cy.get('#theme-button').click(); + cy.get('input[name="sectionDescriptionSetting"][value="enable"]').check(); + cy.get('input[name="journalDescription"][value="1"]').check(); + cy.get('.pkpFormField--color').eq(0).get('input.vc-input__input').first().clear().type('#AAAAAA'); + cy.get('.pkpFormField--color').eq(1).get('input.vc-input__input').eq(7).clear().type('#AAAAAA'); + cy.get('#theme button').contains('Save').click(); + cy.get('#theme [role="status"]').contains('Saved'); + + // Populate journal summary + cy.get('.app__navItem').contains('Journal').click(); + cy.get('#masthead-button').click(); + cy.get('#masthead-description-control-en_US').type(journalDescription); + cy.get('#masthead button').contains('Save').click(); + cy.get('#masthead [role="status"]').contains('Saved'); + + // Check if applied, without bg color of announcements and sections + cy.get('header a').contains('Journal of Public Knowledge').click(); + cy.get('.journal-description').should('have.css', 'background-color', 'rgb(170, 170, 170)'); + cy.get('.journal-description p').first().contains(journalDescription); + }); + + it('Checks category pages & publication versioning', function() { + cy.login('admin', 'admin', journalPath); + cy.visit(path + '/management/settings/context#categories'); + cy.get('#categoriesContainer a').contains('Add Category').click(); + cy.wait(2000); + cy.get('input[name="name[en_US]"]').type('First category', {delay: 0}); + cy.get('input[name="path"]').type('first-category', {delay: 0}); + cy.get('textarea[name="description[en_US]"]').then(node => { + cy.setTinyMceContent(node.attr('id'), categoryDescription); + }); + cy.get('#categoryDetails [id^="submitFormButton"]').click(); + cy.visit(path + '/workflow/index/1/5#publication'); + cy.get('.pkpButton').contains('Create New Version').click(); + cy.get('#modals-container .pkpButton').contains('Yes').click(); + cy.wait(2000); // wait for a new version init + + cy.get('#issue-button').click(); + cy.get('.pkpFormField--options__optionLabel').contains('First category').click(); + cy.get('#issue button').contains('Save').click(); + cy.get('#issue [role="status"]').contains('Saved'); + + cy.get('#titleAbstract-button').click(); + cy.get('#titleAbstract-title-control-en_US').type(' - version 2'); + cy.get('#titleAbstract .pkpButton').contains('Save').click(); + cy.get('#titleAbstract [role="status"]').contains('Saved'); + cy.get('#publication .pkpButton').contains('Publish').click(); + cy.get('.pkp_modal .pkpButton').contains('Publish').click(); + cy.wait(2000); + + // Visit front-end pages + cy.visit(path + '/article/view/1'); + cy.get('.article-page__title').invoke('text').then((text) => { + expect(text).to.include('version 2'); + }); + cy.get('.article-page__versions').children().should('have.length', 2); + cy.visit(path + '/article/view/1/version/1'); + cy.get('.article-page__title').invoke('text').then((text) => { + expect(text).not.to.include('version 2'); + }); + cy.visit(path + '/article/view/1/version/1/1'); + cy.visit(path + '/catalog/category/first-category'); + cy.get('.category__meta').contains('1 Items'); + cy.get('.category__list').children().should('have.length', 1); + }); + + it('Search an article', function() { + cy.visit(path + '/' + 'search' + '/' + 'search'); + cy.get('input[id="query"]').type('Antimicrobial', {delay: 0}); + + // Search from the first day of the current month till now + cy.get('select[name="dateFromYear"]').select(year); + cy.get('select[name="dateFromMonth"]').select(month); + cy.get('select[name="dateFromDay"]').select('1'); + cy.get('select[name="dateToYear"]').select(year); + cy.get('select[name="dateToMonth"]').select(month); + cy.get('select[name="dateToDay"]').select(day); + + cy.get('input[name="authors"]').type('Vajiheh Karbasizaed', {delay: 0}); + cy.get('button[type="submit"]').contains('Search').click(); + cy.get('.search_results').children().should('have.length', 1); + cy.get('.article__title').first().click(); + cy.get('.article-page__title').contains( + 'Antimicrobial, heavy metal resistance and plasmid profile of coliforms isolated from nosocomial infections in a hospital in Isfahan, Iran' + ); + }); + + it('Register a user', function() { + // Sign out + cy.visit(path + '/' + 'login/signOut'); + cy.url().should('include', 'login'); + + // Register; 'cy.register()' command won't work for this theme because privacyConsent label overlays input checkbox + cy.get('a.main-header__admin-link').contains('Register').click(); + cy.url().should('include', '/user/register'); + cy.get('#givenName').type(user.givenName, {delay: 0}); + cy.get('#familyName').type(user.familyName, {delay: 0}); + cy.get('#affiliation').type(user.affiliation, {delay: 0}); + cy.get('#country').select(user.country); + cy.get('#username').type(user.username, {delay: 0}); + cy.get('#email').type(user.username + '@mailinator.com', {delay: 0}); + cy.get('#password').type(user.username + user.username, {delay: 0}); + cy.get('#password2').type(user.username + user.username, {delay: 0}); + cy.get('label[for="privacyConsent"]').click(); + cy.get('label[for="checkbox-reviewer-interests"]').click(); + cy.get('#tagitInput input').type('psychotherapy,neuroscience,neurobiology', {delay: 0}); + cy.get('button[type="submit"]').contains('Register').click().click(); // Cypress expects 2 clicks to submit the form + cy.get('.registration_complete_actions a').contains('View Submissions').click(); + cy.url().should('include', 'submissions'); + }); + + it('Log in/Log out', function() { + // Sign out + cy.visit(path + '/' + 'login/signOut'); + cy.url().should('include', 'login'); + cy.get('#username').type(user.username, {delay: 0}); + cy.get('#password').type(user.username + user.username); + cy.get('button[type="submit"]').contains('Login').click(); + cy.url().should('include', 'submissions'); + }); +});