generated from ministryofjustice/hmpps-template-typescript
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for sessionTemplateVisitStats() macro
- Loading branch information
Showing
4 changed files
with
52 additions
and
6 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
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,46 @@ | ||
import * as cheerio from 'cheerio' | ||
import nunjucks from 'nunjucks' | ||
import { registerNunjucks } from '../../utils/nunjucksSetup' | ||
import { SessionTemplateVisitStatsDto } from '../../data/visitSchedulerApiTypes' | ||
import TestData from '../../routes/testutils/testData' | ||
|
||
const njkEnv = registerNunjucks(null) | ||
const nunjucksString = ` | ||
{%- from "components/sessionTemplateVisitStats.njk" import sessionTemplateVisitStats -%} | ||
{{ sessionTemplateVisitStats(visitStats) }} | ||
` | ||
const compiledTemplate = nunjucks.compile(nunjucksString, njkEnv) | ||
|
||
let visitStats: SessionTemplateVisitStatsDto | ||
const viewContext = { visitStats } | ||
|
||
describe('sessionTemplateVisitStats(visitStats) macro', () => { | ||
it('should handle missing visit stats', () => { | ||
const $ = cheerio.load(compiledTemplate.render(viewContext)) | ||
|
||
expect($.text()).toBe('') | ||
}) | ||
|
||
it('should render cancelled visit count', () => { | ||
viewContext.visitStats = TestData.visitStats({ | ||
cancelCount: 1, | ||
visitCount: 0, | ||
visitsByDate: [], | ||
}) | ||
const $ = cheerio.load(compiledTemplate.render(viewContext)) | ||
|
||
expect($.text().trim()).toContain('0 booked visits') | ||
expect($.text().trim()).toContain('1 cancelled visit') | ||
expect($.text().trim()).not.toContain('Future booked visits') | ||
}) | ||
|
||
it('should render booked visit count and future visits by date date list', () => { | ||
viewContext.visitStats = TestData.visitStats() | ||
const $ = cheerio.load(compiledTemplate.render(viewContext)) | ||
|
||
expect($.text().trim()).toContain('7 booked visits') | ||
expect($.text().trim()).toContain('0 cancelled visits') | ||
expect($.text().trim()).toContain('Future booked visits') | ||
expect($.text().trim()).toContain('8 January 2023 – 4 open and 3 closed') | ||
}) | ||
}) |
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