-
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.
- Loading branch information
1 parent
4eec163
commit 94d51d2
Showing
6 changed files
with
206 additions
and
1 deletion.
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
42 changes: 42 additions & 0 deletions
42
src/server/plugins/engine/views/partials/preview-banner.test.js
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,42 @@ | ||
import { FormStatus } from '~/src/server/routes/types.js' | ||
import { renderView } from '~/test/helpers/component-helpers.js' | ||
|
||
describe('Preview banner partial', () => { | ||
describe.each([ | ||
{ | ||
status: FormStatus.Draft | ||
}, | ||
{ | ||
status: FormStatus.Live | ||
} | ||
])('Status: $status', ({ status }) => { | ||
let $component = /** @type {HTMLElement | null} */ (null) | ||
let $paragraph = /** @type {HTMLElement | null} */ (null) | ||
|
||
beforeEach(() => { | ||
const { container } = renderView('partials/preview-banner.html', { | ||
context: { previewMode: status } | ||
}) | ||
|
||
$component = container.getByRole('region') | ||
$paragraph = container.getByRole('paragraph') | ||
}) | ||
|
||
it('should render contents', () => { | ||
expect($component).toBeInTheDocument() | ||
expect($component).toContainElement($paragraph) | ||
expect($component).toHaveClass('govuk-notification-banner') | ||
expect($paragraph).toHaveClass('govuk-notification-banner__heading') | ||
}) | ||
|
||
it('should have accessible name', () => { | ||
expect($component).toHaveAccessibleName('Important') | ||
}) | ||
|
||
it('should have text content', () => { | ||
expect($component).toHaveTextContent( | ||
`This is a preview of a ${status} form. Do not enter personal information.` | ||
) | ||
}) | ||
}) | ||
}) |
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,47 @@ | ||
import { config } from '~/src/config/index.js' | ||
import { context } from '~/src/server/plugins/nunjucks/context.js' | ||
|
||
describe('Nunjucks context', () => { | ||
describe('Asset path', () => { | ||
it("should include 'assetPath' for GOV.UK Frontend icons", () => { | ||
const { assetPath } = context(null) | ||
expect(assetPath).toBe('/assets') | ||
}) | ||
}) | ||
|
||
describe('Asset helper', () => { | ||
it("should locate 'assets-manifest.json' assets", () => { | ||
const { getAssetPath } = context(null) | ||
|
||
expect(getAssetPath('example.scss')).toBe( | ||
'/stylesheets/example.xxxxxxx.min.css' | ||
) | ||
|
||
expect(getAssetPath('example.mjs')).toBe( | ||
'/javascripts/example.xxxxxxx.min.js' | ||
) | ||
}) | ||
|
||
it('should return path to unknown assets', () => { | ||
const { getAssetPath } = context(null) | ||
|
||
expect(getAssetPath('example.jpg')).toBe('/example.jpg') | ||
expect(getAssetPath('example.gif')).toBe('/example.gif') | ||
}) | ||
}) | ||
|
||
describe('Config', () => { | ||
it('should include environment, phase tag and service info', () => { | ||
const ctx = context(null) | ||
|
||
expect(ctx).toEqual( | ||
expect.objectContaining({ | ||
cdpEnvironment: config.get('cdpEnvironment'), | ||
phaseTag: config.get('phaseTag'), | ||
serviceName: config.get('serviceName'), | ||
serviceVersion: config.get('serviceVersion') | ||
}) | ||
) | ||
}) | ||
}) | ||
}) |
43 changes: 43 additions & 0 deletions
43
src/server/views/components/service-banner/template.test.js
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,43 @@ | ||
import { renderMacro } from '~/test/helpers/component-helpers.js' | ||
|
||
describe('Service banner component', () => { | ||
let $component = /** @type {HTMLElement | null} */ (null) | ||
let $content = /** @type {HTMLElement | null} */ (null) | ||
let $text = /** @type {HTMLElement | null} */ (null) | ||
|
||
beforeEach(() => { | ||
const { container, document } = renderMacro( | ||
'appServiceBanner', | ||
'components/service-banner/macro.njk', | ||
{ | ||
params: { | ||
title: 'Service status', | ||
text: 'This is a service status message' | ||
} | ||
} | ||
) | ||
|
||
$component = container.getByRole('complementary') | ||
$content = document.querySelector('.app-service-banner__content') | ||
$text = document.querySelector('.app-service-banner__text') | ||
}) | ||
|
||
it('should render contents', () => { | ||
expect($component).toBeInTheDocument() | ||
expect($component).toHaveClass('app-service-banner') | ||
expect($component).toContainElement($content) | ||
expect($content).toContainElement($text) | ||
}) | ||
|
||
it('should announce service message', () => { | ||
expect($component).toHaveAttribute('aria-live', 'polite') | ||
}) | ||
|
||
it('should have accessible name', () => { | ||
expect($component).toHaveAccessibleName('Service status') | ||
}) | ||
|
||
it('should have text content', () => { | ||
expect($text).toHaveTextContent('This is a service status message') | ||
}) | ||
}) |
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,66 @@ | ||
import { renderMacro } from '~/test/helpers/component-helpers.js' | ||
|
||
describe('Tag environment component', () => { | ||
describe.each([ | ||
{ | ||
text: 'Local', | ||
env: 'local', | ||
colour: 'green' | ||
}, | ||
{ | ||
text: 'Development', | ||
env: 'dev', | ||
colour: 'grey' | ||
}, | ||
{ | ||
text: 'Test', | ||
env: 'test', | ||
colour: 'yellow' | ||
}, | ||
{ | ||
text: 'External test', | ||
env: 'ext-test', | ||
colour: 'yellow' | ||
}, | ||
{ | ||
text: 'Performance test', | ||
env: 'perf-test', | ||
colour: 'yellow' | ||
}, | ||
{ | ||
text: 'Production', | ||
env: 'prod', | ||
colour: 'red' | ||
}, | ||
{ | ||
text: 'Unknown environment', | ||
env: 'unknown-environment', | ||
colour: 'grey' | ||
} | ||
])('Environment: $text', ({ text, env, colour }) => { | ||
let $component = /** @type {HTMLElement | null} */ (null) | ||
|
||
beforeEach(() => { | ||
const { container } = renderMacro( | ||
'appTagEnv', | ||
'components/tag-env/macro.njk', | ||
{ params: { env } } | ||
) | ||
|
||
$component = container.getByRole('strong') | ||
}) | ||
|
||
it('should render contents', () => { | ||
expect($component).toBeInTheDocument() | ||
expect($component).toHaveClass('govuk-tag') | ||
}) | ||
|
||
it('should have text content', () => { | ||
expect($component).toHaveTextContent(text) | ||
}) | ||
|
||
it('should use environment colour', () => { | ||
expect($component).toHaveClass(`govuk-tag--${colour}`) | ||
}) | ||
}) | ||
}) |
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,4 @@ | ||
{ | ||
"example.mjs": "javascripts/example.xxxxxxx.min.js", | ||
"example.scss": "stylesheets/example.xxxxxxx.min.css" | ||
} |