@defra/forms-engine-plugin 0.1.13 → 0.1.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.public/stylesheets/application.min.css +2 -2
- package/.public/stylesheets/application.min.css.map +1 -1
- package/.server/client/stylesheets/application.scss +1 -11
- package/.server/client/stylesheets/shared.scss +11 -0
- package/.server/server/plugins/engine/plugin.js.map +1 -1
- package/.server/server/plugins/engine/services/localFormsService.js +6 -0
- package/.server/server/plugins/engine/services/localFormsService.js.map +1 -1
- package/.server/server/plugins/nunjucks/context.js +5 -3
- package/.server/server/plugins/nunjucks/context.js.map +1 -1
- package/.server/server/plugins/nunjucks/context.test.js +11 -11
- package/.server/server/plugins/nunjucks/context.test.js.map +1 -1
- package/.server/typings/hapi/index.d.js.map +1 -1
- package/package.json +3 -3
- package/src/client/stylesheets/application.scss +1 -11
- package/src/client/stylesheets/shared.scss +11 -0
- package/src/server/plugins/engine/plugin.ts +2 -3
- package/src/server/plugins/engine/services/localFormsService.js +7 -0
- package/src/server/plugins/nunjucks/context.js +5 -3
- package/src/server/plugins/nunjucks/context.test.js +11 -11
- package/src/typings/hapi/index.d.ts +3 -2
- package/.server/client/stylesheets/_service-banner.scss +0 -24
- package/src/client/stylesheets/_service-banner.scss +0 -24
|
@@ -10,14 +10,14 @@ describe('Nunjucks context', () => {
|
|
|
10
10
|
|
|
11
11
|
describe('Asset path', () => {
|
|
12
12
|
it("should include 'assetPath' for GOV.UK Frontend icons", () => {
|
|
13
|
-
const { assetPath } = devtoolContext()
|
|
13
|
+
const { assetPath } = devtoolContext(null)
|
|
14
14
|
expect(assetPath).toBe('/assets')
|
|
15
15
|
})
|
|
16
16
|
})
|
|
17
17
|
|
|
18
18
|
describe('Asset helper', () => {
|
|
19
19
|
it("should locate 'assets-manifest.json' assets", () => {
|
|
20
|
-
const { getDxtAssetPath } = devtoolContext()
|
|
20
|
+
const { getDxtAssetPath } = devtoolContext(null)
|
|
21
21
|
|
|
22
22
|
expect(getDxtAssetPath('example.scss')).toBe(
|
|
23
23
|
'/stylesheets/example.xxxxxxx.min.css'
|
|
@@ -39,7 +39,7 @@ describe('Nunjucks context', () => {
|
|
|
39
39
|
|
|
40
40
|
// Update config for missing manifest
|
|
41
41
|
config.set('publicDir', tmpdir())
|
|
42
|
-
const { getDxtAssetPath } = devtoolContext()
|
|
42
|
+
const { getDxtAssetPath } = devtoolContext(null)
|
|
43
43
|
|
|
44
44
|
// Uses original paths when missing
|
|
45
45
|
expect(getDxtAssetPath('example.scss')).toBe('/example.scss')
|
|
@@ -48,24 +48,24 @@ describe('Nunjucks context', () => {
|
|
|
48
48
|
})
|
|
49
49
|
|
|
50
50
|
it('should return path to unknown assets', () => {
|
|
51
|
-
const { getDxtAssetPath } = devtoolContext()
|
|
51
|
+
const { getDxtAssetPath } = devtoolContext(null)
|
|
52
52
|
|
|
53
|
-
expect(getDxtAssetPath()).toBe('/')
|
|
53
|
+
expect(getDxtAssetPath('')).toBe('/')
|
|
54
54
|
expect(getDxtAssetPath('example.jpg')).toBe('/example.jpg')
|
|
55
55
|
expect(getDxtAssetPath('example.gif')).toBe('/example.gif')
|
|
56
56
|
})
|
|
57
57
|
})
|
|
58
58
|
|
|
59
59
|
describe('Config', () => {
|
|
60
|
-
it('should include environment, phase tag and service info', () => {
|
|
61
|
-
expect(
|
|
60
|
+
it('should include environment, phase tag and service info', async () => {
|
|
61
|
+
await expect(context(null)).rejects.toThrow(
|
|
62
62
|
'context called before plugin registered'
|
|
63
63
|
)
|
|
64
64
|
})
|
|
65
65
|
})
|
|
66
66
|
|
|
67
67
|
describe('Crumb', () => {
|
|
68
|
-
it('should handle malformed requests with missing state', () => {
|
|
68
|
+
it('should handle malformed requests with missing state', async () => {
|
|
69
69
|
// While state should always exist in a valid Hapi request (it holds cookies),
|
|
70
70
|
// we've seen malformed requests in production where it's missing
|
|
71
71
|
const malformedRequest = /** @type {FormRequest} */ (
|
|
@@ -92,14 +92,14 @@ describe('Nunjucks context', () => {
|
|
|
92
92
|
})
|
|
93
93
|
)
|
|
94
94
|
|
|
95
|
-
const { crumb } = context(malformedRequest)
|
|
95
|
+
const { crumb } = await context(malformedRequest)
|
|
96
96
|
expect(crumb).toBeUndefined()
|
|
97
97
|
expect(
|
|
98
98
|
malformedRequest.server.plugins.crumb.generate
|
|
99
99
|
).not.toHaveBeenCalled()
|
|
100
100
|
})
|
|
101
101
|
|
|
102
|
-
it('should generate crumb when state exists', () => {
|
|
102
|
+
it('should generate crumb when state exists', async () => {
|
|
103
103
|
const mockCrumb = 'generated-crumb-value'
|
|
104
104
|
const validRequest = /** @type {FormRequest} */ (
|
|
105
105
|
/** @type {unknown} */ ({
|
|
@@ -125,7 +125,7 @@ describe('Nunjucks context', () => {
|
|
|
125
125
|
})
|
|
126
126
|
)
|
|
127
127
|
|
|
128
|
-
const { crumb } = context(validRequest)
|
|
128
|
+
const { crumb } = await context(validRequest)
|
|
129
129
|
expect(crumb).toBe(mockCrumb)
|
|
130
130
|
expect(validRequest.server.plugins.crumb.generate).toHaveBeenCalledWith(
|
|
131
131
|
validRequest
|
|
@@ -5,7 +5,6 @@ import { type ServerYar, type Yar } from '@hapi/yar'
|
|
|
5
5
|
import { type Logger } from 'pino'
|
|
6
6
|
|
|
7
7
|
import { type FormModel } from '~/src/server/plugins/engine/models/index.js'
|
|
8
|
-
import { type context } from '~/src/server/plugins/engine/nunjucks.js'
|
|
9
8
|
import {
|
|
10
9
|
type FormRequest,
|
|
11
10
|
type FormRequestPayload
|
|
@@ -22,7 +21,9 @@ declare module '@hapi/hapi' {
|
|
|
22
21
|
'forms-engine-plugin': {
|
|
23
22
|
baseLayoutPath: string
|
|
24
23
|
cacheService: CacheService
|
|
25
|
-
viewContext
|
|
24
|
+
viewContext?: (
|
|
25
|
+
request: FormRequest | FormRequestPayload | null
|
|
26
|
+
) => Record<string, unknown> | Promise<Record<string, unknown>>
|
|
26
27
|
}
|
|
27
28
|
}
|
|
28
29
|
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
@use "govuk-frontend" as *;
|
|
2
|
-
|
|
3
|
-
.app-service-banner {
|
|
4
|
-
display: block;
|
|
5
|
-
background: govuk-colour("yellow");
|
|
6
|
-
color: govuk-colour("black");
|
|
7
|
-
|
|
8
|
-
@include govuk-responsive-padding(2, "top");
|
|
9
|
-
@include govuk-responsive-padding(2, "bottom");
|
|
10
|
-
|
|
11
|
-
&__content {
|
|
12
|
-
margin: 0;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
.govuk-warning-text__text {
|
|
16
|
-
font-weight: $govuk-font-weight-regular;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
.govuk-skip-link:active + &,
|
|
20
|
-
.govuk-skip-link:focus + & {
|
|
21
|
-
// Ofset service banner from skip link
|
|
22
|
-
margin-top: $govuk-border-width + $govuk-focus-width;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
@use "govuk-frontend" as *;
|
|
2
|
-
|
|
3
|
-
.app-service-banner {
|
|
4
|
-
display: block;
|
|
5
|
-
background: govuk-colour("yellow");
|
|
6
|
-
color: govuk-colour("black");
|
|
7
|
-
|
|
8
|
-
@include govuk-responsive-padding(2, "top");
|
|
9
|
-
@include govuk-responsive-padding(2, "bottom");
|
|
10
|
-
|
|
11
|
-
&__content {
|
|
12
|
-
margin: 0;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
.govuk-warning-text__text {
|
|
16
|
-
font-weight: $govuk-font-weight-regular;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
.govuk-skip-link:active + &,
|
|
20
|
-
.govuk-skip-link:focus + & {
|
|
21
|
-
// Ofset service banner from skip link
|
|
22
|
-
margin-top: $govuk-border-width + $govuk-focus-width;
|
|
23
|
-
}
|
|
24
|
-
}
|