Skip to content

Commit

Permalink
Refactor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cgsunkel committed Feb 26, 2024
1 parent c3f7ee5 commit 82d44e9
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 50 deletions.
16 changes: 10 additions & 6 deletions test/end-to-end/cypress/specs/DIT/audit-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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')
})
})
88 changes: 45 additions & 43 deletions test/functional/cypress/specs/investments/edit-history-spec.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
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', () => {
beforeEach(() => {
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', () => {
Expand All @@ -40,66 +42,66 @@ 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 [email protected]'
)
})
})

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'
)
})
Expand Down
3 changes: 2 additions & 1 deletion test/sandbox/fixtures/v3/investment/project-audit.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 82d44e9

Please sign in to comment.