Skip to content

Commit 9651e41

Browse files
authored
RA-243: add log prisoner details e2e tests (#15)
* add log prisoner details e2e tests * update tests * remove redundant code
1 parent 1ba25b6 commit 9651e41

File tree

3 files changed

+96
-4
lines changed

3 files changed

+96
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import LogPrisonerDetailsPage from '../pages/logPrisonerDetails'
2+
import Page from '../pages/page'
3+
4+
context('Log Prisoner Details Page', () => {
5+
let page: LogPrisonerDetailsPage
6+
7+
beforeEach(() => {
8+
cy.task('reset')
9+
cy.task('stubSignIn')
10+
cy.signIn()
11+
12+
cy.visit('/log/prisoner-details')
13+
14+
cy.contains('Swap visiting orders (VOs) for PIN credit').click()
15+
cy.contains('button', 'Continue').click()
16+
17+
page = Page.verifyOnPage(LogPrisonerDetailsPage)
18+
})
19+
20+
it('should direct the user to the correct page', () => {
21+
Page.verifyOnPage(LogPrisonerDetailsPage)
22+
})
23+
24+
it('should display the correct page title', () => {
25+
page.pageTitle().should('include', 'Log prisoner details')
26+
})
27+
28+
it('should render the back link with correct text and href', () => {
29+
page.backLink().should('have.text', 'Back').and('have.attr', 'href', '/log/application-type')
30+
})
31+
32+
it('should display the prisoner details form', () => {
33+
page.form().should('exist')
34+
})
35+
36+
it('should include a hidden CSRF token input field', () => {
37+
page.csrfToken().should('exist').and('have.attr', 'type', 'hidden')
38+
})
39+
40+
it('should render the prison number input field', () => {
41+
page.prisonNumberInput().should('exist').and('have.attr', 'type', 'text').and('have.attr', 'name', 'prisonNumber')
42+
})
43+
44+
it('should render the "Find prisoner" button', () => {
45+
page
46+
.findPrisonerButton()
47+
.should('exist')
48+
.and('have.class', 'govuk-button--secondary')
49+
.and('include.text', 'Find prisoner')
50+
})
51+
52+
it('should render the prisoner name inset text', () => {
53+
page.prisonerNameInsetText().should('exist').and('contain.text', 'Prisoner name: Patel, Taj')
54+
})
55+
56+
it('should render the date picker', () => {
57+
page.dateInput().should('exist')
58+
page.dateLabel().should('exist').and('include.text', 'Date')
59+
})
60+
61+
it('should render the continue button with the correct text', () => {
62+
page.continueButton().should('exist').and('include.text', 'Continue').and('have.class', 'govuk-button--primary')
63+
})
64+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import Page from './page'
2+
3+
export default class LogPrisonerDetailsPage extends Page {
4+
constructor() {
5+
super('Log prisoner details')
6+
}
7+
8+
backLink = () => cy.get('.govuk-back-link')
9+
10+
pageTitle = () => cy.title()
11+
12+
form = () => cy.get('form#log-prisoner-details')
13+
14+
csrfToken = () => cy.get('input[name="_csrf"]')
15+
16+
prisonNumberInput = () => cy.get('input#prison-number')
17+
18+
findPrisonerButton = () => cy.get('[data-test="find-prisoner-button"]')
19+
20+
prisonerNameInsetText = () => cy.get('.govuk-inset-text')
21+
22+
dateInput = () => cy.get('#date')
23+
24+
dateLabel = () => cy.get('label[for="date"]')
25+
26+
continueButton = () => cy.get('[data-test="continue-button"]')
27+
}

server/views/pages/log/prisoner-details.njk

+5-4
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828
Prison number
2929
</label>
3030

31-
<input class="govuk-input govuk-input--width-10" id="prisonNumber" name="prisonNumber" type="text" value="">
31+
<input class="govuk-input govuk-input--width-10" id="prison-number" name="prisonNumber" type="text" value="">
3232

33-
<button id="prison-number-lookup" class="govuk-button govuk-button--secondary" data-module="govuk-button">
33+
<button id="prisoner-number-lookup" class="govuk-button govuk-button--secondary" data-test="find-prisoner-button">
3434
Find prisoner
3535
</button>
3636
</div>
@@ -40,7 +40,7 @@
4040
classes: "govuk-!-margin-top-0"
4141
}) }}
4242

43-
<input type="hidden" id="prisonerName" name="prisonerName" value="Patel, Taj">
43+
<input type="hidden" id="prisoner-name" name="prisonerName" value="Patel, Taj">
4444

4545
{{ mojDatePicker({
4646
id: "date",
@@ -53,7 +53,8 @@
5353

5454
{{ govukButton({
5555
text: "Continue",
56-
classes: "govuk-button--primary"
56+
classes: "govuk-button--primary",
57+
attributes: { "data-test": "continue-button" }
5758
}) }}
5859
</form>
5960
</div>

0 commit comments

Comments
 (0)