From 3644bb07a553ea6dfa38395e997a92540914e8a9 Mon Sep 17 00:00:00 2001 From: Vanita Barrett Date: Wed, 7 Oct 2020 16:24:49 +0100 Subject: [PATCH 01/13] Update back-link text and html to not required The back-link text defaults to "Back". You can provide just a `href` to the component and it will render correctly. Therefore, mark `text` and `html` as not required. --- src/govuk/components/back-link/back-link.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/govuk/components/back-link/back-link.yaml b/src/govuk/components/back-link/back-link.yaml index 70dafefdf7..9f681d2c67 100644 --- a/src/govuk/components/back-link/back-link.yaml +++ b/src/govuk/components/back-link/back-link.yaml @@ -1,12 +1,12 @@ params: - name: text type: string - required: true - description: If `html` is set, this is not required. Text to use within the back link component. If `html` is provided, the `text` argument will be ignored. + required: false + description: Text to use within the back link component. If `html` is provided, the `text` argument will be ignored. Defaults to "Back". - name: html type: string - required: true - description: If `text` is set, this is not required. HTML to use within the back link component. If `html` is provided, the `text` argument will be ignored. + required: false + description: HTML to use within the back link component. If `html` is provided, the `text` argument will be ignored. Defaults to "Back". - name: href type: string required: true From 758eb8dca47060461d28a5db6dda708f2cc3fee6 Mon Sep 17 00:00:00 2001 From: Vanita Barrett Date: Wed, 7 Oct 2020 16:27:11 +0100 Subject: [PATCH 02/13] Mark character count threshold as not required The character count threshold triggers the count message to be hidden by default. If not set, the count message is visible all the time. Therefore, mark the count threshold as not required. --- src/govuk/components/character-count/character-count.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/govuk/components/character-count/character-count.yaml b/src/govuk/components/character-count/character-count.yaml index 2ad2f00f21..6e473841b6 100644 --- a/src/govuk/components/character-count/character-count.yaml +++ b/src/govuk/components/character-count/character-count.yaml @@ -25,7 +25,7 @@ params: description: If `maxlength` is set, this is not required. The maximum number of words. If `maxwords` is provided, the `maxlength` argument will be ignored. - name: threshold type: string - required: true + required: false description: The percentage value of the limit at which point the count message is displayed. If this attribute is set, the count message will be hidden by default. - name: label type: object From f3749152150a3390c9f5fb0e23bfb72b43ee83dd Mon Sep 17 00:00:00 2001 From: Vanita Barrett Date: Wed, 7 Oct 2020 16:31:20 +0100 Subject: [PATCH 03/13] Mark checkbox item.name as not required If checkbox item.name is not set, then the component global nameis used instead. Therefore, mark the checkbox item.name as not required. --- src/govuk/components/checkboxes/checkboxes.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/govuk/components/checkboxes/checkboxes.yaml b/src/govuk/components/checkboxes/checkboxes.yaml index fbf943ff39..11da28adb9 100644 --- a/src/govuk/components/checkboxes/checkboxes.yaml +++ b/src/govuk/components/checkboxes/checkboxes.yaml @@ -54,7 +54,7 @@ params: description: Specific id attribute for the checkbox item. If omitted, then idPrefix option will be applied. - name: name type: string - required: true + required: false description: Specific name for the checkbox item. If omitted, then component global `name` string will be applied. - name: value type: string From 606d41b3a585ee3372e388097bca241cf849f2cc Mon Sep 17 00:00:00 2001 From: Vanita Barrett Date: Wed, 7 Oct 2020 16:32:35 +0100 Subject: [PATCH 04/13] Clarify idPrefix description Match the description for the `item.name` option - when ommitted, the global option is applied instead --- src/govuk/components/checkboxes/checkboxes.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/govuk/components/checkboxes/checkboxes.yaml b/src/govuk/components/checkboxes/checkboxes.yaml index 11da28adb9..3f7e859b09 100644 --- a/src/govuk/components/checkboxes/checkboxes.yaml +++ b/src/govuk/components/checkboxes/checkboxes.yaml @@ -51,7 +51,7 @@ params: - name: id type: string required: false - description: Specific id attribute for the checkbox item. If omitted, then idPrefix option will be applied. + description: Specific id attribute for the checkbox item. If omitted, then component global `idPrefix` option will be applied. - name: name type: string required: false From d653076cbc5640c4609c3af61bf66f052682c932 Mon Sep 17 00:00:00 2001 From: Vanita Barrett Date: Wed, 7 Oct 2020 16:33:43 +0100 Subject: [PATCH 05/13] Mark date input label as not required If the date input label is not provided, the name is used instead. Therefore, mark the label as not required. --- src/govuk/components/date-input/date-input.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/govuk/components/date-input/date-input.yaml b/src/govuk/components/date-input/date-input.yaml index 03f01d546b..303d76cbc5 100644 --- a/src/govuk/components/date-input/date-input.yaml +++ b/src/govuk/components/date-input/date-input.yaml @@ -22,7 +22,7 @@ params: description: Item-specific name attribute. - name: label type: string - required: true + required: false description: Item-specific label text. If provided, this will be used instead of `name` for item label text. - name: value type: string From d77fc46eab7070245a808a361e21cd037799a850 Mon Sep 17 00:00:00 2001 From: Vanita Barrett Date: Wed, 7 Oct 2020 16:34:30 +0100 Subject: [PATCH 06/13] Add missing required attribute to error message option The visuallyHiddenText option was missing the required option. It has a default value of "Error" so is not required, but let's make that clear and keep things consistent. --- src/govuk/components/error-message/error-message.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/govuk/components/error-message/error-message.yaml b/src/govuk/components/error-message/error-message.yaml index 0482990794..4ab3a077af 100644 --- a/src/govuk/components/error-message/error-message.yaml +++ b/src/govuk/components/error-message/error-message.yaml @@ -21,6 +21,7 @@ params: description: HTML attributes (for example data attributes) to add to the error message span tag - name: visuallyHiddenText type: string + required: false description: A visually hidden prefix used before the error message. Defaults to "Error". accessibilityCriteria: | From f59dd22d5bd49b285389658c461aafcfd4315df4 Mon Sep 17 00:00:00 2001 From: Vanita Barrett Date: Wed, 7 Oct 2020 16:36:44 +0100 Subject: [PATCH 07/13] Add missing required attributes to footer meta option --- src/govuk/components/footer/footer.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/govuk/components/footer/footer.yaml b/src/govuk/components/footer/footer.yaml index a600816a44..06093a6b96 100644 --- a/src/govuk/components/footer/footer.yaml +++ b/src/govuk/components/footer/footer.yaml @@ -6,12 +6,15 @@ params: params: - name: visuallyHiddenTitle type: string + required: false description: Title for a meta item section, which defaults to Support links - name: html type: string + required: false description: HTML to add to the meta section of the footer, which will appear below any links specified using meta.items. - name: text type: string + required: false description: Text to add to the meta section of the footer, which will appear below any links specified using meta.items. If meta.html is specified, this option is ignored. - name: items type: array From 4a834cc68245aee2f7070e04b5cd35f865780544 Mon Sep 17 00:00:00 2001 From: Vanita Barrett Date: Wed, 7 Oct 2020 16:38:01 +0100 Subject: [PATCH 08/13] Mark footer navigation.title as required The footer navigation title does not have a default. If navigation is provided, but the title attribute is missed, you end up with an empty heading tag. Therefore, mark the title as required. --- src/govuk/components/footer/footer.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/govuk/components/footer/footer.yaml b/src/govuk/components/footer/footer.yaml index 06093a6b96..5ec1b1ac85 100644 --- a/src/govuk/components/footer/footer.yaml +++ b/src/govuk/components/footer/footer.yaml @@ -40,7 +40,7 @@ params: params: - name: title type: string - required: false + required: true description: Title for a section - name: columns type: integer From c39cb0c7808e143601556aabc291452a2e7f0f55 Mon Sep 17 00:00:00 2001 From: Vanita Barrett Date: Wed, 7 Oct 2020 16:40:10 +0100 Subject: [PATCH 09/13] Make use of `idPrefix` instead of `id` clearer Make it clearer that if items.id is not set, then `idPrefix` is required instead. --- src/govuk/components/tabs/tabs.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/govuk/components/tabs/tabs.yaml b/src/govuk/components/tabs/tabs.yaml index ed0651d3b6..430fb97cec 100644 --- a/src/govuk/components/tabs/tabs.yaml +++ b/src/govuk/components/tabs/tabs.yaml @@ -19,7 +19,7 @@ params: - name: id type: string required: true - description: Specific id attribute for the tab item. If omitted, then `idPrefix` string will be applied. + description: Specific id attribute for the tab item. If omitted, then `idPrefix` string is required instead. - name: label type: string required: true From d3f09829bb225ef5ea909bc566ca02cd79c72557 Mon Sep 17 00:00:00 2001 From: Vanita Barrett Date: Thu, 8 Oct 2020 11:05:11 +0100 Subject: [PATCH 10/13] Mark header navigation.text and navigation.html as required It is possible to pass navigation items without a `href` - you might want to do this if you're showing the current page. However, passing a navigation item without one of `text` or `html` results in no text or link rendering at all. Following the pattern we use for other components, we should mark `navigation.text` and `navigation.html` as required and use the description to explain that one overrides the other. The description already explains the relationship between the two. Therefore, we should mark the navigation.text and navigation.html as required. --- src/govuk/components/header/header.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/govuk/components/header/header.yaml b/src/govuk/components/header/header.yaml index c2088c17d5..ed2fbe161b 100644 --- a/src/govuk/components/header/header.yaml +++ b/src/govuk/components/header/header.yaml @@ -26,11 +26,11 @@ params: params: - name: text type: string - required: false + required: true description: Text for the navigation item. If `html` is provided, the `text` argument will be ignored. - name: html type: string - required: false + required: true description: HTML for the navigation item. If `html` is provided, the `text` argument will be ignored. - name: href type: string From 8d94c44a80137dabaa0f0b564dc063cfdf67c6d5 Mon Sep 17 00:00:00 2001 From: Vanita Barrett Date: Thu, 8 Oct 2020 11:39:47 +0100 Subject: [PATCH 11/13] Mark navigation.text and navigation.href as required Both `text` and `href` attributes need to be present to create a link. A navigation item with no href or text does not render - you end up with an empty
    element. We also instruct users that a navigation.title is required, so you also end up with a heading with an empty list underneath. Therefore, mark navigation.items.text and navigation.items.href as required --- src/govuk/components/footer/footer.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/govuk/components/footer/footer.yaml b/src/govuk/components/footer/footer.yaml index 5ec1b1ac85..d16f02a00f 100644 --- a/src/govuk/components/footer/footer.yaml +++ b/src/govuk/components/footer/footer.yaml @@ -53,11 +53,11 @@ params: params: - name: text type: string - required: false + required: true description: List item text in the navigation section of the footer. - name: href type: string - required: false + required: true description: List item href attribute in the navigation section of the footer. Both `text` and `href` attributes need to be present to create a link. - name: attributes type: object From 5eb6eb58d655c5a58eb9296bb6474ce9cf61e881 Mon Sep 17 00:00:00 2001 From: Vanita Barrett Date: Thu, 8 Oct 2020 11:48:16 +0100 Subject: [PATCH 12/13] Mark footer meta.items.text and meta.items.href as required Passing a href by itsef results in an invisible link (no visible text). Passing text by itself results in a link with no href. Therefore, mark the footer meta.items.text and meta.items.href as required. --- src/govuk/components/footer/footer.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/govuk/components/footer/footer.yaml b/src/govuk/components/footer/footer.yaml index d16f02a00f..173ccb4ba7 100644 --- a/src/govuk/components/footer/footer.yaml +++ b/src/govuk/components/footer/footer.yaml @@ -23,11 +23,11 @@ params: params: - name: text type: string - required: false + required: true description: List item text in the meta section of the footer. - name: href type: string - required: false + required: true description: List item href attribute in the meta section of the footer. - name: attributes type: object From d52f62ff1a3a37e017c62e6f1ee019503e243c18 Mon Sep 17 00:00:00 2001 From: Vanita Barrett Date: Thu, 8 Oct 2020 14:15:23 +0100 Subject: [PATCH 13/13] Change after-build-package tests to look at all objects The way the previous tests were structured seemed to test for the presence of at least one single object within the component options with the required attributes, instead of all options having the correct attributes. The same was happening for the fixtures file. This meant that one missing `required` attribute in a component yaml file would not cause the test to fail. This commit tests for the presence of the required attributes by looping through each option/fixture. It also fixes one typo picked up by these new tests. --- src/govuk/components/input/input.yaml | 2 +- .../__tests__/after-build-package.test.js | 28 +++++++++++-------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/govuk/components/input/input.yaml b/src/govuk/components/input/input.yaml index 9daffe5478..6f0b6c36fd 100644 --- a/src/govuk/components/input/input.yaml +++ b/src/govuk/components/input/input.yaml @@ -13,7 +13,7 @@ params: description: Type of input control to render. Defaults to "text". - name: inputmode type: string - require: false + required: false description: Optional value for [inputmode](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/inputmode). - name: value type: string diff --git a/tasks/gulp/__tests__/after-build-package.test.js b/tasks/gulp/__tests__/after-build-package.test.js index 6df70afbc3..1d4b98694e 100644 --- a/tasks/gulp/__tests__/after-build-package.test.js +++ b/tasks/gulp/__tests__/after-build-package.test.js @@ -107,17 +107,19 @@ describe('package/', () => { return readFile(filePath, 'utf8') .then((data) => { var parsedData = JSON.parse(data) + // We expect the component JSON to contain "name", "type", "required", "description" - expect(parsedData).toEqual( - expect.arrayContaining([ + expect(parsedData).toBeInstanceOf(Array) + parsedData.forEach((option) => { + expect(option).toEqual( expect.objectContaining({ name: expect.any(String), type: expect.any(String), required: expect.any(Boolean), description: expect.any(String) }) - ]) - ) + ) + }) }) .catch(error => { throw error @@ -135,15 +137,19 @@ describe('package/', () => { expect(parsedData).toEqual( expect.objectContaining({ component: name, - fixtures: expect.arrayContaining([ - expect.objectContaining({ - name: expect.any(String), - options: expect.any(Object), - html: expect.any(String) - }) - ]) + fixtures: expect.any(Object) }) ) + + parsedData.fixtures.forEach((fixture) => { + expect(fixture).toEqual( + expect.objectContaining({ + name: expect.any(String), + options: expect.any(Object), + html: expect.any(String) + }) + ) + }) }) .catch(error => { throw error