From dc43b889165ba34cf598731c2785fe7926ebc134 Mon Sep 17 00:00:00 2001 From: Ramon Wenger Date: Thu, 5 Aug 2021 11:41:57 +0200 Subject: [PATCH] Add cypress test for read only portfolio --- .../frontend/read-only/portfolio.spec.js | 44 +++++++++++++++++ .../frontend/read-only/project.spec.js | 48 +++++++++++++++++++ .../integration/frontend/snapshots.spec.js | 1 - client/cypress/support/helpers.js | 1 + .../components/portfolio/ProjectActions.vue | 4 +- .../src/components/portfolio/ProjectEntry.vue | 13 ++--- .../components/portfolio/ProjectWidget.vue | 9 ++-- .../graphql/gql/fragments/projectParts.gql | 2 +- .../src/graphql/gql/queries/projectQuery.gql | 2 +- client/src/pages/portfolio/portfolio.vue | 6 ++- client/src/pages/portfolio/project.vue | 11 +++-- server/core/management/commands/dummy_data.py | 16 +++---- 12 files changed, 130 insertions(+), 27 deletions(-) create mode 100644 client/cypress/integration/frontend/read-only/portfolio.spec.js create mode 100644 client/cypress/integration/frontend/read-only/project.spec.js diff --git a/client/cypress/integration/frontend/read-only/portfolio.spec.js b/client/cypress/integration/frontend/read-only/portfolio.spec.js new file mode 100644 index 00000000..8eb73b66 --- /dev/null +++ b/client/cypress/integration/frontend/read-only/portfolio.spec.js @@ -0,0 +1,44 @@ +import {getMinimalMe} from '../../../support/helpers'; + +const getOperations = ({readOnly = false}) => ({ + MeQuery: getMinimalMe({readOnly}), + ProjectsQuery: { + projects: { + edges: [ + { + node: { + id: 'projectId', + final: false, + student: { + id: 'meId', + }, + entriesCount: 3, + }, + }, + ], + }, + }, +}); + +describe('Read Only Portfolio', () => { + beforeEach(() => { + cy.setup(); + }); + + it('Can create and edit project', () => { + cy.mockGraphqlOps({operations: getOperations({readOnly: false})}); + + cy.visit('/portfolio'); + cy.getByDataCy('add-project-button').should('exist'); + cy.getByDataCy('project-widget').should('have.length', 1); + cy.getByDataCy('project-widget-actions').should('exist'); + }); + it('Can not create and edit project', () => { + cy.mockGraphqlOps({operations: getOperations({readOnly: true})}); + + cy.visit('/portfolio'); + cy.getByDataCy('add-project-button').should('not.exist'); + cy.getByDataCy('project-widget').should('have.length', 1); + cy.getByDataCy('project-widget-actions').should('not.exist'); + }); +}); diff --git a/client/cypress/integration/frontend/read-only/project.spec.js b/client/cypress/integration/frontend/read-only/project.spec.js new file mode 100644 index 00000000..b27e1d64 --- /dev/null +++ b/client/cypress/integration/frontend/read-only/project.spec.js @@ -0,0 +1,48 @@ +import {getMinimalMe} from '../../../support/helpers'; + +const getOperations = ({readOnly = false}) => ({ + MeQuery: getMinimalMe({readOnly}), + ProjectQuery: { + project: { + id: 'projectId', + final: false, + student: { + id: 'meId', + }, + entriesCount: 3, + entries: { + edges: [ + { + node: {}, + }, + ], + }, + }, + }, +}); + +const testProject = (readOnly, shouldActionsExist) => { + cy.mockGraphqlOps({operations: getOperations({readOnly})}); + + const exist = shouldActionsExist ? 'exist' : 'not.exist'; + + cy.visit('/portfolio/project-name'); + cy.getByDataCy('project-title').should('exist'); + cy.getByDataCy('project-entry').should('have.length', 1); + cy.getByDataCy('add-project-entry').should(exist); + cy.getByDataCy('project-actions').should(exist); + cy.getByDataCy('project-entry-more').should(exist); +}; + +describe('Read Only Project', () => { + beforeEach(() => { + cy.setup(); + }); + + it('Can create and edit project entry', () => { + testProject(false, true); + }); + it('Can not create and edit project entry', () => { + testProject(true, false); + }); +}); diff --git a/client/cypress/integration/frontend/snapshots.spec.js b/client/cypress/integration/frontend/snapshots.spec.js index d820584d..3877580d 100644 --- a/client/cypress/integration/frontend/snapshots.spec.js +++ b/client/cypress/integration/frontend/snapshots.spec.js @@ -1,4 +1,3 @@ -import getMe from '../../fixtures/me.minimal'; import module from '../../fixtures/module.minimal'; import mocks from '../../fixtures/mocks'; import {getMinimalMe} from '../../support/helpers'; diff --git a/client/cypress/support/helpers.js b/client/cypress/support/helpers.js index 27532c28..908b7e77 100644 --- a/client/cypress/support/helpers.js +++ b/client/cypress/support/helpers.js @@ -2,6 +2,7 @@ export const getMinimalMe = ({readOnly = false, classReadOnly = false, isTeacher = true}) => ({ me: { + id: 'meId', onboardingVisited: true, readOnly, isTeacher, diff --git a/client/src/components/portfolio/ProjectActions.vue b/client/src/components/portfolio/ProjectActions.vue index 601ebefa..ebe17199 100644 --- a/client/src/components/portfolio/ProjectActions.vue +++ b/client/src/components/portfolio/ProjectActions.vue @@ -1,5 +1,7 @@