Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show submitted referrals #663

Merged
merged 6 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions cypress_shared/pages/apply/full.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { TemporaryAccommodationApplication as Application } from '../../../server/@types/shared'
import paths from '../../../server/paths/apply'
import type { Section } from '../../../server/utils/applicationUtils'
import { personName } from '../../../server/utils/personUtils'
import Page from '../page'

export default class ApplicationFullPage extends Page {
constructor(private readonly application: Application) {
super(personName(application.person, 'Limited access offender'))
}

static visit(application: Application): ApplicationFullPage {
cy.visit(paths.applications.full({ id: application.id }))

return new ApplicationFullPage(application)
}

shouldShowApplication(applicationTranslatedDocument: Record<'sections', Array<Section>>) {
applicationTranslatedDocument.sections.forEach(section => {
cy.get('h2').contains(section.title)

section.tasks.forEach(task => {
cy.get('.govuk-summary-card__title-wrapper')
.contains(task.title)
.parent()
.next('div')
.within(() => {
task.content.forEach(content => {
Object.entries(content).forEach(([key, value]) => {
if (typeof value === 'string') {
value.split('\n').forEach(line => {
this.assertDefinition(key, line)
})
} else {
cy.get('dt')
.contains(key)
.parent()
.within(() => {
value.forEach((embeddedRecord, index) => {
cy.get('dl.govuk-summary-list--embedded')
.eq(index)
.within(() => {
Object.keys(embeddedRecord).forEach(embeddedKey => {
this.assertDefinition(embeddedKey, embeddedRecord[embeddedKey] as string)
})
})
})
})
}
})
})
})
})
})
}
}
2 changes: 2 additions & 0 deletions cypress_shared/pages/apply/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import SelectOffencePage from './selectOffence'
import StartPage from './startPage'
import SubmissionConfirmation from './submissionConfirmation'
import TaskListPage from './taskListPage'
import ApplicationFullPage from './full'

export {
AccommodationRequiredFromDatePage,
Expand Down Expand Up @@ -92,4 +93,5 @@ export {
SubstanceMisusePage,
SupportInTheCommunityPage,
TaskListPage,
ApplicationFullPage,
}
67 changes: 41 additions & 26 deletions cypress_shared/pages/apply/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ import { isFullPerson, personName } from '../../../server/utils/personUtils'
import Page from '../page'

export default class ListPage extends Page {
constructor(private readonly inProgressApplications: Array<Application>) {
constructor(
private readonly inProgressApplications: Array<Application>,
private readonly submittedApplications: Array<Application>,
) {
super('Transitional Accommodation (CAS3) referrals')
}

static visit(inProgressApplications: Array<Application>): ListPage {
static visit(inProgressApplications: Array<Application>, submittedApplications: Array<Application>): ListPage {
cy.visit(paths.applications.index.pattern)

return new ListPage(inProgressApplications)
return new ListPage(inProgressApplications, submittedApplications)
}

clickApplication(application: Application) {
Expand All @@ -27,35 +30,47 @@ export default class ListPage extends Page {
this.shouldShowApplications(this.inProgressApplications, 'in-progress', 'In Progress')
}

shouldShowSubmittedApplications(): void {
this.shouldShowApplications(this.submittedApplications, 'applications-submitted', 'Submitted')
}

shouldShowSubmittedApplication(application: Application): void {
this.shouldShowApplication(application, 'applications-submitted', 'Submitted')
}

clickSubmit() {
cy.get('.govuk-button').click()
}

clickSubmittedTab() {
cy.get('a').contains('Submitted').click()
}

private shouldShowApplication(application: Application, containerId: string, status: string): void {
cy.get(`#${containerId}`).within(() => {
cy.get(`a[href*="${paths.applications.show({ id: application.id })}"]`)
.parent()
.parent()
.within(() => {
cy.get('th').eq(0).contains(personName(application.person, 'Limited access offender'))
cy.get('td').eq(0).contains(application.person.crn)
cy.get('td')
.eq(1)
.contains(
application.submittedAt
? DateFormats.isoDateToUIDate(application.submittedAt, {
format: 'short',
})
: 'N/A',
)
cy.get('td').eq(2).contains(status)
})
})
}

private shouldShowApplications(applications: Array<Application>, containerId: string, status: string): void {
cy.get(`#${containerId}`).find('tbody>tr').should('have.length', applications.length)

applications.forEach(application => {
const releaseDate = application.data['basic-information']?.['release-date']?.releaseDate

cy.get(`#${containerId}`).within(() => {
cy.get(`a[href*="${paths.applications.show({ id: application.id })}"]`)
.parent()
.parent()
.within(() => {
cy.get('th').eq(0).contains(personName(application.person, 'Limited access offender'))
cy.get('td').eq(0).contains(application.person.crn)
cy.get('td')
.eq(1)
.contains(
releaseDate
? DateFormats.isoDateToUIDate(releaseDate, {
format: 'short',
})
: 'N/A',
)
cy.get('td').eq(2).contains(status)
})
})
})
applications.forEach(application => this.shouldShowApplication(application, containerId, status))
}
}
3 changes: 2 additions & 1 deletion e2e/tests/apply-and-place.feature
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ Feature: Apply for and book a Temporary Accommodation bedspace
Given I am logged in as a referrer
When I start a new application
And I fill in and complete an application
Then I should see a confirmation of the application
And I see a confirmation of the application
Then I can see the full submitted application
Scenario: Booking a bedspace from an assessment
Given I am logged in as an assessor
When I view an existing active premises
Expand Down
18 changes: 17 additions & 1 deletion e2e/tests/stepDefinitions/apply.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Given, Then } from '@badeball/cypress-cucumber-preprocessor'

import ApplyHelper from '../../../cypress_shared/helpers/apply'
import ListPage from '../../../cypress_shared/pages/apply/list'
import ApplicationFullPage from '../../../cypress_shared/pages/apply/full'
import SelectOffencePage from '../../../cypress_shared/pages/apply/selectOffence'
import SubmissionConfirmation from '../../../cypress_shared/pages/apply/submissionConfirmation'
import Page from '../../../cypress_shared/pages/page'
Expand Down Expand Up @@ -48,8 +50,22 @@ Given('I fill in and complete an application', () => {
})
})

Then('I should see a confirmation of the application', () => {
Given('I see a confirmation of the application', () => {
const confirmationPage = Page.verifyOnPage(SubmissionConfirmation)

confirmationPage.clickBackToDashboard()
})

Then('I can see the full submitted application', () => {
cy.url().then(function _() {
const listPage = Page.verifyOnPage(ListPage, [], [])

listPage.clickSubmittedTab()

listPage.shouldShowSubmittedApplication(this.application)

listPage.clickApplication(this.application)

Page.verifyOnPage(ApplicationFullPage, this.application)
})
})
32 changes: 27 additions & 5 deletions integration_tests/tests/apply/apply.cy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
ApplicationFullPage,
EnterCRNPage,
ListPage,
MoveOnPlanPage,
Expand Down Expand Up @@ -187,7 +188,7 @@ context('Apply', () => {
confirmationPage.clickBackToDashboard()

// Then I am taken back to the dashboard
Page.verifyOnPage(ListPage, applications)
Page.verifyOnPage(ListPage, applications, [])
})

it('shows an error if the application is submitted without checking the confirm checkbox', function test() {
Expand All @@ -198,7 +199,7 @@ context('Apply', () => {
apply.setupApplicationStubs()

// When I visit the application listing page
const listPage = ListPage.visit([this.application])
const listPage = ListPage.visit([this.application], [])

// And I click on the application
listPage.clickApplication(this.application)
Expand All @@ -220,7 +221,7 @@ context('Apply', () => {
apply.setupApplicationStubs()

// When I visit the application listing page
const listPage = ListPage.visit([application])
const listPage = ListPage.visit([application], [])

// And I click on the application
listPage.clickApplication(application)
Expand All @@ -238,7 +239,7 @@ context('Apply', () => {
apply.setupApplicationStubs()

// When I visit the application listing page
const listPage = ListPage.visit([this.application])
const listPage = ListPage.visit([this.application], [])

// And I click on the application
listPage.clickApplication(this.application)
Expand Down Expand Up @@ -277,7 +278,7 @@ context('Apply', () => {
apply.setupApplicationStubs()

// When I visit the application listing page
const listPage = ListPage.visit([this.application])
const listPage = ListPage.visit([this.application], [])

// And I click on the application
listPage.clickApplication(this.application)
Expand All @@ -296,4 +297,25 @@ context('Apply', () => {
// Then I check your answers should be marked as completed
taskListPage.shouldShowTaskStatus('check-your-answers', 'Completed')
})

it('shows the full submitted application', function test() {
// Given there is a complete and submitted application
const application = { ...this.application, status: 'submitted' }

cy.task('stubApplications', [application])
cy.task('stubApplicationGet', { application })

// When I visit the application listing page
const listPage = ListPage.visit([], [application])

// And I click on the submitted tab
listPage.clickSubmittedTab()

// And I click on an application
listPage.clickApplication(application)

// Then I should see the full application
const applicationFullPage = Page.verifyOnPage(ApplicationFullPage, application)
applicationFullPage.shouldShowApplication(application.document)
})
})
8 changes: 7 additions & 1 deletion integration_tests/tests/apply/list.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,17 @@ context('Applications dashboard', () => {
cy.signIn()

// When I visit the Previous Applications page
const page = ListPage.visit(inProgressApplications)
const page = ListPage.visit(inProgressApplications, submittedApplications)

// Then I should see all of the in progress applications
page.shouldShowInProgressApplications()

// And I click on the submitted tab
page.clickSubmittedTab()

// Then I should see the applications that have been submitted
page.shouldShowSubmittedApplications()

// And I the button should take me to the application start page
page.clickSubmit()

Expand Down
2 changes: 1 addition & 1 deletion integration_tests/tests/apply/show.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ context('Application Page', () => {
page.clickBack()

// Then I navigate to the list application page
Page.verifyOnPage(ListPage, inProgressApplications)
Page.verifyOnPage(ListPage, inProgressApplications, [])
})
})
2 changes: 1 addition & 1 deletion integration_tests/tests/landing.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ context('Landing', () => {
cy.signIn()

// I am redirected to the application listing page
Page.verifyOnPage(ListPage, [])
Page.verifyOnPage(ListPage, [], [])
})

it('redirects a user who is not an assessor or a referrer', () => {
Expand Down
15 changes: 15 additions & 0 deletions server/controllers/apply/applicationsController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,4 +348,19 @@ describe('applicationsController', () => {
expect(response.render).toHaveBeenCalledWith('applications/confirm')
})
})

describe('full', () => {
it('renders the full application page for submitted referrals', async () => {
const application = createMock<TemporaryAccommodationApplication>()

request = createMock<Request>({
params: { id: application.id },
})

const requestHandler = applicationsController.full()
await requestHandler(request, response, next)

expect(response.render).toHaveBeenCalledWith('applications/full', application)
})
})
})
13 changes: 13 additions & 0 deletions server/controllers/apply/applicationsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,17 @@ export default class ApplicationsController {
return res.render('applications/confirm')
}
}

full(): RequestHandler {
libuk marked this conversation as resolved.
Show resolved Hide resolved
return async (req: Request, res: Response) => {
const callConfig = extractCallConfig(req)

const { id } = req.params
const application = await this.applicationService.findApplication(callConfig, id)

return res.render('applications/full', {
application,
})
}
}
}
1 change: 1 addition & 0 deletions server/paths/apply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const paths = {
index: applicationsPath,
show: applicationPath,
update: applicationPath,
full: applicationPath.path('full'),
checkYourAnswers: applicationPath.path('check-your-answers'),
submission: applicationPath.path('submission'),
confirm: applicationPath.path('confirm'),
Expand Down
1 change: 1 addition & 0 deletions server/routes/apply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export default function routes(controllers: Controllers, services: Services, rou
get(paths.applications.index.pattern, applicationsController.index(), { auditEvent: 'VIEW_APPLICATIONS_LIST' })
get(paths.applications.new.pattern, applicationsController.new(), { auditEvent: 'VIEW_APPLICATION_NEW' })
get(paths.applications.show.pattern, applicationsController.show(), { auditEvent: 'VIEW_APPLICATION' })
get(paths.applications.full.pattern, applicationsController.full(), { auditEvent: 'VIEW_FULL_APPLICATION' })
get(paths.applications.confirm.pattern, applicationsController.confirm(), {
auditEvent: 'VIEW_APPLICATION_CONFIRM',
})
Expand Down
1 change: 1 addition & 0 deletions server/services/applicationService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ describe('ApplicationService', () => {

expect(result).toEqual({
inProgress: inProgressApplications,
submitted: submittedApplications,
})

expect(applicationClientFactory).toHaveBeenCalledWith(callConfig)
Expand Down
4 changes: 4 additions & 0 deletions server/services/applicationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export default class ApplicationService {
const allApplications = await applicationClient.all()
const result = {
inProgress: [],
submitted: [],
} as GroupedApplications

await Promise.all(
Expand All @@ -43,6 +44,9 @@ export default class ApplicationService {
case 'inProgress':
result.inProgress.push(application)
break
case 'submitted':
result.submitted.push(application)
break
default:
break
}
Expand Down
Loading