-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
57 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', () => { | ||
|
@@ -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' | ||
) | ||
}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters