@defra/forms-engine-plugin 0.0.3 → 0.0.5

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.
Files changed (105) hide show
  1. package/.public/assets/fonts/bold-affa96571d-v2.woff +0 -0
  2. package/.public/assets/fonts/bold-b542beb274-v2.woff2 +0 -0
  3. package/.public/assets/fonts/light-94a07e06a1-v2.woff2 +0 -0
  4. package/.public/assets/fonts/light-f591b13f7d-v2.woff +0 -0
  5. package/.public/assets/images/favicon.ico +0 -0
  6. package/.public/assets/images/favicon.svg +1 -0
  7. package/.public/assets/images/govuk-crest.svg +1 -0
  8. package/.public/assets/images/govuk-icon-180.png +0 -0
  9. package/.public/assets/images/govuk-icon-192.png +0 -0
  10. package/.public/assets/images/govuk-icon-512.png +0 -0
  11. package/.public/assets/images/govuk-icon-mask.svg +1 -0
  12. package/.public/assets/images/govuk-opengraph-image.png +0 -0
  13. package/.public/assets/manifest.json +39 -0
  14. package/.public/assets-manifest.json +24 -0
  15. package/.public/javascripts/application.0fd8c18.min.js +3 -0
  16. package/.public/javascripts/application.0fd8c18.min.js.LICENSE.txt +58 -0
  17. package/.public/javascripts/application.0fd8c18.min.js.map +1 -0
  18. package/.public/javascripts/file-upload.b2f18f5.min.js +2 -0
  19. package/.public/javascripts/file-upload.b2f18f5.min.js.map +1 -0
  20. package/.public/javascripts/vendor/accessible-autocomplete.275d332.min.js +2 -0
  21. package/.public/javascripts/vendor/accessible-autocomplete.275d332.min.js.map +1 -0
  22. package/.public/stylesheets/application.e340021.min.css +14 -0
  23. package/.public/stylesheets/application.e340021.min.css.map +1 -0
  24. package/package.json +7 -2
  25. package/.browserslistrc +0 -16
  26. package/.editorconfig +0 -9
  27. package/.eslintrc.cjs +0 -266
  28. package/.github/dependabot.yml +0 -85
  29. package/.github/workflows/check-pull-request.yml +0 -209
  30. package/.github/workflows/pr-notifier.yml +0 -98
  31. package/.github/workflows/publish.yml +0 -111
  32. package/.husky/pre-commit +0 -1
  33. package/.lintstagedrc.js +0 -4
  34. package/.nvmrc +0 -1
  35. package/.prettierignore +0 -8
  36. package/.prettierrc.cjs +0 -26
  37. package/Dockerfile +0 -61
  38. package/Procfile +0 -1
  39. package/babel.config.cjs +0 -55
  40. package/compose/aws.env +0 -4
  41. package/compose/start-localstack.sh +0 -26
  42. package/docker-compose.yaml +0 -86
  43. package/globals.d.ts +0 -1
  44. package/jest.config.cjs +0 -54
  45. package/jest.environment.js +0 -4
  46. package/jest.setup.cjs +0 -14
  47. package/postcss.config.js +0 -26
  48. package/sonar-project.properties +0 -17
  49. package/stylelint.config.js +0 -10
  50. package/test/client/javascripts/file-upload.test.js +0 -1197
  51. package/test/condition/checkboxes.test.js +0 -112
  52. package/test/condition/radios.test.js +0 -112
  53. package/test/condition/text.test.js +0 -103
  54. package/test/fixtures/assets-manifest.json +0 -4
  55. package/test/fixtures/form.js +0 -86
  56. package/test/fixtures/index.js +0 -2
  57. package/test/fixtures/list.js +0 -92
  58. package/test/form/cookies.test.js +0 -338
  59. package/test/form/csrf.test.js +0 -87
  60. package/test/form/definitions/basic.js +0 -101
  61. package/test/form/definitions/blank.js +0 -10
  62. package/test/form/definitions/checkboxes.json +0 -88
  63. package/test/form/definitions/components.json +0 -452
  64. package/test/form/definitions/conditional-reveal.js +0 -140
  65. package/test/form/definitions/conditions-basic.js +0 -187
  66. package/test/form/definitions/conditions-complex.js +0 -338
  67. package/test/form/definitions/conditions-dates.js +0 -78
  68. package/test/form/definitions/conditions-escaping.js +0 -143
  69. package/test/form/definitions/demo-cph-number.js +0 -3099
  70. package/test/form/definitions/feedback.json +0 -45
  71. package/test/form/definitions/fields-optional.js +0 -402
  72. package/test/form/definitions/fields-required.js +0 -402
  73. package/test/form/definitions/file-upload-basic.js +0 -44
  74. package/test/form/definitions/file-upload.js +0 -66
  75. package/test/form/definitions/minimal.js +0 -39
  76. package/test/form/definitions/phase-alpha.json +0 -33
  77. package/test/form/definitions/phase-default.json +0 -26
  78. package/test/form/definitions/radios.json +0 -88
  79. package/test/form/definitions/repeat-mixed.js +0 -54
  80. package/test/form/definitions/repeat.js +0 -70
  81. package/test/form/definitions/status.json +0 -126
  82. package/test/form/definitions/templates.js +0 -183
  83. package/test/form/definitions/test.json +0 -581
  84. package/test/form/definitions/text.json +0 -75
  85. package/test/form/definitions/titles.json +0 -170
  86. package/test/form/definitions.test.js +0 -47
  87. package/test/form/exit-page.test.js +0 -210
  88. package/test/form/feedback.test.js +0 -68
  89. package/test/form/fields-optional.test.js +0 -237
  90. package/test/form/fields-required.test.js +0 -294
  91. package/test/form/file-upload.test.js +0 -313
  92. package/test/form/govuk-notify.test.js +0 -449
  93. package/test/form/journey-basic.test.js +0 -444
  94. package/test/form/persist-files.test.js +0 -227
  95. package/test/form/phase-banner.test.js +0 -71
  96. package/test/form/repeat.test.js +0 -628
  97. package/test/form/summary-submission-email.test.js +0 -95
  98. package/test/form/template.test.js +0 -288
  99. package/test/form/titles.test.js +0 -204
  100. package/test/helpers/component-helpers.js +0 -74
  101. package/test/utils/get-cookie.js +0 -42
  102. package/test/utils/get-form-definitions.js +0 -18
  103. package/tmp.pdf +0 -1
  104. package/tsconfig.json +0 -28
  105. package/webpack.config.js +0 -208
@@ -1,112 +0,0 @@
1
- import { resolve } from 'node:path'
2
-
3
- import { StatusCodes } from 'http-status-codes'
4
-
5
- import { createServer } from '~/src/server/index.js'
6
- import { getFormMetadata } from '~/src/server/plugins/engine/services/formsService.js'
7
- import * as fixtures from '~/test/fixtures/index.js'
8
- import { renderResponse } from '~/test/helpers/component-helpers.js'
9
-
10
- const basePath = '/checkboxes'
11
- const key = 'wqJmSf'
12
-
13
- jest.mock('~/src/server/plugins/engine/services/formsService.js')
14
-
15
- describe('Checkboxes based conditions', () => {
16
- /** @type {Server} */
17
- let server
18
-
19
- // Create server before each test
20
- beforeAll(async () => {
21
- server = await createServer({
22
- formFileName: 'checkboxes.json',
23
- formFilePath: resolve(import.meta.dirname, '../form/definitions')
24
- })
25
-
26
- await server.initialize()
27
- })
28
-
29
- beforeEach(() => {
30
- jest.mocked(getFormMetadata).mockResolvedValue(fixtures.form.metadata)
31
- })
32
-
33
- afterAll(async () => {
34
- await server.stop()
35
- })
36
-
37
- test('Checkboxes are rendered', async () => {
38
- const { container } = await renderResponse(server, {
39
- url: `${basePath}/first-page`
40
- })
41
-
42
- for (const example of [
43
- {
44
- name: key,
45
- id: key,
46
- text: 'Shire',
47
- value: 'shire'
48
- },
49
- {
50
- name: key,
51
- id: `${key}-2`,
52
- text: 'Race',
53
- value: 'race'
54
- },
55
- {
56
- name: key,
57
- id: `${key}-3`,
58
- text: 'Pantomime',
59
- value: 'pantomime'
60
- },
61
- {
62
- name: key,
63
- id: `${key}-4`,
64
- text: 'Other',
65
- value: 'other'
66
- }
67
- ]) {
68
- const $checkbox = container.getByRole('checkbox', {
69
- name: example.text
70
- })
71
-
72
- expect($checkbox).toBeInTheDocument()
73
- expect($checkbox).toHaveAttribute('id', example.id)
74
- expect($checkbox).toHaveAttribute('name', example.name)
75
- expect($checkbox).toHaveAttribute('value', example.value)
76
- expect($checkbox).toHaveClass('govuk-checkboxes__input')
77
- expect($checkbox).not.toBeChecked()
78
- }
79
- })
80
-
81
- test('Testing POST /first-page with nothing checked redirects correctly', async () => {
82
- const form = {}
83
-
84
- const res = await server.inject({
85
- url: `${basePath}/first-page`,
86
- method: 'POST',
87
- payload: form
88
- })
89
-
90
- expect(res.statusCode).toBe(StatusCodes.SEE_OTHER)
91
- expect(res.headers.location).toBe(`${basePath}/second-page`)
92
- })
93
-
94
- test('Testing POST /first-page with "other" checked redirects correctly', async () => {
95
- const form = {
96
- [key]: 'other'
97
- }
98
-
99
- const res = await server.inject({
100
- url: `${basePath}/first-page`,
101
- method: 'POST',
102
- payload: form
103
- })
104
-
105
- expect(res.statusCode).toBe(StatusCodes.SEE_OTHER)
106
- expect(res.headers.location).toBe(`${basePath}/third-page`)
107
- })
108
- })
109
-
110
- /**
111
- * @import { Server } from '@hapi/hapi'
112
- */
@@ -1,112 +0,0 @@
1
- import { resolve } from 'node:path'
2
-
3
- import { StatusCodes } from 'http-status-codes'
4
-
5
- import { createServer } from '~/src/server/index.js'
6
- import { getFormMetadata } from '~/src/server/plugins/engine/services/formsService.js'
7
- import * as fixtures from '~/test/fixtures/index.js'
8
- import { renderResponse } from '~/test/helpers/component-helpers.js'
9
-
10
- const basePath = '/radios'
11
- const key = 'wqJmSf'
12
-
13
- jest.mock('~/src/server/plugins/engine/services/formsService.js')
14
-
15
- describe('Radio based conditions', () => {
16
- /** @type {Server} */
17
- let server
18
-
19
- // Create server before each test
20
- beforeAll(async () => {
21
- server = await createServer({
22
- formFileName: 'radios.json',
23
- formFilePath: resolve(import.meta.dirname, '../form/definitions')
24
- })
25
-
26
- await server.initialize()
27
- })
28
-
29
- beforeEach(() => {
30
- jest.mocked(getFormMetadata).mockResolvedValue(fixtures.form.metadata)
31
- })
32
-
33
- afterAll(async () => {
34
- await server.stop()
35
- })
36
-
37
- test('Radio are rendered', async () => {
38
- const { container } = await renderResponse(server, {
39
- url: `${basePath}/first-page`
40
- })
41
-
42
- for (const example of [
43
- {
44
- name: key,
45
- id: key,
46
- text: 'Shire',
47
- value: 'shire'
48
- },
49
- {
50
- name: key,
51
- id: `${key}-2`,
52
- text: 'Race',
53
- value: 'race'
54
- },
55
- {
56
- name: key,
57
- id: `${key}-3`,
58
- text: 'Pantomime',
59
- value: 'pantomime'
60
- },
61
- {
62
- name: key,
63
- id: `${key}-4`,
64
- text: 'Other',
65
- value: 'other'
66
- }
67
- ]) {
68
- const $radio = container.getByRole('radio', {
69
- name: example.text
70
- })
71
-
72
- expect($radio).toBeInTheDocument()
73
- expect($radio).toHaveAttribute('id', example.id)
74
- expect($radio).toHaveAttribute('name', example.name)
75
- expect($radio).toHaveAttribute('value', example.value)
76
- expect($radio).toHaveClass('govuk-radios__input')
77
- expect($radio).not.toBeChecked()
78
- }
79
- })
80
-
81
- test('Testing POST /first-page with nothing checked redirects correctly', async () => {
82
- const form = {}
83
-
84
- const res = await server.inject({
85
- url: `${basePath}/first-page`,
86
- method: 'POST',
87
- payload: form
88
- })
89
-
90
- expect(res.statusCode).toBe(StatusCodes.SEE_OTHER)
91
- expect(res.headers.location).toBe(`${basePath}/second-page`)
92
- })
93
-
94
- test('Testing POST /first-page with "other" checked redirects correctly', async () => {
95
- const form = {
96
- [key]: 'other'
97
- }
98
-
99
- const res = await server.inject({
100
- url: `${basePath}/first-page`,
101
- method: 'POST',
102
- payload: form
103
- })
104
-
105
- expect(res.statusCode).toBe(StatusCodes.SEE_OTHER)
106
- expect(res.headers.location).toBe(`${basePath}/third-page`)
107
- })
108
- })
109
-
110
- /**
111
- * @import { Server } from '@hapi/hapi'
112
- */
@@ -1,103 +0,0 @@
1
- import { resolve } from 'node:path'
2
-
3
- import { StatusCodes } from 'http-status-codes'
4
-
5
- import { createServer } from '~/src/server/index.js'
6
- import { getFormMetadata } from '~/src/server/plugins/engine/services/formsService.js'
7
- import * as fixtures from '~/test/fixtures/index.js'
8
- import { renderResponse } from '~/test/helpers/component-helpers.js'
9
-
10
- const basePath = '/text'
11
- const key = 'wqJmSf'
12
-
13
- jest.mock('~/src/server/plugins/engine/services/formsService.js')
14
-
15
- describe('TextField based conditions', () => {
16
- /** @type {Server} */
17
- let server
18
-
19
- // Create server before each test
20
- beforeAll(async () => {
21
- server = await createServer({
22
- formFileName: 'text.json',
23
- formFilePath: resolve(import.meta.dirname, '../form/definitions')
24
- })
25
-
26
- await server.initialize()
27
- })
28
-
29
- beforeEach(() => {
30
- jest.mocked(getFormMetadata).mockResolvedValue(fixtures.form.metadata)
31
- })
32
-
33
- afterAll(async () => {
34
- await server.stop()
35
- })
36
-
37
- test('TextField is rendered', async () => {
38
- const { container } = await renderResponse(server, {
39
- url: `${basePath}/first-page`
40
- })
41
-
42
- const $input = container.getByRole('textbox', {
43
- name: 'First page (optional)'
44
- })
45
-
46
- const $warning = container.getByRole('link', {
47
- name: 'enter the email address (opens in new tab)'
48
- })
49
-
50
- expect($warning).toBeInTheDocument()
51
- expect($input).toBeInTheDocument()
52
- expect($input).toHaveAttribute('id', key)
53
- expect($input).toHaveAttribute('name', key)
54
- expect($input).toHaveClass('govuk-input')
55
- expect($input).not.toHaveValue()
56
- })
57
-
58
- test('Testing POST /first-page without values does not redirect', async () => {
59
- const form = {}
60
-
61
- const res = await server.inject({
62
- url: `${basePath}/first-page`,
63
- method: 'POST',
64
- payload: form
65
- })
66
-
67
- expect(res.statusCode).toBe(StatusCodes.OK)
68
- })
69
-
70
- test('Testing POST /first-page with an empty string redirects correctly', async () => {
71
- const form = {
72
- [key]: ''
73
- }
74
-
75
- const res = await server.inject({
76
- url: `${basePath}/first-page`,
77
- method: 'POST',
78
- payload: form
79
- })
80
-
81
- expect(res.statusCode).toBe(StatusCodes.SEE_OTHER)
82
- expect(res.headers.location).toBe(`${basePath}/second-page`)
83
- })
84
-
85
- test('Testing POST /first-page with an string "other" redirects correctly', async () => {
86
- const form = {
87
- [key]: 'other'
88
- }
89
-
90
- const res = await server.inject({
91
- url: `${basePath}/first-page`,
92
- method: 'POST',
93
- payload: form
94
- })
95
-
96
- expect(res.statusCode).toBe(StatusCodes.SEE_OTHER)
97
- expect(res.headers.location).toBe(`${basePath}/third-page`)
98
- })
99
- })
100
-
101
- /**
102
- * @import { Server } from '@hapi/hapi'
103
- */
@@ -1,4 +0,0 @@
1
- {
2
- "example.mjs": "javascripts/example.xxxxxxx.min.js",
3
- "example.scss": "stylesheets/example.xxxxxxx.min.css"
4
- }
@@ -1,86 +0,0 @@
1
- import {
2
- ComponentType,
3
- ControllerPath,
4
- ControllerType
5
- } from '@defra/forms-model'
6
-
7
- const now = new Date()
8
-
9
- /**
10
- * @satisfies {FormMetadataAuthor}
11
- */
12
- export const author = {
13
- id: 'J6PlucvwkmNlYxX9HnSEj27AcJAVx_08IvZ-IPNTvAN',
14
- displayName: 'Enrique Chase'
15
- }
16
-
17
- /**
18
- * @satisfies {FormMetadataState}
19
- */
20
- export const state = {
21
- createdAt: now,
22
- createdBy: author,
23
- updatedAt: now,
24
- updatedBy: author
25
- }
26
-
27
- /**
28
- * @satisfies {FormMetadata}
29
- */
30
- export const metadata = {
31
- id: '661e4ca5039739ef2902b214',
32
- slug: 'test-form',
33
- title: 'Test form',
34
- organisation: 'Defra',
35
- teamName: 'Defra Forms',
36
- teamEmail: 'defraforms@defra.gov.uk',
37
- createdAt: now,
38
- createdBy: author,
39
- updatedAt: now,
40
- updatedBy: author
41
- }
42
-
43
- /**
44
- * @satisfies {FormDefinition}
45
- */
46
- export const definition = {
47
- name: '',
48
- startPage: '/page-one',
49
- pages: [
50
- {
51
- path: '/page-one',
52
- title: 'Page one',
53
- section: 'section',
54
- components: [
55
- {
56
- type: ComponentType.TextField,
57
- name: 'textField',
58
- title: 'This is your first field',
59
- hint: 'Help text',
60
- options: {},
61
- schema: {}
62
- }
63
- ],
64
- next: [{ path: ControllerPath.Summary }]
65
- },
66
- {
67
- title: 'Summary',
68
- path: ControllerPath.Summary,
69
- controller: ControllerType.Summary
70
- }
71
- ],
72
- sections: [
73
- {
74
- name: 'section',
75
- title: 'Section title',
76
- hideTitle: false
77
- }
78
- ],
79
- conditions: [],
80
- lists: [],
81
- outputEmail: 'enrique.chase@defra.gov.uk'
82
- }
83
-
84
- /**
85
- * @import { FormDefinition, FormMetadata, FormMetadataAuthor, FormMetadataState } from '@defra/forms-model'
86
- */
@@ -1,2 +0,0 @@
1
- export * as form from '~/test/fixtures/form.js'
2
- export * as list from '~/test/fixtures/list.js'
@@ -1,92 +0,0 @@
1
- /**
2
- * @satisfies {List}
3
- */
4
- export const listNumber = {
5
- title: 'Example number list',
6
- name: 'listNumber',
7
- type: 'number',
8
- items: [
9
- { text: '1 point', value: 1 },
10
- { text: '2 points', value: 2 },
11
- { text: '3 points', value: 3 },
12
- { text: '4 points', value: 4 }
13
- ]
14
- }
15
-
16
- export const listNumberExamples = [
17
- {
18
- text: '1 point',
19
- value: 1,
20
- state: 1
21
- },
22
- {
23
- text: '2 points',
24
- value: 2,
25
- state: 2
26
- },
27
- {
28
- text: '3 points',
29
- value: 3,
30
- state: 3
31
- },
32
- {
33
- text: '4 points',
34
- value: 4,
35
- state: 4
36
- }
37
- ]
38
-
39
- /**
40
- * @satisfies {List}
41
- */
42
- export const listString = {
43
- title: 'Example string list',
44
- name: 'listString',
45
- type: 'string',
46
- items: [
47
- { text: '1 hour', value: '1' },
48
- { text: '2 hours', value: '2' },
49
- { text: '3 hours', value: '3' },
50
- { text: '4 hours', value: '4' }
51
- ]
52
- }
53
-
54
- export const listStringExamples = [
55
- {
56
- text: '1 hour',
57
- value: '1',
58
- state: '1'
59
- },
60
- {
61
- text: '2 hours',
62
- value: '2',
63
- state: '2'
64
- },
65
- {
66
- text: '3 hours',
67
- value: '3',
68
- state: '3'
69
- },
70
- {
71
- text: '4 hours',
72
- value: '4',
73
- state: '4'
74
- }
75
- ]
76
-
77
- export const listYesNoExamples = [
78
- {
79
- text: 'Yes',
80
- value: true,
81
- state: true
82
- },
83
- {
84
- text: 'No',
85
- value: false,
86
- state: false
87
- }
88
- ]
89
-
90
- /**
91
- * @import { List } from '@defra/forms-model'
92
- */