Skip to content

Commit

Permalink
test: Add jest tests amd cypress
Browse files Browse the repository at this point in the history
  • Loading branch information
avoinea committed Sep 25, 2023
1 parent 5269c75 commit 28ea75a
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ pipeline {
node(label: 'docker') {
script {
try {
sh '''docker pull eeacms/plone-backend; docker run --rm -d --name="$BUILD_TAG-plone" -e SITE="Plone" -e PROFILES="eea.kitkat:testing" eeacms/plone-backend'''
sh '''docker pull eeacms/eea-website-backend; docker run --rm -d --name="$BUILD_TAG-plone" -e SITE="Plone" -e PROFILES="eea.progress.workflow:default" eeacms/eea-website-backend'''
sh '''docker pull plone/volto-addon-ci; docker run -i --name="$BUILD_TAG-cypress" --link $BUILD_TAG-plone:plone -e NAMESPACE="$NAMESPACE" -e GIT_NAME=$GIT_NAME -e GIT_BRANCH="$BRANCH_NAME" -e GIT_CHANGE_ID="$CHANGE_ID" -e DEPENDENCIES="$DEPENDENCIES" -e VOLTO=$VOLTO plone/volto-addon-ci cypress'''
} finally {
try {
Expand Down
7 changes: 7 additions & 0 deletions cypress/e2e/01-block-basics.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,15 @@ describe('Blocks Tests', () => {
cy.get('#toolbar-save').click();
cy.url().should('eq', Cypress.config().baseUrl + '/cypress/my-page');

cy.waitForResourceToLoad('@workflow.progress');

// then the page view should contain our changes
cy.contains('My Add-on Page');
cy.get('.block.image');

// Workflow progress is present
cy.get('#toolbar-workflow-progress button').click();
cy.get('.sidenav-ol').contains('Pending review');

});
});
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
version: "3"
services:
backend:
image: eeacms/plone-backend
image: eeacms/eea-website-backend
ports:
- "8080:8080"
environment:
SITE: "Plone"
PROFILES: "eea.kitkat:testing"
PROFILES: "eea.progress.workflow:default"

frontend:
build:
Expand Down
4 changes: 2 additions & 2 deletions src/ProgressWorkflow.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const ProgressWorkflow = (props) => {
const [workflowProgressSteps, setWorkflowProgressSteps] = useState([]);
const [currentState, setCurrentState] = useState(null);
const workflowProgress = useSelector((state) => {
if (state?.workflowProgress?.workflow?.loaded === true) {
if (state?.workflowProgress?.get?.loaded === true) {
const progress = state?.workflowProgress?.result;
if (
progress &&
Expand Down Expand Up @@ -141,7 +141,7 @@ const ProgressWorkflow = (props) => {
basePathname !== '/' && // wihout this there will be a flicker for going back to home ('/' is included in all api paths)
workflowProgress?.result?.steps &&
workflowProgress.result.steps.length > 0 &&
!workflowProgress.workflow?.error &&
!workflowProgress.get?.error &&
Array.isArray(workflowProgress?.result?.steps)
) {
findCurrentState(
Expand Down
7 changes: 6 additions & 1 deletion src/ProgressWorkflow.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const propsEmpty = {};
describe('ProgressWorkflow', () => {
it('renders the ProgressWorkflow component without breaking if props and workflow are empty', () => {
const store = mockStore({
token: 'secret',
intl: {
locale: 'en',
messages: {},
Expand All @@ -47,6 +48,7 @@ describe('ProgressWorkflow', () => {

it('renders the ProgressWorkflow component', () => {
const store = mockStore({
token: 'secret',
intl: {
locale: 'en',
messages: {},
Expand All @@ -55,6 +57,8 @@ describe('ProgressWorkflow', () => {
'@id': 'http://localhost:3000/api/my-page/@workflow.progress',
done: 50,
steps: [
[['archived'], 0, ['Archived'], ['Not visible to the public.']],
[['deleted'], 0, ['Deleted'], ['Not visible to the public.']],
[
['private'],
25,
Expand Down Expand Up @@ -108,13 +112,14 @@ describe('ProgressWorkflow', () => {

it('renders the ProgressWorkflow component with Percent showing correct value', () => {
const store = mockStore({
token: 'secret',
intl: {
locale: 'en',
messages: {},
},
workflowProgress: {
'@id': 'http://localhost:3000/api/my-page/@workflow.progress',
done: 50,
done: 100,
steps: [
[
['private'],
Expand Down
17 changes: 3 additions & 14 deletions src/reducers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,8 @@ const initialState = {
loading: false,
error: null,
},
subrequests: {},
};

/**
* Get request key
* @function getRequestKey
* @param {string} actionType Action type.
* @returns {string} Request key.
*/
function getRequestKey(actionType) {
return actionType.split('_')[0].toLowerCase();
}

/**
* Data figure reducer.
* @function workflowProgress
Expand All @@ -37,7 +26,7 @@ export function workflowProgress(state = initialState, action = {}) {
case `${WORKFLOW_PROGRESS}_PENDING`:
return {
...state,
[getRequestKey(action.type)]: {
get: {
loading: true,
loaded: false,
error: null,
Expand All @@ -46,7 +35,7 @@ export function workflowProgress(state = initialState, action = {}) {
case `${WORKFLOW_PROGRESS}_SUCCESS`:
return {
...state,
[getRequestKey(action.type)]: {
get: {
loading: false,
loaded: true,
error: null,
Expand All @@ -56,7 +45,7 @@ export function workflowProgress(state = initialState, action = {}) {
case `${WORKFLOW_PROGRESS}_FAIL`:
return {
...state,
[getRequestKey(action.type)]: {
get: {
loading: false,
loaded: false,
error: action.error,
Expand Down
60 changes: 60 additions & 0 deletions src/reducers/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { workflowProgress } from './index';

describe('workflowProgress reducer', () => {
const initialState = {
get: {
loaded: false,
loading: false,
error: null,
},
};

it('handles WORKFLOW_PROGRESS_PENDING action', () => {
const action = { type: 'WORKFLOW_PROGRESS_PENDING' };
const newState = workflowProgress(initialState, action);
expect(newState).toMatchObject({
get: {
loading: true,
loaded: false,
error: null,
},
});
});

it('handles WORKFLOW_PROGRESS_SUCCESS action', () => {
const action = {
type: 'WORKFLOW_PROGRESS_SUCCESS',
result: { someData: 'data' },
};
const newState = workflowProgress(initialState, action);
expect(newState).toMatchObject({
get: {
loading: false,
loaded: true,
error: null,
},
result: { someData: 'data' },
});
});

it('handles WORKFLOW_PROGRESS_FAIL action', () => {
const action = {
type: 'WORKFLOW_PROGRESS_FAIL',
error: 'Some error message',
};
const newState = workflowProgress(initialState, action);
expect(newState).toMatchObject({
get: {
loading: false,
loaded: false,
error: 'Some error message',
},
});
});

it('returns the initial state when given an unknown action', () => {
const action = { type: 'UNKNOWN_ACTION' };
const newState = workflowProgress(initialState, action);
expect(newState).toMatchObject(initialState);
});
});

0 comments on commit 28ea75a

Please sign in to comment.