diff --git a/test/end-to-end/cypress/specs/DIT/audit-spec.js b/test/end-to-end/cypress/specs/DIT/audit-spec.js index 8f747944239..f28d887186e 100644 --- a/test/end-to-end/cypress/specs/DIT/audit-spec.js +++ b/test/end-to-end/cypress/specs/DIT/audit-spec.js @@ -11,6 +11,7 @@ const { } = require('../../../../../src/client/components/AuditHistory/constants') const { assertBadge, + assertBadgeNotPresent, } = require('../../../../functional/cypress/support/collection-list-assertions') const todaysDate = formatWithoutParsing(new Date(), DATE_MEDIUM_FORMAT) @@ -102,15 +103,18 @@ describe('Investment Project', () => { assertFlashMessage('Investment details updated') cy.visit(urls.investments.editHistory.index(investmentProjectObj.pk)) + cy.get('[data-test="collection-item"]').as('collectionItems') + cy.get('@collectionItems').eq(0).as('listItem1') - cy.get(selectors.editHistory.change(1).updated) + cy.get('@listItem1') .should('contain', todaysDate) .and('contain', 'DIT Staff') + .and('contain', 'No changes were made to the project in this update') - cy.get(selectors.editHistory.change(1).noChanges).should( - 'have.text', - 'No changes were made to the project in this update' - ) - cy.get('h3').should('contain', '1 change') + cy.get('[data-test="collection-header-name"]') + .should('exist') + .should('contain', '1 project change') + + assertBadgeNotPresent('@listItem1') }) }) diff --git a/test/functional/cypress/specs/investments/edit-history-spec.js b/test/functional/cypress/specs/investments/edit-history-spec.js index 34a84b89d71..7cb50872c89 100644 --- a/test/functional/cypress/specs/investments/edit-history-spec.js +++ b/test/functional/cypress/specs/investments/edit-history-spec.js @@ -1,20 +1,17 @@ -const { - assertLocalHeader, - assertBreadcrumbs, -} = require('../../support/assertions') -const fixtures = require('../../fixtures') -const { editHistory } = require('../../../../selectors') -const urls = require('../../../../../src/lib/urls') +import { assertLocalHeader, assertBreadcrumbs } from '../../support/assertions' +import { + assertBadge, + assertBadgeNotPresent, +} from '../../support/collection-list-assertions' +import fixtures from '../../fixtures' +import urls from '../../../../../src/lib/urls' +import { NOT_SET } from '../../../../../src/client/modules/Investments/Projects/EditHistory/constants' -const assertChanges = (table, caption, beforeChange, afterChange) => { - cy.get(table.caption).should('have.text', caption) - cy.get(table.beforeChangeText).should( - 'have.text', - 'Information before change' - ) - cy.get(table.beforeChangeValue).should('have.text', beforeChange) - cy.get(table.afterChangeText).should('have.text', 'Information after change') - cy.get(table.afterChangeValue).should('have.text', afterChange) +const assertChanges = (itemNo, field, oldVal, newVal) => { + cy.get(`@listItem${itemNo}`) + .should('contain', field) + .and('contain', oldVal) + .and('contain', newVal) } describe('Edit History', () => { @@ -22,6 +19,11 @@ describe('Edit History', () => { cy.visit( urls.investments.editHistory.index(fixtures.investment.newHotelFdi.id) ) + cy.get('[data-test="collection-item"]').as('collectionItems') + cy.get('@collectionItems').eq(0).as('listItem1') + cy.get('@collectionItems').eq(1).as('listItem2') + cy.get('@collectionItems').eq(2).as('listItem3') + cy.get('@collectionItems').eq(3).as('listItem4') }) context('when viewing the "Edit History" page', () => { @@ -40,57 +42,57 @@ describe('Edit History', () => { 'Edit history': null, }) }) + + it('should render the collection header', () => { + cy.get('[data-test="collection-header-name"]') + .should('exist') + .should('contain', '4 project changes') + }) + + it('should render the correct badges', () => { + assertBadge('@listItem1', '8 changes') + assertBadgeNotPresent('@listItem3') + }) }) context('when viewing a change', () => { it('should display the date when the update occurred and by whom', () => { - cy.get(editHistory.change(1).updated).should( - 'have.text', + cy.get('@listItem1').should( + 'contain', 'Updated on 29 Apr 2020, 4:14pm by Eloisa Ward' ) }) it('should display the changes for a boolean change', () => { - assertChanges( - editHistory.change(1).table(2), - 'Site decided', - 'False', - 'True' - ) + assertChanges(1, 'Site decided', 'No', 'Yes') }) it('should display the changes for a text change', () => { - assertChanges( - editHistory.change(1).table(3), - 'Address 1', - '10 Main Road', - '20 Main Road' - ) + assertChanges(1, 'Address line 1', '10 Main Road', '20 Main Road') }) it('should display the changes for a previously empty field', () => { - assertChanges( - editHistory.change(1).table(4), - 'Address 2', - 'Not set', - 'Redford' - ) + assertChanges(1, 'Address line 2', 'Not set', 'Redford') }) it('should display the changes for a field allowing many options', () => { assertChanges( - editHistory.change(1).table(5), + 1, 'Delivery partners', - 'New Anglia LEP' + 'North Eastern LEP', - 'North Eastern LEP' + 'Northern Ireland (disabled)' + 'New Anglia LEP, North Eastern LEP', + 'North Eastern LEP, Northern Ireland (disabled)' ) }) + + it('should display the changes for a currency field', () => { + assertChanges(4, 'Total investment', NOT_SET, '£123,456,789') + }) }) context('when viewing a change made by a user with no recorded name', () => { it('should display an email instead of user name', () => { - cy.get(editHistory.change(2).updated).should( - 'have.text', + cy.get('@listItem2').should( + 'contain', 'Updated on 29 Apr 2020, 4:13pm by Stanford.Mayert@gmail.coz' ) }) @@ -98,8 +100,8 @@ describe('Edit History', () => { context('when viewing a change log where no changes were recorded', () => { it('should display expected text', () => { - cy.get(editHistory.change(3).noChanges).should( - 'have.text', + cy.get('@listItem3').should( + 'contain', 'No changes were made to the project in this update' ) }) diff --git a/test/sandbox/fixtures/v3/investment/project-audit.json b/test/sandbox/fixtures/v3/investment/project-audit.json index ef75047f1f1..ff44b722825 100644 --- a/test/sandbox/fixtures/v3/investment/project-audit.json +++ b/test/sandbox/fixtures/v3/investment/project-audit.json @@ -71,7 +71,8 @@ "average_salary": [ "Below £25,000", "£35,000 and above" ], "number_safeguarded_jobs": [ 1, 123123 ], "r_and_d_budget": [ false, true ], - "non_fdi_r_and_d_budget": [ true, false ] + "non_fdi_r_and_d_budget": [ true, false ], + "total_investment": [ null, 123456789] }, "note": null }