diff --git a/Jenkinsfile b/Jenkinsfile index 39051ba..9e0ebd8 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -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 { diff --git a/cypress/e2e/01-block-basics.cy.js b/cypress/e2e/01-block-basics.cy.js index 089c7b3..9a649e0 100644 --- a/cypress/e2e/01-block-basics.cy.js +++ b/cypress/e2e/01-block-basics.cy.js @@ -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'); + }); }); diff --git a/docker-compose.yml b/docker-compose.yml index 5d79f5c..49df180 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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: diff --git a/src/ProgressWorkflow.jsx b/src/ProgressWorkflow.jsx index 1ad7f36..e298d85 100644 --- a/src/ProgressWorkflow.jsx +++ b/src/ProgressWorkflow.jsx @@ -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 && @@ -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( diff --git a/src/ProgressWorkflow.test.jsx b/src/ProgressWorkflow.test.jsx index 731f378..041ca97 100644 --- a/src/ProgressWorkflow.test.jsx +++ b/src/ProgressWorkflow.test.jsx @@ -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: {}, @@ -47,6 +48,7 @@ describe('ProgressWorkflow', () => { it('renders the ProgressWorkflow component', () => { const store = mockStore({ + token: 'secret', intl: { locale: 'en', messages: {}, @@ -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, @@ -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'], diff --git a/src/reducers/index.js b/src/reducers/index.js index 08264c6..b0f4f8d 100644 --- a/src/reducers/index.js +++ b/src/reducers/index.js @@ -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 @@ -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, @@ -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, @@ -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, diff --git a/src/reducers/index.test.js b/src/reducers/index.test.js new file mode 100644 index 0000000..5f72ca4 --- /dev/null +++ b/src/reducers/index.test.js @@ -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); + }); +});