Skip to content

Commit

Permalink
Update billing tests
Browse files Browse the repository at this point in the history
Use new data-test attributes wherever possible. Also, realised we kept including asserts inside getters to local variables, for example

```javascript
  cy.get('@formattedCurrentDate').then((formattedCurrentDate) => {
    cy.get('tr:nth-child(1)')
      .should('contain.text', formattedCurrentDate)
      .and('contain.text', 'Test Region')
      .and('contain.text', 'Annual')
  })
```

We only needed to assert the date value inside the `cy.get('@formattedCurrentDate')` call. But it makes it look like you have to do them all for the test to work for the uninitiated. So, where we have spotted stuff like this we have also fixed it up.
  • Loading branch information
Cruikshanks committed Apr 30, 2024
1 parent 085095f commit b555e63
Show file tree
Hide file tree
Showing 13 changed files with 201 additions and 264 deletions.
15 changes: 7 additions & 8 deletions cypress/e2e/internal/billing/annual/cancel-existing.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('Cancel an existing annual bill run (internal)', () => {

// Bill runs
// click the Create a bill run button
cy.get('#main-content > a.govuk-button').contains('Create a bill run').click()
cy.get('.govuk-button').contains('Create a bill run').click()

// Which kind of bill run do you want to create?
// choose Annual and continue
Expand All @@ -52,14 +52,13 @@ describe('Cancel an existing annual bill run (internal)', () => {
// The bill run we created will be the top result. We expect it's status to be BUILDING. Building might take a few
// seconds though so to avoid the test failing we use our custom Cypress command to look for the status EMPTY, and
// if not found reload the page and try again. We then select it using the link on the date created
cy.reloadUntilTextFound('tr:nth-child(1) > td:nth-child(6) > .govuk-tag', 'Empty')
cy.reloadUntilTextFound('[data-test="bill-run-status-0"] > .govuk-tag', 'empty')
cy.get('@formattedCurrentDate').then((formattedCurrentDate) => {
cy.get('tr:nth-child(1)')
.should('contain.text', formattedCurrentDate)
.and('contain.text', 'Test Region')
.and('contain.text', 'Annual')
cy.get('[data-test="date-created-0"]').should('contain.text', formattedCurrentDate)
})
cy.get('tr:nth-child(1) > td:nth-child(1) > a').click()
cy.get('[data-test="region-0"]').should('contain.text', 'Test Region')
cy.get('[data-test="bill-run-type-0"]').should('contain.text', 'Annual')
cy.get('[data-test="date-created-0"] > .govuk-link').click()

// Test Region annual bill run
// quick test that the display is as expected and then click Cancel bill run
Expand All @@ -84,6 +83,6 @@ describe('Cancel an existing annual bill run (internal)', () => {

// Bill runs
// confirm we are back on the bill runs page
cy.get('h1.govuk-heading-l').should('contain.text', 'Bill runs')
cy.get('.govuk-heading-xl').should('contain.text', 'Bill runs')
})
})
24 changes: 11 additions & 13 deletions cypress/e2e/internal/billing/annual/journey.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('Create and send annual bill run (internal)', () => {

// Bill runs
// click the Create a bill run button
cy.get('#main-content > a.govuk-button').contains('Create a bill run').click()
cy.get('.govuk-button').contains('Create a bill run').click()

// Which kind of bill run do you want to create?
// choose Annual and continue
Expand All @@ -49,14 +49,13 @@ describe('Create and send annual bill run (internal)', () => {
// The bill run we created will be the top result. We expect it's status to be BUILDING. Building might take a few
// seconds though so to avoid the test failing we use our custom Cypress command to look for the status READY, and
// if not found reload the page and try again. We then select it using the link on the date created
cy.reloadUntilTextFound('tr:nth-child(1) > td:nth-child(6) > .govuk-tag', 'Ready')
cy.reloadUntilTextFound('[data-test="bill-run-status-0"] > .govuk-tag', 'ready')
cy.get('@formattedCurrentDate').then((formattedCurrentDate) => {
cy.get('tr:nth-child(1)')
.should('contain.text', formattedCurrentDate)
.and('contain.text', 'Test Region')
.and('contain.text', 'Annual')
cy.get('[data-test="date-created-0"]').should('contain.text', formattedCurrentDate)
})
cy.get('tr:nth-child(1) > td:nth-child(1) > a').click()
cy.get('[data-test="region-0"]').should('contain.text', 'Test Region')
cy.get('[data-test="bill-run-type-0"]').should('contain.text', 'Annual')
cy.get('[data-test="date-created-0"] > .govuk-link').click()

// Test Region annual bill run
// quick test that the display is as expected and then click Send bill run
Expand Down Expand Up @@ -96,12 +95,11 @@ describe('Create and send annual bill run (internal)', () => {
// Bill runs
// back on the bill runs page confirm our bill run is present and listed as SENT
cy.get('@formattedCurrentDate').then((formattedCurrentDate) => {
cy.get('#main-content > div:nth-child(5) > div > table > tbody > tr:nth-child(1)')
.should('contain.text', formattedCurrentDate)
.and('contain.text', 'Test Region')
.and('contain.text', 'Annual')
.and('contain.text', '2,171.00')
.and('contain.text', 'Sent')
cy.get('[data-test="date-created-0"] > .govuk-link').should('contain.text', formattedCurrentDate)
})
cy.get('[data-test="region-0"]').should('contain.text', 'Test Region')
cy.get('[data-test="bill-run-type-0"]').should('contain.text', 'Annual')
cy.get('[data-test="number-of-bills-0"]').should('contain.text', '4')
cy.get('[data-test="bill-run-status-0"] > .govuk-tag').should('contain.text', 'sent')
})
})
13 changes: 6 additions & 7 deletions cypress/e2e/internal/billing/annual/remove-licence.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('Remove bill from annual bill run (internal)', () => {

// Bill runs
// click the Create a bill run button
cy.get('#main-content > a.govuk-button').contains('Create a bill run').click()
cy.get('.govuk-button').contains('Create a bill run').click()

// Which kind of bill run do you want to create?
// choose Annual and continue
Expand All @@ -49,14 +49,13 @@ describe('Remove bill from annual bill run (internal)', () => {
// The bill run we created will be the top result. We expect it's status to be BUILDING. Building might take a few
// seconds though so to avoid the test failing we use our custom Cypress command to look for the status READY, and
// if not found reload the page and try again. We then select it using the link on the date created
cy.reloadUntilTextFound('tr:nth-child(1) > td:nth-child(6) > .govuk-tag', 'Ready')
cy.reloadUntilTextFound('[data-test="bill-run-status-0"] > .govuk-tag', 'ready')
cy.get('@formattedCurrentDate').then((formattedCurrentDate) => {
cy.get('tr:nth-child(1)')
.should('contain.text', formattedCurrentDate)
.and('contain.text', 'Test Region')
.and('contain.text', 'Annual')
cy.get('[data-test="date-created-0"]').should('contain.text', formattedCurrentDate)
})
cy.get('tr:nth-child(1) > td:nth-child(1) > a').click()
cy.get('[data-test="region-0"]').should('contain.text', 'Test Region')
cy.get('[data-test="bill-run-type-0"]').should('contain.text', 'Annual')
cy.get('[data-test="date-created-0"] > .govuk-link').click()

// Test Region annual bill run
// quick test that the display is as expected and then click view bill link
Expand Down
35 changes: 15 additions & 20 deletions cypress/e2e/internal/billing/supplementary/cancel-existing.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('Cancel existing supplementary bill runs (internal)', () => {

// Bill runs
// click the Create a bill run button
cy.get('#main-content > a.govuk-button').contains('Create a bill run').click()
cy.get('.govuk-button').contains('Create a bill run').click()

// Which kind of bill run do you want to create?
// choose Supplementary and continue
Expand All @@ -55,15 +55,13 @@ describe('Cancel existing supplementary bill runs (internal)', () => {
// The bill run we created will be the top result. We expect it's status to be BUILDING. Building might take a few
// seconds though so to avoid the test failing we use our custom Cypress command to look for the status READY, and
// if not found reload the page and try again. We then select it using the link on the date created
cy.reloadUntilTextFound('tr:nth-child(1) > td:nth-child(6) > .govuk-tag', 'Ready')
cy.reloadUntilTextFound('[data-test="bill-run-status-0"] > .govuk-tag', 'ready')
cy.get('@formattedCurrentDate').then((formattedCurrentDate) => {
cy.get('tr:nth-child(1)')
.should('contain.text', formattedCurrentDate)
.and('contain.text', 'Old charge scheme')
.and('contain.text', 'Test Region')
.and('contain.text', 'Supplementary')
cy.get('[data-test="date-created-0"]').should('contain.text', formattedCurrentDate).and('contain.text', 'Old charge scheme')
})
cy.get('tr:nth-child(1) > td:nth-child(1) > a').click()
cy.get('[data-test="region-0"]').should('contain.text', 'Test Region')
cy.get('[data-test="bill-run-type-0"]').should('contain.text', 'Supplementary')
cy.get('[data-test="date-created-0"] > .govuk-link').click()

// Test Region supplementary bill run
// quick test that the display is as expected and then click Cancel bill run
Expand All @@ -87,21 +85,18 @@ describe('Cancel existing supplementary bill runs (internal)', () => {

// Bill runs
// confirm we are back on the bill runs page
cy.get('h1.govuk-heading-l').should('contain.text', 'Bill runs')
cy.get('.govuk-heading-xl').should('contain.text', 'Bill runs')

// -------------------------------------------------------------------------
cy.log('Deleting the SROC supplementary bill run')

// select the SROC bill run
// On fast machines you might not see the cancelling entry in the bill runs screen. So, we have a conditional
// to determine which row to click. If 'Cancelling' is seen click the next row down, else click the current row.
cy.get(':nth-child(1) > :nth-child(6) > .govuk-tag').then((topRowStatus) => {
if (topRowStatus.text().includes('Cancelling')) {
cy.get('tr:nth-child(2) > td:nth-child(1) > a').click()
} else {
cy.get('tr:nth-child(1) > td:nth-child(1) > a').click()
}
})
// Bill runs
//
// The bill run we created will be the top result. We expect it's status to be CANCELLING. Cancelling might take a
// few seconds though so to avoid the test failing we use our custom Cypress command to look for the status READY,
// and if not found reload the page and try again. We then select it using the link on the date created
cy.reloadUntilTextFound('[data-test="bill-run-status-0"] > .govuk-tag', 'ready')
cy.get('[data-test="date-created-0"] > .govuk-link').click()

// Test Region supplementary bill run
// quick test that the display is as expected and then click Cancel bill run
Expand All @@ -125,6 +120,6 @@ describe('Cancel existing supplementary bill runs (internal)', () => {

// Bill runs
// confirm we are back on the bill runs page
cy.get('h1.govuk-heading-l').should('contain.text', 'Bill runs')
cy.get('.govuk-heading-xl').should('contain.text', 'Bill runs')
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('Change billing account in current financial year (internal)', () => {

// Bill runs
// click the Create a bill run button
cy.get('#main-content > a.govuk-button').contains('Create a bill run').click()
cy.get('.govuk-button').contains('Create a bill run').click()

// Which kind of bill run do you want to create?
// choose Supplementary and continue
Expand All @@ -59,14 +59,13 @@ describe('Change billing account in current financial year (internal)', () => {
// The bill run we created will be the second from top result. We expect it's status to be BUILDING. Building might
// take a few seconds though so to avoid the test failing we use our custom Cypress command to look for the status
// READY, and if not found reload the page and try again. We then select it using the link on the date created
cy.reloadUntilTextFound('tr:nth-child(2) > td:nth-child(6) > .govuk-tag', 'Ready')
cy.reloadUntilTextFound('[data-test="bill-run-status-1"] > .govuk-tag', 'ready')
cy.get('@formattedCurrentDate').then((formattedCurrentDate) => {
cy.get('tr:nth-child(1)')
.should('contain.text', formattedCurrentDate)
.and('contain.text', 'Test Region')
.and('contain.text', 'Supplementary')
cy.get('[data-test="date-created-1"]').should('contain.text', formattedCurrentDate)
})
cy.get('tr:nth-child(2) > td:nth-child(1) > a').click()
cy.get('[data-test="region-1"]').should('contain.text', 'Test Region')
cy.get('[data-test="bill-run-type-1"]').should('contain.text', 'Supplementary')
cy.get('[data-test="date-created-1"] > .govuk-link').click()

// Test Region supplementary bill run
// check the details before sending the bill run
Expand Down Expand Up @@ -112,25 +111,18 @@ describe('Change billing account in current financial year (internal)', () => {

// Bill runs
// back on the bill runs page confirm our SROC bill run is present and listed as SENT
cy.get('#main-content > div:nth-child(5) > div > table > tbody > tr:nth-child(2)').within(() => {
cy.get('@formattedCurrentDate').then((formattedCurrentDate) => {
cy.get('td:nth-child(1)').should('contain.text', formattedCurrentDate)
})

cy.get('td:nth-child(2)').should('contain.text', 'Test Region')
cy.get('td:nth-child(3)').should('contain.text', 'Supplementary')

cy.get('@currentFinancialYearInfo').then((currentFinancialYearInfo) => {
cy.get('td:nth-child(4)').should('contain.text', currentFinancialYearInfo.billingPeriodCount)
})

cy.get('td:nth-child(6)').should('contain.text', 'Sent')
cy.get('@formattedCurrentDate').then((formattedCurrentDate) => {
cy.get('[data-test="date-created-1"] > .govuk-link').should('contain.text', formattedCurrentDate)
})
cy.get('[data-test="region-1"]').should('contain.text', 'Test Region')
cy.get('[data-test="bill-run-type-1"]').should('contain.text', 'Supplementary')
cy.get('[data-test="number-of-bills-1"]').should('contain.text', '3')
cy.get('[data-test="bill-run-status-1"] > .govuk-tag').should('contain.text', 'sent')

// -------------------------------------------------------------------------

// click the Search menu link
cy.get('#navbar-view').click()
cy.get('#nav-search').click()

// Search
// search for a licence and select it
Expand Down Expand Up @@ -208,7 +200,7 @@ describe('Change billing account in current financial year (internal)', () => {

// Bill runs
// click the Create a bill run button
cy.get('#main-content > a.govuk-button').contains('Create a bill run').click()
cy.get('.govuk-button').contains('Create a bill run').click()

// Which kind of bill run do you want to create?
// choose Supplementary and continue
Expand All @@ -220,9 +212,6 @@ describe('Change billing account in current financial year (internal)', () => {
cy.get('label.govuk-radios__label').contains('Test Region').click()
cy.get('form > .govuk-button').contains('Continue').click()

// click the Bill runs menu link
cy.get('#navbar-bill-runs').contains('Bill runs').click()

// -------------------------------------------------------------------------
cy.log('Confirming and sending the SROC supplementary bill run')

Expand All @@ -231,14 +220,13 @@ describe('Change billing account in current financial year (internal)', () => {
// The bill run we created will be the top result. We expect it's status to be BUILDING. Building might take a few
// seconds though so to avoid the test failing we use our custom Cypress command to look for the status READY, and
// if not found reload the page and try again. We then select it using the link on the date created
cy.reloadUntilTextFound('tr:nth-child(1) > td:nth-child(6) > .govuk-tag', 'Ready')
cy.reloadUntilTextFound('[data-test="bill-run-status-0"] > .govuk-tag', 'ready')
cy.get('@formattedCurrentDate').then((formattedCurrentDate) => {
cy.get('tr:nth-child(1)')
.should('contain.text', formattedCurrentDate)
.and('contain.text', 'Test Region')
.and('contain.text', 'Supplementary')
cy.get('[data-test="date-created-0"]').should('contain.text', formattedCurrentDate)
})
cy.get('tr:nth-child(1) > td:nth-child(1) > a').click()
cy.get('[data-test="region-0"]').should('contain.text', 'Test Region')
cy.get('[data-test="bill-run-type-0"]').should('contain.text', 'Supplementary')
cy.get('[data-test="date-created-0"] > .govuk-link').click()

// Test Region supplementary bill run
// check the details before sending the bill run
Expand Down Expand Up @@ -293,13 +281,12 @@ describe('Change billing account in current financial year (internal)', () => {
// Bill runs
// back on the bill runs page confirm our SROC bill run is present and listed as SENT
cy.get('@formattedCurrentDate').then((formattedCurrentDate) => {
cy.get('#main-content > div:nth-child(5) > div > table > tbody > tr:nth-child(1)')
.should('contain.text', formattedCurrentDate)
.and('contain.text', 'Test Region')
.and('contain.text', 'Supplementary')
.and('contain.text', '2')
.and('contain.text', '£0.00')
.and('contain.text', 'Sent')
cy.get('[data-test="date-created-0"] > .govuk-link').should('contain.text', formattedCurrentDate)
})
cy.get('[data-test="region-0"]').should('contain.text', 'Test Region')
cy.get('[data-test="bill-run-type-0"]').should('contain.text', 'Supplementary')
cy.get('[data-test="number-of-bills-0"]').should('contain.text', '2')
cy.get('[data-test="bill-run-total-0"]').should('contain.text', '£0.00')
cy.get('[data-test="bill-run-status-0"] > .govuk-tag').should('contain.text', 'sent')
})
})
Loading

0 comments on commit b555e63

Please sign in to comment.