Skip to content

Commit

Permalink
Merge pull request #17 from eea/cypress-ci
Browse files Browse the repository at this point in the history
Add integration tests
  • Loading branch information
razvanMiu authored Jul 5, 2021
2 parents 7f3aa93 + bd44c88 commit 6ee8c27
Show file tree
Hide file tree
Showing 8 changed files with 974 additions and 37 deletions.
60 changes: 35 additions & 25 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,42 @@ pipeline {
}

stages {

stage('Integration tests') {
steps {
node(label: 'docker') {
script {
try {
sh '''docker pull plone; docker run -d --name="$BUILD_TAG-plone" -e SITE="Plone" -e PROFILES="profile-plone.restapi:blocks" plone fg'''
sh '''docker pull eeacms/volto-project-ci; docker run -i --name="$BUILD_TAG-cypress" --link $BUILD_TAG-plone:plone -e GIT_NAME=$GIT_NAME -e GIT_BRANCH="$BRANCH_NAME" -e GIT_CHANGE_ID="$CHANGE_ID" eeacms/volto-project-ci cypress'''
} finally {
try {
sh '''rm -rf cypress-reports cypress-results'''
sh '''mkdir -p cypress-reports cypress-results'''
sh '''docker cp $BUILD_TAG-cypress:/opt/frontend/my-volto-project/cypress/videos cypress-reports/'''
sh '''docker cp $BUILD_TAG-cypress:/opt/frontend/my-volto-project/cypress/reports cypress-results/'''
archiveArtifacts artifacts: 'cypress-reports/videos/*.mp4', fingerprint: true
}
finally {
catchError(buildResult: 'SUCCESS', stageResult: 'SUCCESS') {
junit testResults: 'cypress-results/**/*.xml', allowEmptyResults: true
}
sh script: "docker stop $BUILD_TAG-plone", returnStatus: true
sh script: "docker rm -v $BUILD_TAG-plone", returnStatus: true
sh script: "docker rm -v $BUILD_TAG-cypress", returnStatus: true
}
}
}
}
}
}

stage('Build & Push') {
when {
allOf {
environment name: 'CHANGE_ID', value: ''
}
}
steps{
node(label: 'docker-host') {
script {
Expand Down Expand Up @@ -49,31 +84,6 @@ pipeline {
}
}

// stage('Integration tests') {
// steps {
// parallel(

// "Cypress": {
// node(label: 'docker') {
// script {
// try {
// sh '''docker pull eeacms/plonesaas; docker run -d --name="$BUILD_TAG-plone" -e SITE="Plone" -e PROFILES="profile-plone.restapi:blocks" plone fg'''
// sh '''docker pull eeacms/eprtr-frontend; docker run -i --name="$BUILD_TAG-cypress" --link $BUILD_TAG-plone:plone -e NAMESPACE="$NAMESPACE" -e TIMEOUT=600000 -e GIT_NAME=$GIT_NAME -e GIT_BRANCH="$BRANCH_NAME" -e GIT_CHANGE_ID="$CHANGE_ID" eeacms/eprtr-frontend cypress'''
// } finally {
// sh '''mkdir -p cypress-reports'''
// sh '''docker cp $BUILD_TAG-cypress:/opt/frontend/cypress/videos cypress-reports/'''
// stash name: "cypress-reports", includes: "cypress-reports/**/*"
// archiveArtifacts artifacts: 'cypress-reports/videos/*.mp4', fingerprint: true
// sh '''echo "$(docker stop $BUILD_TAG-plone; docker rm -v $BUILD_TAG-plone; docker rm -v $BUILD_TAG-cypress)" '''
// }
// }
// }
// }

// )
// }
// }

stage('Upgrade demo') {
when {
buildingTag()
Expand Down
12 changes: 10 additions & 2 deletions cypress.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
{
"baseUrl": "http://localhost:3000",
"viewportWidth": 1280
}
"viewportWidth": 1280,
"defaultCommandTimeout": 15000,
"reporter": "junit",
"video": true,
"reporterOptions": {
"mochaFile": "cypress/reports/cypress-[hash].xml",
"jenkinsMode": true,
"toConsole": true
}
}
22 changes: 22 additions & 0 deletions cypress/helpers/actions/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export const save = (path) => {
cy.url().then(($url) => {
if ($url.includes(path)) {
//cy.get('.ui.button.save').click();
cy.get('#toolbar-save').click();
cy.url().should('eq', Cypress.config().baseUrl + path);
} else {
cy.log('Wrong path');
}
});
};

export const cancel = (path) => {
cy.url().then(($url) => {
if ($url.includes(path)) {
cy.get('.ui.button.cancel').click();
cy.url().should('eq', Cypress.config().baseUrl + path);
} else {
cy.log('Wrong path');
}
});
};
38 changes: 32 additions & 6 deletions cypress/helpers/blocks/index.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,46 @@
import { openSidebar, closeSidebar } from '../index';

export const changePageTitle = (title) => {
export const changePageTitle = (title, delay = 10) => {
cy.get('.documentFirstHeading > .public-DraftStyleDefault-block')
.clear()
.type(title)
.get('.documentFirstHeading span[data-text]')
.contains(title);

cy.get('.documentFirstHeading > .public-DraftStyleDefault-block').type(
'{enter}',
);
};

export const addBlock = (groupTitle, groupId, blockId) => {
closeSidebar();
cy.get('.ui.basic.icon.button.block-add-button').first().click();
cy.get('.blocks-chooser .title').contains(groupTitle).click();
cy.get(`.content.active.${groupId} .button.${blockId}`).click();
cy.get(`#page-edit div.block-editor-${blockId}`);
openSidebar();
cy.getIfExists(
'#page-edit div.block-editor-slate',
() => {
cy.get('#page-edit div.block-editor-slate').last().click();
},
() => {
cy.getIfExists('#page-edit div.block-editor-text', () => {
cy.get('#page-edit div.block-editor-text').last().click();
});
},
);
cy.get('.ui.basic.icon.button.block-add-button').last().click();
cy.getIfExists(
`.content.active.${groupId}`,
() => {
cy.get(`.content.active.${groupId} .button.${blockId}`).click();
cy.get(`#page-edit div.block-editor-${blockId}`).type('{enter}');
openSidebar();
},
() => {
cy.get('.blocks-chooser .title').contains(groupTitle).click();
cy.get(`.content.active.${groupId} .button.${blockId}`).click();
cy.get(`#page-edit div.block-editor-${blockId}`);
cy.get(`#page-edit div.block-editor-${blockId}`).type('{enter}');
openSidebar();
},
);
};

export const selectBlock = (blockId) => {
Expand Down
7 changes: 4 additions & 3 deletions cypress/helpers/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { openSidebar, closeSidebar, openSidebarTab } from './sidebar';
export { changePageTitle, addBlock, selectBlock } from './blocks';
export { setInputValue, filtersModal } from './utils';
export * from './actions';
export * from './blocks';
export * from './sidebar';
export * from './utils';
4 changes: 3 additions & 1 deletion cypress/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ export const filtersModal = {
search: (text) => {
cy.get('.filters-container .search-input-container input').type(text);
cy.wait(2000);
cy.get('.filters-container .search-input-container input').type('{enter}');
cy.get('.filters-container .search-input-container span.suggestion-term')
.contains(text)
.click();
},
};
16 changes: 16 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,20 @@ function setBaseAndExtent(...args) {
document.getSelection().setBaseAndExtent(...args);
}

function getIfExists(
selector,
successAction = () => {},
failAction = () => {},
) {
cy.get('body').then((body) => {
if (body.find(selector).length > 0 && successAction) {
successAction();
} else if (failAction) {
failAction();
}
});
}

Cypress.Commands.add('navigate', (route = '') => {
return cy.window().its('appHistory').invoke('push', route);
});
Expand All @@ -314,6 +328,8 @@ Cypress.Commands.add('settings', (key, value) => {
return cy.window().its('settings');
});

Cypress.Commands.add('getIfExists', getIfExists);

Cypress.Commands.add(
'controlledTextAreaChange',
{ prevSubject: 'element' },
Expand Down
Loading

0 comments on commit 6ee8c27

Please sign in to comment.