generated from ministryofjustice/hmpps-template-typescript
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Navigate to placeholder occupancy view
- Loading branch information
1 parent
027a975
commit 6f32035
Showing
9 changed files
with
124 additions
and
31 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Page, expect } from '@playwright/test' | ||
import { BasePage } from '../basePage' | ||
import { Premises } from '../../../server/@types/shared' | ||
|
||
export class OccupancyViewScreen extends BasePage { | ||
static async initialize(page: Page, premisesName: Premises['name']) { | ||
await expect(page.locator('h1')).toContainText(`View spaces in ${premisesName}`) | ||
|
||
return new OccupancyViewScreen(page) | ||
} | ||
} |
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
51 changes: 51 additions & 0 deletions
51
server/controllers/match/placementRequests/occupancyViewController.test.ts
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import type { NextFunction, Request, Response } from 'express' | ||
import { DeepMocked, createMock } from '@golevelup/ts-jest' | ||
|
||
import { PlacementRequestService } from '../../../services' | ||
import { personFactory, placementRequestDetailFactory } from '../../../testutils/factories' | ||
import OccupancyViewController from './occupancyViewController' | ||
|
||
describe('OccupancyViewController', () => { | ||
const token = 'SOME_TOKEN' | ||
|
||
const request: DeepMocked<Request> = createMock<Request>({ user: { token } }) | ||
const response: DeepMocked<Response> = createMock<Response>({}) | ||
const next: DeepMocked<NextFunction> = createMock<NextFunction>({}) | ||
|
||
const placementRequestService = createMock<PlacementRequestService>({}) | ||
|
||
let occupancyViewController: OccupancyViewController | ||
|
||
beforeEach(() => { | ||
jest.resetAllMocks() | ||
occupancyViewController = new OccupancyViewController(placementRequestService) | ||
}) | ||
|
||
describe('view', () => { | ||
it('should render the occupancy view template', async () => { | ||
const person = personFactory.build({ name: 'John Wayne' }) | ||
const placementRequestDetail = placementRequestDetailFactory.build({ person }) | ||
const premisesName = 'Hope House' | ||
const premisesId = 'abc123' | ||
|
||
placementRequestService.getPlacementRequest.mockResolvedValue(placementRequestDetail) | ||
|
||
const query = { | ||
premisesName, | ||
premisesId, | ||
} | ||
|
||
const params = { id: placementRequestDetail.id } | ||
|
||
const requestHandler = occupancyViewController.view() | ||
|
||
await requestHandler({ ...request, params, query }, response, next) | ||
|
||
expect(response.render).toHaveBeenCalledWith('match/placementRequests/occupancyView/view', { | ||
pageHeading: `View spaces in ${premisesName}`, | ||
placementRequest: placementRequestDetail, | ||
}) | ||
expect(placementRequestService.getPlacementRequest).toHaveBeenCalledWith(token, placementRequestDetail.id) | ||
}) | ||
}) | ||
}) |
24 changes: 24 additions & 0 deletions
24
server/controllers/match/placementRequests/occupancyViewController.ts
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import type { Request, Response, TypedRequestHandler } from 'express' | ||
import { ApType } from '@approved-premises/api' | ||
import { PlacementRequestService } from '../../../services' | ||
|
||
interface NewRequest extends Request { | ||
params: { id: string } | ||
query: { startDate: string; durationDays: string; premisesName: string; premisesId: string; apType: ApType } | ||
} | ||
|
||
export default class { | ||
constructor(private readonly placementRequestService: PlacementRequestService) {} | ||
|
||
view(): TypedRequestHandler<Request, Response> { | ||
return async (req: NewRequest, res: Response) => { | ||
const placementRequest = await this.placementRequestService.getPlacementRequest(req.user.token, req.params.id) | ||
const { premisesName } = req.query | ||
|
||
res.render('match/placementRequests/occupancyView/view', { | ||
pageHeading: `View spaces in ${premisesName}`, | ||
placementRequest, | ||
}) | ||
} | ||
} | ||
} |
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
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
24 changes: 24 additions & 0 deletions
24
server/views/match/placementRequests/occupancyView/view.njk
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{% from "govuk/components/summary-list/macro.njk" import govukSummaryList %} | ||
{% from "govuk/components/button/macro.njk" import govukButton %} | ||
{% from "govuk/components/back-link/macro.njk" import govukBackLink %} | ||
|
||
{% extends "../../layout-with-details.njk" %} | ||
|
||
{% set pageTitle = applicationName + " - " + pageHeading %} | ||
|
||
{% block beforeContent %} | ||
{{ govukBackLink({ | ||
text: "Back to other APs", | ||
href: paths.v2Match.placementRequests.search.spaces({ id: placementRequest.id }) | ||
}) }} | ||
{% endblock %} | ||
|
||
{% block content %} | ||
<div class="govuk-width-container"> | ||
<div class="govuk-grid-row"> | ||
<div class="govuk-grid-column-two-thirds"> | ||
<h1 class="govuk-heading-l">{{ pageHeading }}</h1> | ||
</div> | ||
</div> | ||
</div> | ||
{% endblock %} |