diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000000..bf61aef403 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1 @@ +* @ONSdigital/design-team-devs diff --git a/__snapshots__/layout/_template.spec.js.snap b/__snapshots__/layout/_template.spec.js.snap index 62e0c6dbc0..bc80c256e6 100644 --- a/__snapshots__/layout/_template.spec.js.snap +++ b/__snapshots__/layout/_template.spec.js.snap @@ -234,28 +234,30 @@ exports[`base page template matches the favicons block override snapshot 1`] = ` -
-
-
-
- - + +
+
+
+
- -
Social survey
+ + + +
Social survey
+ + +
+
- - -
-
+ @@ -473,28 +475,30 @@ exports[`base page template matches the footer block override snapshot 1`] = `
-
-
-
-
- - + +
+
+
+
- -
Social survey
+ + + +
Social survey
+ + +
+
- - -
-
+ @@ -882,29 +886,30 @@ exports[`base page template matches the full configuration snapshot 1`] = `
-
-
-
-
- - + +
+
+ - - -
+ +
+ @@ -936,14 +941,14 @@ exports[`base page template matches the full configuration snapshot 1`] = ` -
- - -
- - +
+ + +
+ + @@ -975,12 +980,13 @@ exports[`base page template matches the full configuration snapshot 1`] = ` - -
- + +
+ +
-
+ @@ -1393,10 +1399,6 @@ exports[`base page template matches the full configuration snapshot 1`] = ` - - - - @@ -1405,7 +1407,12 @@ exports[`base page template matches the full configuration snapshot 1`] = ` -
  • + + + + + +
  • @@ -1416,10 +1423,14 @@ exports[`base page template matches the full configuration snapshot 1`] = `
  • - -
  • + + + + + +
  • @@ -1430,10 +1441,14 @@ exports[`base page template matches the full configuration snapshot 1`] = `
  • - -
  • + + + + + +
  • @@ -1441,8 +1456,7 @@ exports[`base page template matches the full configuration snapshot 1`] = ` Respondent Charter -
  • - +
    @@ -1462,10 +1476,6 @@ exports[`base page template matches the full configuration snapshot 1`] = ` - - - - @@ -1474,7 +1484,12 @@ exports[`base page template matches the full configuration snapshot 1`] = ` -
  • + + + + + +
  • @@ -1485,10 +1500,14 @@ exports[`base page template matches the full configuration snapshot 1`] = `
  • - -
  • + + + + + +
  • @@ -1499,10 +1518,14 @@ exports[`base page template matches the full configuration snapshot 1`] = `
  • - -
  • + + + + + +
  • @@ -1510,8 +1533,7 @@ exports[`base page template matches the full configuration snapshot 1`] = ` Contact us -
  • - +
    @@ -1531,10 +1553,6 @@ exports[`base page template matches the full configuration snapshot 1`] = ` - - - - @@ -1543,7 +1561,12 @@ exports[`base page template matches the full configuration snapshot 1`] = ` -
  • + + + + + +
  • @@ -1561,10 +1584,14 @@ exports[`base page template matches the full configuration snapshot 1`] = `
  • - -
  • + + + + + +
  • @@ -1575,10 +1602,14 @@ exports[`base page template matches the full configuration snapshot 1`] = `
  • - -
  • + + + + + +
  • @@ -1586,8 +1617,7 @@ exports[`base page template matches the full configuration snapshot 1`] = ` News -
  • - +
    @@ -1616,10 +1646,6 @@ exports[`base page template matches the full configuration snapshot 1`] = ` - - - - @@ -1628,7 +1654,12 @@ exports[`base page template matches the full configuration snapshot 1`] = ` -
  • + + + + + +
  • @@ -1639,10 +1670,14 @@ exports[`base page template matches the full configuration snapshot 1`] = `
  • - -
  • + + + + + +
  • @@ -1653,10 +1688,14 @@ exports[`base page template matches the full configuration snapshot 1`] = `
  • - -
  • + + + + + +
  • @@ -1667,10 +1706,14 @@ exports[`base page template matches the full configuration snapshot 1`] = `
  • - -
  • + + + + + +
  • @@ -1678,8 +1721,7 @@ exports[`base page template matches the full configuration snapshot 1`] = ` Terms and conditions -
  • - + @@ -1961,28 +2003,30 @@ exports[`base page template matches the meta block override snapshot 1`] = `
    -
    -
    -
    -
    - - + +
    +
    +
    +
    - -
    Social survey
    + + + +
    Social survey
    + + +
    +
    - - -
    -
    + @@ -2184,28 +2228,30 @@ exports[`base page template matches the social block override snapshot 1`] = `
    -
    -
    -
    -
    - - + +
    +
    +
    +
    - -
    Social survey
    + + + +
    Social survey
    + + +
    +
    - - -
    -
    + diff --git a/backstop_data/bitmaps_reference/ds-vr-test__components_button_example-button-group_0_document_0_desktop.png b/backstop_data/bitmaps_reference/ds-vr-test__components_button_example-button-group_0_document_0_desktop.png index 073c5bd7a8..2680887f75 100644 --- a/backstop_data/bitmaps_reference/ds-vr-test__components_button_example-button-group_0_document_0_desktop.png +++ b/backstop_data/bitmaps_reference/ds-vr-test__components_button_example-button-group_0_document_0_desktop.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:67ea8eb0705c1d803762190b653c450e6c614f17bcb56d1b09d4d25ebacfba30 -size 14186 +oid sha256:7f96539c3e58c205968c560c3f1115ffccea5a285bd0c12ff198b822908fa3b5 +size 14187 diff --git a/backstop_data/bitmaps_reference/ds-vr-test__components_button_example-button-group_0_document_1_tablet.png b/backstop_data/bitmaps_reference/ds-vr-test__components_button_example-button-group_0_document_1_tablet.png index f4896a3df2..771aff4891 100644 --- a/backstop_data/bitmaps_reference/ds-vr-test__components_button_example-button-group_0_document_1_tablet.png +++ b/backstop_data/bitmaps_reference/ds-vr-test__components_button_example-button-group_0_document_1_tablet.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:d8b152b09273c19d7e02ca4bb69189e153d248711ba8e66a02e4d38561da4482 -size 9032 +oid sha256:9057e9b897ea1d8504f8d5594e12a826280bc4c88311d30e09fb9f27906a5a2d +size 9022 diff --git a/backstop_data/bitmaps_reference/ds-vr-test__components_button_example-button-group_0_document_2_mobile.png b/backstop_data/bitmaps_reference/ds-vr-test__components_button_example-button-group_0_document_2_mobile.png index aba1f68d63..f1956d8e85 100644 --- a/backstop_data/bitmaps_reference/ds-vr-test__components_button_example-button-group_0_document_2_mobile.png +++ b/backstop_data/bitmaps_reference/ds-vr-test__components_button_example-button-group_0_document_2_mobile.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:53b21b44f05cf83164c6e491b2aa15377683c556eb542b1c263bfda355bf8e7d -size 6033 +oid sha256:02ca0247ddf43b925cfad05c59d4566589e376e57df09a23e3c89a0e6ad24b23 +size 6032 diff --git a/backstop_data/bitmaps_reference/ds-vr-test__components_description-list_example-inline-description-list_0_document_0_desktop.png b/backstop_data/bitmaps_reference/ds-vr-test__components_description-list_example-inline-description-list_0_document_0_desktop.png index 0a08429eb9..501054bf24 100644 --- a/backstop_data/bitmaps_reference/ds-vr-test__components_description-list_example-inline-description-list_0_document_0_desktop.png +++ b/backstop_data/bitmaps_reference/ds-vr-test__components_description-list_example-inline-description-list_0_document_0_desktop.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:10b3fac1f117b5156eed79c8e8acd67c758bcf750706a405f707127224f296e5 -size 29101 +oid sha256:5e7e64f58cd1df264462b40d72a23456e35e8d3b36079d8d6163380da5669200 +size 29211 diff --git a/backstop_data/bitmaps_reference/ds-vr-test__components_description-list_example-inline-description-list_0_document_1_tablet.png b/backstop_data/bitmaps_reference/ds-vr-test__components_description-list_example-inline-description-list_0_document_1_tablet.png index 094d8bb803..787d83b991 100644 --- a/backstop_data/bitmaps_reference/ds-vr-test__components_description-list_example-inline-description-list_0_document_1_tablet.png +++ b/backstop_data/bitmaps_reference/ds-vr-test__components_description-list_example-inline-description-list_0_document_1_tablet.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:f86583c3c214887dfe5a160e4f9e89827597713760b91ed7bef9650d6830abb3 -size 26901 +oid sha256:2f3ce338fc733ae77a2874dca95f1f3496ca0660ce7d0f9ff1ebec76caa226f8 +size 27025 diff --git a/backstop_data/bitmaps_reference/ds-vr-test__components_description-list_example-inline-description-list_0_document_2_mobile.png b/backstop_data/bitmaps_reference/ds-vr-test__components_description-list_example-inline-description-list_0_document_2_mobile.png index f5141703a9..46fe8f06e5 100644 --- a/backstop_data/bitmaps_reference/ds-vr-test__components_description-list_example-inline-description-list_0_document_2_mobile.png +++ b/backstop_data/bitmaps_reference/ds-vr-test__components_description-list_example-inline-description-list_0_document_2_mobile.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:24353f18540d373c96f4de57c56514d2dfc1c2d792c92436bff1ae9e0fd55e35 -size 23850 +oid sha256:916702efd8bc81c6e9b58f8ff13e097c11f95d564f09a88cbf6a58f7d284e6ba +size 23969 diff --git a/backstop_data/bitmaps_reference/ds-vr-test__components_header_example-header-basic_0_document_0_desktop.png b/backstop_data/bitmaps_reference/ds-vr-test__components_header_example-header-basic_0_document_0_desktop.png new file mode 100644 index 0000000000..84b7f01461 --- /dev/null +++ b/backstop_data/bitmaps_reference/ds-vr-test__components_header_example-header-basic_0_document_0_desktop.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:03c53a0bcd6fe29cd4c9fe59227cc4f2612f00f0a08eb0c2a53d7334c241fcd6 +size 14266 diff --git a/backstop_data/bitmaps_reference/ds-vr-test__components_header_example-header-basic_0_document_1_tablet.png b/backstop_data/bitmaps_reference/ds-vr-test__components_header_example-header-basic_0_document_1_tablet.png new file mode 100644 index 0000000000..f34345bbff --- /dev/null +++ b/backstop_data/bitmaps_reference/ds-vr-test__components_header_example-header-basic_0_document_1_tablet.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:65f329afc04fde5ff5f541b2712b183accab1446bd76d6944042949de4413fab +size 9069 diff --git a/backstop_data/bitmaps_reference/ds-vr-test__components_header_example-header-basic_0_document_2_mobile.png b/backstop_data/bitmaps_reference/ds-vr-test__components_header_example-header-basic_0_document_2_mobile.png new file mode 100644 index 0000000000..75468ba73d --- /dev/null +++ b/backstop_data/bitmaps_reference/ds-vr-test__components_header_example-header-basic_0_document_2_mobile.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fb39535ce7f5f1affd77107ef3155d32b4197e7b0805065b221d379d05f9e88f +size 5422 diff --git a/backstop_data/bitmaps_reference/ds-vr-test__components_hero_example-hero-grey_0_document_0_desktop.png b/backstop_data/bitmaps_reference/ds-vr-test__components_hero_example-hero-grey_0_document_0_desktop.png new file mode 100644 index 0000000000..fed0fc64cd --- /dev/null +++ b/backstop_data/bitmaps_reference/ds-vr-test__components_hero_example-hero-grey_0_document_0_desktop.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d1281c7b5cc116410f9add67692e230581ce5b8e4976d2ac8e20c46cd59e020f +size 79351 diff --git a/backstop_data/bitmaps_reference/ds-vr-test__components_hero_example-hero-grey_0_document_1_tablet.png b/backstop_data/bitmaps_reference/ds-vr-test__components_hero_example-hero-grey_0_document_1_tablet.png new file mode 100644 index 0000000000..ca759aecbd --- /dev/null +++ b/backstop_data/bitmaps_reference/ds-vr-test__components_hero_example-hero-grey_0_document_1_tablet.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e3bce5cf21914ebf9ba6b4a848c59cccc1ca209882f446603737f4fad82b01f6 +size 77032 diff --git a/backstop_data/bitmaps_reference/ds-vr-test__components_hero_example-hero-grey_0_document_2_mobile.png b/backstop_data/bitmaps_reference/ds-vr-test__components_hero_example-hero-grey_0_document_2_mobile.png new file mode 100644 index 0000000000..c2ec970118 --- /dev/null +++ b/backstop_data/bitmaps_reference/ds-vr-test__components_hero_example-hero-grey_0_document_2_mobile.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8b5618c2c948e45ae4abd65f46b65afd0bb4a6ba49b4d13544528ef2a524a684 +size 72186 diff --git a/src/components/address-input/_macro.spec.js b/src/components/address-input/_macro.spec.js index 5377705ad3..44ab507366 100644 --- a/src/components/address-input/_macro.spec.js +++ b/src/components/address-input/_macro.spec.js @@ -83,7 +83,6 @@ describe('FOR: Macro: Address-input', () => { ariaYouHaveSelected: '[params.ariaYouHaveSelected]', ariaMinChars: '[params.ariaMinChars]', minChars: '[params.minChars]', - ariaResultsLabel: '[params.ariaResultsLabel]', ariaOneResult: '[params.ariaOneResult]', ariaNResults: '[params.ariaNResults]', ariaLimitedResults: '[params.ariaLimitedResults]', diff --git a/src/components/address-input/autosuggest.address.spec.js b/src/components/address-input/autosuggest.address.spec.js index 42f8e0c9d6..3d2103277d 100644 --- a/src/components/address-input/autosuggest.address.spec.js +++ b/src/components/address-input/autosuggest.address.spec.js @@ -15,7 +15,6 @@ const EXAMPLE_ADDRESS_INPUT = { ariaYouHaveSelected: 'You have selected', ariaMinChars: 'Enter 3 or more characters for suggestions.', minChars: 3, - ariaResultsLabel: 'Country suggestions', ariaOneResult: 'There is one suggestion available.', ariaNResults: 'There are {n} suggestions available.', ariaLimitedResults: 'Type more characters to improve your search', diff --git a/src/components/autosuggest/autosuggest.spec.js b/src/components/autosuggest/autosuggest.spec.js index b7525f6eb0..97a0ddf025 100644 --- a/src/components/autosuggest/autosuggest.spec.js +++ b/src/components/autosuggest/autosuggest.spec.js @@ -16,7 +16,6 @@ const EXAMPLE_AUTOSUGGEST = { ariaYouHaveSelected: 'You have selected', ariaMinChars: 'Enter 3 or more characters for suggestions.', minChars: 3, - ariaResultsLabel: 'Country suggestions', ariaOneResult: 'There is one suggestion available.', ariaNResults: 'There are {n} suggestions available.', ariaLimitedResults: 'Type more characters to improve your search', @@ -40,7 +39,6 @@ const EXAMPLE_AUTOSUGGEST_WITH_LANGUAGE = { ariaYouHaveSelected: 'You have selected', ariaMinChars: 'Enter 3 or more characters for suggestions.', minChars: 3, - ariaResultsLabel: 'Country suggestions', ariaOneResult: 'There is one suggestion available.', ariaNResults: 'There are {n} suggestions available.', ariaLimitedResults: 'Type more characters to improve your search', diff --git a/src/components/button/_button.scss b/src/components/button/_button.scss index 076ff11f76..12addc8838 100644 --- a/src/components/button/_button.scss +++ b/src/components/button/_button.scss @@ -569,6 +569,6 @@ $button-shadow-size: 3px; .ons-btn, a { - margin: 0 1rem 1rem 0; + margin: 0 1.5rem 1rem 0; } } diff --git a/src/components/char-check-limit/_macro.spec.js b/src/components/char-check-limit/_macro.spec.js index 6eba91e262..210d568830 100644 --- a/src/components/char-check-limit/_macro.spec.js +++ b/src/components/char-check-limit/_macro.spec.js @@ -5,65 +5,57 @@ import * as cheerio from 'cheerio'; import axe from '../../tests/helpers/axe'; import { renderComponent } from '../../tests/helpers/rendering'; -const EXAMPLE_CHAR_CHECK_LIMIT = { - id: 'example-char-check-limit', - charCountSingular: 'You have {x} character remaining', - charCountPlural: 'You have {x} characters remaining', - charCountOverLimitSingular: '{x} character too many', - charCountOverLimitPlural: '{x} characters too many', -}; - -describe('macro: char-check-limit', () => { - it('passes jest-axe checks without check', async () => { - const $ = cheerio.load(renderComponent('char-check-limit', EXAMPLE_CHAR_CHECK_LIMIT)); - - const results = await axe($.html()); - expect(results).toHaveNoViolations(); - }); - - it('passes jest-axe checks with check', async () => { - const $ = cheerio.load( - renderComponent( - 'char-check-limit', - { - ...EXAMPLE_CHAR_CHECK_LIMIT, - variant: 'check', - }, - ['

    Test content.

    '], - ), - ); - - const results = await axe($.html()); - expect(results).toHaveNoViolations(); - }); - - it('has the provided `id` attribute', () => { - const $ = cheerio.load(renderComponent('char-check-limit', EXAMPLE_CHAR_CHECK_LIMIT)); - - expect($('.ons-input__limit').attr('id')).toBe('example-char-check-limit'); - }); - - it('has the provided data attributes', () => { - const $ = cheerio.load(renderComponent('char-check-limit', EXAMPLE_CHAR_CHECK_LIMIT)); - - expect($('.ons-input__limit').attr('data-charcount-singular')).toBe('You have {x} character remaining'); - expect($('.ons-input__limit').attr('data-charcount-plural')).toBe('You have {x} characters remaining'); - expect($('.ons-input__limit').attr('data-charcount-limit-singular')).toBe('{x} character too many'); - expect($('.ons-input__limit').attr('data-charcount-limit-plural')).toBe('{x} characters too many'); +import { EXAMPLE_CHAR_CHECK_LIMIT } from './_test-examples'; + +describe('FOR: Macro: CharCheckLimit', () => { + describe('GIVEN: Params: Required', () => { + describe('WHEN: required params are provided', () => { + const $ = cheerio.load(renderComponent('char-check-limit', EXAMPLE_CHAR_CHECK_LIMIT)); + + test('THEN: passes jest-axe checks', async () => { + const results = await axe($.html()); + + expect(results).toHaveNoViolations(); + }); + test('THEN: has the provided id attribute', () => { + expect($('.ons-input__limit').attr('id')).toBe('example-char-check-limit'); + }); + test('THEN: has the data attribute which defines charCountPlural', () => { + expect($('.ons-input__limit').attr('data-charcount-plural')).toBe('You have {x} characters remaining'); + }); + test('THEN: has the data attribute which defines charCountSingular', () => { + expect($('.ons-input__limit').attr('data-charcount-singular')).toBe('You have {x} character remaining'); + }); + test('THEN: has the data attribute which defines charCountOverLimitSingular', () => { + expect($('.ons-input__limit').attr('data-charcount-limit-singular')).toBe('{x} character too many'); + }); + test('THEN: has the data attribute which defines charCountOverLimitPlural', () => { + expect($('.ons-input__limit').attr('data-charcount-limit-plural')).toBe('{x} characters too many'); + }); + }); }); - it('has expected nested content', () => { - const $ = cheerio.load( - renderComponent( - 'char-check-limit', - { - ...EXAMPLE_CHAR_CHECK_LIMIT, - variant: 'check', - }, - ['

    Test content.

    '], - ), - ); - - expect($('.ons-js-char-check-input').html().trim()).toBe('

    Test content.

    '); + describe('GIVEN: Params: variant', () => { + describe('WHEN: variant is provided', () => { + const $ = cheerio.load( + renderComponent( + 'char-check-limit', + { + ...EXAMPLE_CHAR_CHECK_LIMIT, + variant: 'check', + }, + ['

    Test content.

    '], + ), + ); + + test('THEN: passes jest-axe checks with variant set to check', async () => { + const results = await axe($.html()); + expect(results).toHaveNoViolations(); + }); + + test('THEN: renders the passed content', () => { + expect($('.ons-js-char-check-input').text()).toBe('Test content.'); + }); + }); }); }); diff --git a/src/components/char-check-limit/_test-examples.js b/src/components/char-check-limit/_test-examples.js new file mode 100644 index 0000000000..6a700b1cbb --- /dev/null +++ b/src/components/char-check-limit/_test-examples.js @@ -0,0 +1,7 @@ +export const EXAMPLE_CHAR_CHECK_LIMIT = { + id: 'example-char-check-limit', + charCountSingular: 'You have {x} character remaining', + charCountPlural: 'You have {x} characters remaining', + charCountOverLimitSingular: '{x} character too many', + charCountOverLimitPlural: '{x} characters too many', +}; diff --git a/src/components/description-list/_macro-options.md b/src/components/description-list/_macro-options.md index 324f027775..3a64f09971 100644 --- a/src/components/description-list/_macro-options.md +++ b/src/components/description-list/_macro-options.md @@ -21,3 +21,4 @@ | ----------- | ------ | -------- | ----------------------------------------------------- | | id | string | false | The HTML `id` for the description of the related term | | description | string | true | The value of the description of the related term | +| url | string | false | The url of the description of the related term | diff --git a/src/components/description-list/_macro.njk b/src/components/description-list/_macro.njk index 329491b2c9..92e9890a1f 100644 --- a/src/components/description-list/_macro.njk +++ b/src/components/description-list/_macro.njk @@ -21,7 +21,13 @@ {% if descriptionItem.id %}id="{{ descriptionItem.id }}"{% endif %} class="ons-description-list__value ons-grid__col ons-col-{{ params.descriptionCol }}@{{ 'xs@l' if params.variant == 'inline' else 'm' }}" > - {{- descriptionItem.description -}} + {%- if descriptionItem.url -%} + + {{- descriptionItem.description -}} + + {%- else -%} + {{- descriptionItem.description -}} + {%- endif -%} {% endif %} {% endfor %} diff --git a/src/components/description-list/_macro.spec.js b/src/components/description-list/_macro.spec.js index fa45111ceb..508a51cd6d 100644 --- a/src/components/description-list/_macro.spec.js +++ b/src/components/description-list/_macro.spec.js @@ -30,6 +30,7 @@ const EXAMPLE_DESCRIPTION_LIST_FULL = { { id: 'description-3', description: '49300005832', + url: '#', }, ], }, @@ -142,7 +143,9 @@ describe('macro: description-list', () => { expect($listElements[4].tagName).toBe('dd'); expect($($listElements[4]).attr('id')).toBe('description-3'); - expect($($listElements[4]).text()).toBe('49300005832'); + const $link = $($listElements[4]).find('a'); + expect($link.attr('href')).toBe('#'); + expect($link.text()).toBe('49300005832'); }); it.each([ diff --git a/src/components/description-list/example-inline-description-list.njk b/src/components/description-list/example-inline-description-list.njk index e7114ffd1e..a43605286c 100644 --- a/src/components/description-list/example-inline-description-list.njk +++ b/src/components/description-list/example-inline-description-list.njk @@ -49,7 +49,8 @@ "description": "Jacky Turner" }, { - "description": "Louise Goodland" + "description": "Louise Goodland", + 'url': '#' } ] } diff --git a/src/components/document-list/_macro.spec.js b/src/components/document-list/_macro.spec.js index 1af96d5c57..a345201bdc 100644 --- a/src/components/document-list/_macro.spec.js +++ b/src/components/document-list/_macro.spec.js @@ -4,381 +4,371 @@ import * as cheerio from 'cheerio'; import axe from '../../tests/helpers/axe'; import { renderComponent } from '../../tests/helpers/rendering'; - -const EXAMPLE_DOCUMENT_LIST_BASIC = { - title: { - text: 'Crime and justice', - url: '#0', - }, - description: 'Some description', -}; - -const EXAMPLE_DOCUMENT_LIST_WITH_THUMBNAIL = { - ...EXAMPLE_DOCUMENT_LIST_BASIC, - thumbnail: { - smallSrc: '/example-small.png', - largeSrc: '/example-large.png', - }, -}; - -const EXAMPLE_DOCUMENT_LIST_WITH_METADATA_FILE = { - ...EXAMPLE_DOCUMENT_LIST_BASIC, - metadata: { - file: { - fileType: 'PDF', - fileSize: '499KB', - filePages: '1 page', - }, - }, -}; - -const EXAMPLE_DOCUMENT_LIST_WITH_METADATA_OBJECT = { - ...EXAMPLE_DOCUMENT_LIST_BASIC, - metadata: { - object: { - text: 'Poster', - url: '#0', - ref: 'some ref', - }, - }, -}; - -const EXAMPLE_DOCUMENT_LIST_WITH_MULTIPLE = { - ...EXAMPLE_DOCUMENT_LIST_BASIC, - id: 'some-id', - thumbnail: { - smallSrc: '/example-small.png', - largeSrc: '/example-large.png', - }, - metadata: { - object: { - text: 'Poster', - url: '#0', - ref: 'some ref', - }, - file: { - fileType: 'PDF', - fileSize: '499KB', - filePages: '1 page', - }, - date: { - iso: '2022-01-01', - short: '1 January 2022', - showPrefix: true, - prefix: 'Released', - }, - }, -}; - -describe('macro: document list', () => { - describe('global configuration', () => { - it('passes jest-axe checks', async () => { +import { + EXAMPLE_DOCUMENT_LIST_BASIC, + EXAMPLE_DOCUMENT_LIST_WITH_THUMBNAIL, + EXAMPLE_DOCUMENT_LIST_WITH_METADATA_FILE, + EXAMPLE_DOCUMENT_LIST_WITH_METADATA_OBJECT, + EXAMPLE_DOCUMENT_LIST_WITH_METADATA_DATE, + EXAMPLE_DOCUMENT_LIST_WITH_MULTIPLE, +} from './_test-examples'; + +describe('FOR: Macro: Document list', () => { + describe('GIVEN: Params: required', () => { + describe('WHEN: required parameters are provided within a document', () => { const $ = cheerio.load( renderComponent('document-list', { - id: 'some-id', documents: [EXAMPLE_DOCUMENT_LIST_BASIC, EXAMPLE_DOCUMENT_LIST_BASIC, EXAMPLE_DOCUMENT_LIST_BASIC], }), ); - - const results = await axe($.html()); - expect(results).toHaveNoViolations(); + test('THEN: passes jest-axe checks', async () => { + const results = await axe($.html()); + expect(results).toHaveNoViolations(); + }); + + test('THEN: renders the same number of documents items as the number passed in', () => { + expect($('.ons-document-list__item').length).toBe(3); + }); + test('THEN: has expected url for the title', () => { + expect($('.ons-document-list__item-title a').attr('href')).toBe('#0'); + }); }); + }); - it('has the provided `id` attribute', () => { - const $ = cheerio.load( - renderComponent('document-list', { - id: 'some-id', - documents: [EXAMPLE_DOCUMENT_LIST_BASIC, EXAMPLE_DOCUMENT_LIST_BASIC, EXAMPLE_DOCUMENT_LIST_BASIC], - }), - ); - - expect($('#some-id').length).toBe(1); + describe('GIVEN: Params: description', () => { + describe('WHEN: description is provided', () => { + test('THEN: has expected description', () => { + const $ = cheerio.load(renderComponent('document-list', { documents: [EXAMPLE_DOCUMENT_LIST_BASIC] })); + const title = $('.ons-document-list__item-description').html().trim(); + expect(title).toBe('Some description'); + }); }); + }); - it('has custom classes applied', () => { - const $ = cheerio.load( - renderComponent('document-list', { - classes: 'custom-class', - documents: [EXAMPLE_DOCUMENT_LIST_BASIC, EXAMPLE_DOCUMENT_LIST_BASIC, EXAMPLE_DOCUMENT_LIST_BASIC], - }), - ); - - expect($('.ons-document-list').hasClass('custom-class')).toBe(true); + describe('GIVEN: Params: id', () => { + describe('WHEN: id is provided', () => { + test('THEN: has the provided id attribute', () => { + const $ = cheerio.load( + renderComponent('document-list', { + id: 'some-id', + documents: [EXAMPLE_DOCUMENT_LIST_BASIC, EXAMPLE_DOCUMENT_LIST_BASIC, EXAMPLE_DOCUMENT_LIST_BASIC], + }), + ); + expect($('#some-id').length).toBe(1); + }); }); + }); - it('outputs the correct number of document items', () => { - const $ = cheerio.load( - renderComponent('document-list', { - documents: [EXAMPLE_DOCUMENT_LIST_BASIC, EXAMPLE_DOCUMENT_LIST_BASIC, EXAMPLE_DOCUMENT_LIST_BASIC], - }), - ); + describe('GIVEN: Params: classes', () => { + describe('WHEN: additional style classes are provided', () => { + test('THEN: renders with additional classes provided', () => { + const $ = cheerio.load( + renderComponent('document-list', { + classes: 'custom-class', + documents: [EXAMPLE_DOCUMENT_LIST_BASIC, EXAMPLE_DOCUMENT_LIST_BASIC, EXAMPLE_DOCUMENT_LIST_BASIC], + }), + ); + expect($('.ons-document-list').hasClass('custom-class')).toBe(true); + }); + }); + describe('WHEN: addtional style classes are provided within document', () => { + test('THEN: renders with additional classes provided', () => { + const $ = cheerio.load( + renderComponent('document-list', { + documents: [{ ...EXAMPLE_DOCUMENT_LIST_BASIC, classes: 'custom-class' }], + }), + ); + expect($('.ons-document-list__item').hasClass('custom-class')).toBe(true); + }); + }); + }); + describe('GIVEN: Params: attributes', () => { + describe('WHEN: attributes are provided', () => { + test('THEN: renders with provided HTML attributes', () => { + const $ = cheerio.load( + renderComponent('document-list', { + documents: [EXAMPLE_DOCUMENT_LIST_BASIC], + attributes: { + a: 123, + b: 456, + }, + }), + ); + expect($('.ons-document-list').attr('a')).toBe('123'); + expect($('.ons-document-list').attr('b')).toBe('456'); + }); + }); + describe('WHEN: attributes are provided within document', () => { + test('THEN: renders with provided HTML attributes', () => { + const $ = cheerio.load( + renderComponent('document-list', { + documents: [ + { + ...EXAMPLE_DOCUMENT_LIST_BASIC, + attributes: { + a: 123, + b: 456, + }, + }, + ], + }), + ); + expect($('.ons-document-list__item').attr('a')).toBe('123'); + expect($('.ons-document-list__item').attr('b')).toBe('456'); + }); + }); + }); - expect($('.ons-document-list__item').length).toBe(3); + describe('GIVEN: Params: headingLevel', () => { + describe('WHEN: headingLevel is provided', () => { + test('THEN: the heading tag is set to the level provided', () => { + const $ = cheerio.load( + renderComponent('document-list', { + headingLevel: 1, + documents: [EXAMPLE_DOCUMENT_LIST_BASIC], + }), + ); + const headingLevel = $('.ons-document-list__item-title')[0].tagName; + expect(headingLevel).toBe('h1'); + }); }); + }); - it('has the correct container if `fullWidth`', () => { - const $ = cheerio.load( - renderComponent('document-list', { - documents: [{ ...EXAMPLE_DOCUMENT_LIST_BASIC, featured: true, fullWidth: true }], - }), - ); + describe('GIVEN: Params: featured', () => { + describe('WHEN: featured is set for a document', () => { + test('THEN: applies the featured class to the document item', () => { + const $ = cheerio.load( + renderComponent('document-list', { + documents: [{ ...EXAMPLE_DOCUMENT_LIST_BASIC, featured: true }], + }), + ); - expect($('.ons-container').length).toBe(1); + expect($('.ons-document-list__item--featured').length).toBe(1); + }); }); + }); - it('has the correct container class if `fullWidth` and `wide`', () => { - const $ = cheerio.load( - renderComponent('document-list', { - documents: [{ ...EXAMPLE_DOCUMENT_LIST_BASIC, featured: true, fullWidth: true, wide: true }], - }), - ); + describe('GIVEN: Params: fullWidth', () => { + describe('WHEN: fullWidth is set for a document', () => { + test('THEN: document item does not have the container class', () => { + const $ = cheerio.load( + renderComponent('document-list', { + documents: [{ ...EXAMPLE_DOCUMENT_LIST_BASIC, fullWidth: true }], + }), + ); - expect($('.ons-container--wide').length).toBe(1); + expect($('.ons-document-list__item > .ons-container').length).toBe(0); + }); }); - it('has the correct container class if `featured`', () => { + describe('WHEN: fullWidth is set for a featured document', () => { const $ = cheerio.load( renderComponent('document-list', { - documents: [{ ...EXAMPLE_DOCUMENT_LIST_BASIC, featured: true }], + documents: [{ ...EXAMPLE_DOCUMENT_LIST_BASIC, featured: true, fullWidth: true }], }), ); + test('THEN: applies full width class to document item', () => { + expect($('.ons-document-list__item--full-width').length).toBe(1); + }); - expect($('.ons-document-list__item--featured').length).toBe(1); + test('THEN: document item has the container class', () => { + expect($('.ons-document-list__item > .ons-container').length).toBe(1); + }); }); + }); - it('has the correct class for `showMetadataFirst`', () => { - const $ = cheerio.load( - renderComponent('document-list', { - documents: [{ ...EXAMPLE_DOCUMENT_LIST_BASIC, showMetadataFirst: true }], - }), - ); + describe('GIVEN: Params: wide', () => { + describe('WHEN: wide is set for a document', () => { + test('THEN: does not render with the wide container class', () => { + const $ = cheerio.load( + renderComponent('document-list', { + documents: [{ ...EXAMPLE_DOCUMENT_LIST_BASIC, wide: true }], + }), + ); - expect($('.ons-document-list__item-header--reverse').length).toBe(1); + expect($('.ons-container--wide').length).toBe(0); + }); }); - - it('overrides the heading title tag when `headingLevel` is provided', () => { + describe('WHEN: wide is set for a featured document with fullWidth', () => { const $ = cheerio.load( renderComponent('document-list', { - headingLevel: 1, - documents: [EXAMPLE_DOCUMENT_LIST_BASIC], + documents: [{ ...EXAMPLE_DOCUMENT_LIST_BASIC, featured: true, fullWidth: true, wide: true }], }), ); - const headingLevel = $('.ons-document-list__item-title')[0].tagName; - expect(headingLevel).toBe('h1'); - }); - - it('has expected `title`', () => { - const $ = cheerio.load(renderComponent('document-list', { documents: [EXAMPLE_DOCUMENT_LIST_BASIC] })); - const title = $('.ons-document-list__item-title a').html().trim(); - expect(title).toBe('Crime and justice'); - }); + test('THEN: applies the wide class to the container', () => { + expect($('.ons-container').hasClass('ons-container--wide')).toBe(true); + }); - it('has expected `url` for the title', () => { - const $ = cheerio.load(renderComponent('document-list', { documents: [EXAMPLE_DOCUMENT_LIST_BASIC] })); - expect($('.ons-document-list__item-title a').attr('href')).toBe('#0'); + test('THEN: document item has container--wide class', () => { + expect($('.ons-document-list__item > .ons-container--wide').length).toBe(1); + }); }); + }); - it('has expected `description`', () => { - const $ = cheerio.load(renderComponent('document-list', { documents: [EXAMPLE_DOCUMENT_LIST_BASIC] })); - const title = $('.ons-document-list__item-description').html().trim(); - expect(title).toBe('Some description'); + describe('GIVEN: Params: showMetadataFirst', () => { + describe('WHEN: showMetadataFirst is set for a document', () => { + test('THEN: applies the reverse class to document header to display the metadata before the title', () => { + const $ = cheerio.load( + renderComponent('document-list', { + documents: [{ ...EXAMPLE_DOCUMENT_LIST_BASIC, showMetadataFirst: true }], + }), + ); + expect($('.ons-document-list__item-header--reverse').length).toBe(1); + }); }); }); - describe('mode: with thumbnail', () => { - it('passes jest-axe checks', async () => { + describe('GIVEN: Params: thumbnail', () => { + describe('WHEN: thumbnail is provided for a document', () => { const $ = cheerio.load( renderComponent('document-list', { - id: 'some-id', documents: [EXAMPLE_DOCUMENT_LIST_WITH_THUMBNAIL], }), ); - const results = await axe($.html()); - expect(results).toHaveNoViolations(); - }); - - it('has expected `srcset` attribute', () => { - const $ = cheerio.load(renderComponent('document-list', { documents: [EXAMPLE_DOCUMENT_LIST_WITH_THUMBNAIL] })); - - const srcset = $('.ons-document-list__image-link img').attr('srcset'); - expect(srcset).toBe('/example-small.png 1x, /example-large.png 2x'); - }); + test('THEN: passes jest-axe checks', async () => { + const results = await axe($.html()); + expect(results).toHaveNoViolations(); + }); - it('has expected `src` attribute', () => { - const $ = cheerio.load(renderComponent('document-list', { documents: [EXAMPLE_DOCUMENT_LIST_WITH_THUMBNAIL] })); + test('THEN: has expected srcset attribute', () => { + const srcset = $('.ons-document-list__image-link img').attr('srcset'); + expect(srcset).toBe('/example-small.png 1x, /example-large.png 2x'); + }); - const src = $('.ons-document-list__image-link img').attr('src'); - expect(src).toBe('/example-small.png'); + test('THEN: has expected src attribute', () => { + const src = $('.ons-document-list__image-link img').attr('src'); + expect(src).toBe('/example-small.png'); + }); }); - it('has the placeholder class if `thumbnail` is true', () => { - const $ = cheerio.load( - renderComponent('document-list', { - documents: [{ ...EXAMPLE_DOCUMENT_LIST_BASIC, thumbnail: true }], - }), - ); - - expect($('.ons-document-list__image-link').hasClass('ons-document-list__image-link--placeholder')).toBe(true); + describe('WHEN: thumbnail is not provided but is set to true', () => { + test('THEN: has a placeholder class', () => { + const $ = cheerio.load( + renderComponent('document-list', { + documents: [{ ...EXAMPLE_DOCUMENT_LIST_BASIC, thumbnail: true }], + }), + ); + expect($('.ons-document-list__image-link').hasClass('ons-document-list__image-link--placeholder')).toBe(true); + }); }); }); - describe('mode: with metadata `file` configuration', () => { - it('passes jest-axe checks', async () => { - const $ = cheerio.load( - renderComponent('document-list', { - documents: [EXAMPLE_DOCUMENT_LIST_WITH_METADATA_FILE], - }), - ); - - const results = await axe($.html()); - expect(results).toHaveNoViolations(); - }); - - it('has visually hidden `file` information after the title', () => { + describe('GIVEN: Params: file', () => { + describe('WHEN: file configuration is provided within a document metadata', () => { const $ = cheerio.load( renderComponent('document-list', { documents: [EXAMPLE_DOCUMENT_LIST_WITH_METADATA_FILE], }), ); - const hiddenText = $('.ons-document-list__item-title a .ons-u-vh').text().trim(); - expect(hiddenText).toBe(', PDF document download, 499KB, 1 page'); - }); + test('THEN: passes jest-axe checks', async () => { + const results = await axe($.html()); + expect(results).toHaveNoViolations(); + }); - it('has `file` information displayed', () => { - const $ = cheerio.load( - renderComponent('document-list', { - documents: [EXAMPLE_DOCUMENT_LIST_WITH_METADATA_FILE], - }), - ); + test('THEN: has visually hidden file information after the title', () => { + const hiddenText = $('.ons-document-list__item-title a .ons-u-vh').text().trim(); + expect(hiddenText).toBe(', PDF document download, 499KB, 1 page'); + }); - const hiddenText = $('.ons-document-list__item-attribute').text().trim(); - expect(hiddenText).toBe('PDF, 499KB, 1 page'); + test('THEN: has file information', () => { + const fileInfo = $('.ons-document-list__item-attribute').text().trim(); + expect(fileInfo).toBe('PDF, 499KB, 1 page'); + }); }); }); - describe('mode: with metadata `object` configuration', () => { - it('passes jest-axe checks', async () => { + describe('GIVEN: Params: object', () => { + describe('WHEN: object configuration is provided within a document metadata', () => { const $ = cheerio.load( renderComponent('document-list', { documents: [EXAMPLE_DOCUMENT_LIST_WITH_METADATA_OBJECT], }), ); - const results = await axe($.html()); - expect(results).toHaveNoViolations(); - }); - - it('has the provided `url`', () => { - const $ = cheerio.load( - renderComponent('document-list', { - documents: [EXAMPLE_DOCUMENT_LIST_WITH_METADATA_OBJECT], - }), - ); + test('THEN: passes jest-axe checks', async () => { + const results = await axe($.html()); + expect(results).toHaveNoViolations(); + }); - const url = $('.ons-document-list__attribute-link').attr('href'); - expect(url).toBe('#0'); - }); + test('THEN: has the provided url', () => { + const url = $('.ons-document-list__attribute-link').attr('href'); + expect(url).toBe('#0'); + }); - it('has expected `text`', () => { - const $ = cheerio.load(renderComponent('document-list', { documents: [EXAMPLE_DOCUMENT_LIST_WITH_METADATA_OBJECT] })); - const text = $('.ons-document-list__attribute-link > span').text().trim(); - expect(text).toBe('Poster:'); - }); + test('THEN: has expected text', () => { + const text = $('.ons-document-list__attribute-link > span').text().trim(); + expect(text).toBe('Poster:'); + }); - it('has expected `ref`', () => { - const $ = cheerio.load(renderComponent('document-list', { documents: [EXAMPLE_DOCUMENT_LIST_WITH_METADATA_OBJECT] })); - const text = $('.ons-document-list__attribute-link + span').text().trim(); - expect(text).toBe('some ref'); + test('THEN: has expected ref', () => { + const text = $('.ons-document-list__attribute-link + span').text().trim(); + expect(text).toBe('some ref'); + }); }); }); - describe('mode: with metadata `date` configuration', () => { - it('passes jest-axe checks', async () => { + describe('GIVEN: Params: date', () => { + describe('WHEN: date configuration is provided within a document metadata', () => { const $ = cheerio.load( renderComponent('document-list', { - documents: [ - { - ...EXAMPLE_DOCUMENT_LIST_BASIC, - metadata: { - date: { - iso: '2022-01-01', - short: '1 January 2022', - }, - }, - }, - ], + documents: [EXAMPLE_DOCUMENT_LIST_WITH_METADATA_DATE], }), ); - const results = await axe($.html()); - expect(results).toHaveNoViolations(); - }); + test('THEN: passes jest-axe checks', async () => { + const results = await axe($.html()); + expect(results).toHaveNoViolations(); + }); - it('has the default `prefix` text', () => { - const $ = cheerio.load( - renderComponent('document-list', { - documents: [ - { - ...EXAMPLE_DOCUMENT_LIST_BASIC, - metadata: { - date: { - iso: '2022-01-01', - short: '1 January 2022', - }, - }, - }, - ], - }), - ); + test('THEN: has the default prefix text', () => { + const text = $('.ons-document-list__item-attribute > span').text().trim(); + expect(text).toBe('Published:'); + }); - const text = $('.ons-document-list__item-attribute > span').text().trim(); - expect(text).toBe('Published:'); - }); + test('THEN: has the visually hidden class for prefix text', () => { + expect($('.ons-document-list__item-attribute > span').hasClass('ons-u-vh')).toBe(true); + }); - it('has the visually hidden class for `prefix` text', () => { - const $ = cheerio.load( - renderComponent('document-list', { - documents: [ - { - ...EXAMPLE_DOCUMENT_LIST_BASIC, - metadata: { - date: { - iso: '2022-01-01', - short: '1 January 2022', - }, - }, - }, - ], - }), - ); - expect($('.ons-document-list__item-attribute > span').hasClass('ons-u-vh')).toBe(true); + test('THEN: has the correct datetime attribute value', () => { + expect($('time').attr('datetime')).toBe('2022-01-01'); + }); + + test('THEN: has the correct time value', () => { + const time = $('.ons-document-list__item-attribute time').text().trim(); + expect(time).toBe('1 January 2022'); + }); }); + }); - it('has the provided `prefix` text', () => { - const $ = cheerio.load( - renderComponent('document-list', { - documents: [ - { - ...EXAMPLE_DOCUMENT_LIST_BASIC, - metadata: { - date: { - prefix: 'Released', - iso: '2022-01-01', - short: '1 January 2022', + describe('GIVEN: Params: prefix', () => { + describe('WHEN: prefix is provided in the date metadata configuration for a document', () => { + test('THEN: has the provided prefix text', () => { + const $ = cheerio.load( + renderComponent('document-list', { + documents: [ + { + ...EXAMPLE_DOCUMENT_LIST_BASIC, + metadata: { + date: { + prefix: 'Released', + iso: '2022-01-01', + short: '1 January 2022', + }, }, }, - }, - ], - }), - ); - - const text = $('.ons-document-list__item-attribute > span').text().trim(); - expect(text).toBe('Released:'); + ], + }), + ); + const text = $('.ons-document-list__item-attribute > span').text().trim(); + expect(text).toBe('Released:'); + }); }); + }); - it('has the correct class for `showPrefix`', () => { + describe('GIVEN: Params: showprefix', () => { + describe('WHEN: showprefix is set in the date metadata configuration for a document', () => { const $ = cheerio.load( renderComponent('document-list', { documents: [ @@ -396,80 +386,41 @@ describe('macro: document list', () => { }), ); - expect($('.ons-document-list__item-attribute > span').hasClass('ons-u-fw-b')).toBe(true); - }); - - it('has the correct datetime attribute value', () => { - const $ = cheerio.load( - renderComponent('document-list', { - documents: [ - { - ...EXAMPLE_DOCUMENT_LIST_BASIC, - metadata: { - date: { - iso: '2022-01-01', - short: '1 January 2022', - }, - }, - }, - ], - }), - ); - expect($('time').attr('datetime')).toBe('2022-01-01'); - }); + test('THEN: applies bold font class to the prefix text', () => { + expect($('.ons-document-list__item-attribute > span').hasClass('ons-u-fw-b')).toBe(true); + }); - it('has the correct `time` value', () => { - const $ = cheerio.load( - renderComponent('document-list', { - documents: [ - { - ...EXAMPLE_DOCUMENT_LIST_BASIC, - metadata: { - date: { - iso: '2022-01-01', - short: '1 January 2022', - }, - }, - }, - ], - }), - ); + test('THEN: does not has the visually hidden class for prefix text', () => { + expect($('.ons-document-list__item-attribute > span').hasClass('ons-u-vh')).toBe(false); + }); - const time = $('.ons-document-list__item-attribute time').text().trim(); - expect(time).toBe('1 January 2022'); + test('THEN: has the default prefix text', () => { + const text = $('.ons-document-list__item-attribute > span').text().trim(); + expect(text).toBe('Published:'); + }); }); }); - describe('mode: with all parameters', () => { - it('passes jest-axe checks', async () => { - const $ = cheerio.load( - renderComponent('document-list', { - documents: [EXAMPLE_DOCUMENT_LIST_WITH_MULTIPLE], - }), - ); - - const results = await axe($.html()); - expect(results).toHaveNoViolations(); - }); - - it('has the correct document thumbnail class', async () => { + describe('GIVEN: Params: metadata', () => { + describe('WHEN: when document has metadata with all available configurations', () => { const $ = cheerio.load( renderComponent('document-list', { documents: [EXAMPLE_DOCUMENT_LIST_WITH_MULTIPLE], }), ); - expect($('.ons-document-list__item-image').hasClass('ons-document-list__item-image--file')).toBe(true); - }); + test('THEN: passes jest-axe checks', async () => { + const results = await axe($.html()); + expect(results).toHaveNoViolations(); + }); - it('has the correct document list class', async () => { - const $ = cheerio.load( - renderComponent('document-list', { - documents: [EXAMPLE_DOCUMENT_LIST_WITH_MULTIPLE], - }), - ); + test('THEN: has the correct document thumbnail class', async () => { + expect($('.ons-document-list__item-image').hasClass('ons-document-list__item-image--file')).toBe(true); + }); - expect($('.ons-document-list__item-attribute').hasClass('ons-u-mr-no')).toBe(true); + test('THEN: the document list object item has the utility class that removes the margin between the object and file list items', async () => { + expect($('.ons-document-list__item-attribute').hasClass('ons-u-mr-no')).toBe(true); + }); }); }); }); diff --git a/src/components/document-list/_test-examples.js b/src/components/document-list/_test-examples.js new file mode 100644 index 0000000000..b559d24731 --- /dev/null +++ b/src/components/document-list/_test-examples.js @@ -0,0 +1,74 @@ +export const EXAMPLE_DOCUMENT_LIST_BASIC = { + title: { + text: 'Crime and justice', + url: '#0', + }, + description: 'Some description', +}; + +export const EXAMPLE_DOCUMENT_LIST_WITH_THUMBNAIL = { + ...EXAMPLE_DOCUMENT_LIST_BASIC, + thumbnail: { + smallSrc: '/example-small.png', + largeSrc: '/example-large.png', + }, +}; + +export const EXAMPLE_DOCUMENT_LIST_WITH_METADATA_FILE = { + ...EXAMPLE_DOCUMENT_LIST_BASIC, + metadata: { + file: { + fileType: 'PDF', + fileSize: '499KB', + filePages: '1 page', + }, + }, +}; + +export const EXAMPLE_DOCUMENT_LIST_WITH_METADATA_OBJECT = { + ...EXAMPLE_DOCUMENT_LIST_BASIC, + metadata: { + object: { + text: 'Poster', + url: '#0', + ref: 'some ref', + }, + }, +}; + +export const EXAMPLE_DOCUMENT_LIST_WITH_METADATA_DATE = { + ...EXAMPLE_DOCUMENT_LIST_BASIC, + metadata: { + date: { + iso: '2022-01-01', + short: '1 January 2022', + }, + }, +}; + +export const EXAMPLE_DOCUMENT_LIST_WITH_MULTIPLE = { + ...EXAMPLE_DOCUMENT_LIST_BASIC, + id: 'some-id', + thumbnail: { + smallSrc: '/example-small.png', + largeSrc: '/example-large.png', + }, + metadata: { + object: { + text: 'Poster', + url: '#0', + ref: 'some ref', + }, + file: { + fileType: 'PDF', + fileSize: '499KB', + filePages: '1 page', + }, + date: { + iso: '2022-01-01', + short: '1 January 2022', + showPrefix: true, + prefix: 'Released', + }, + }, +}; diff --git a/src/components/header/_macro-options.md b/src/components/header/_macro-options.md index 76837cfafd..b1cf9c4c18 100644 --- a/src/components/header/_macro-options.md +++ b/src/components/header/_macro-options.md @@ -1,22 +1,22 @@ -| Name | Type | Required | Description | -| --------------------- | ------------------------------------------------- | -------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- | -| phase | `PhaseBanner` [_(ref)_](/components/phase-banner) | false | Settings to set the Phase banner component within the HTML `
    ` element | -| wide | boolean | false | Set to “true” to increase the maximum width of the layout container to 1280px | -| fullWidth | boolean | false | Set to “true” to increase the maximum width of the layout container to the full width of the viewport | -| classes | string | false | Classes to add to the wrapping `header` | -| variants | array or string | false | An array of values or single value (string) to adjust the component using available variants: “internal”, "neutral" and “description” | -| mastheadLogoUrl | string | false | Wraps the masthead logo in a link. Set the URL for the HTML `href` attribute for the link. | -| mastheadLogo | object`` | false | Settings for a [custom organisation logo](#mastheadlogo) in the masthead. Defaults to the ONS logo. | -| language | object`` | false | Settings for the [language selector](#language) | -| serviceLinks | object`` | false | Settings for the [service links](#servicelinks) in the masthead | -| title | string | true (unless `titleLogo` is set) | The title for the service | -| description | string | false | Tagline or description for the service | -| titleAsH1 | boolean | false | Override to wrap the header `title` in an `

    ` heading | -| titleLogo | object`` | false | Settings for a [custom title logo](#titlelogo) in the header. | -| titleUrl | string | false | Wraps the title logo in a link. Set the URL for the HTML `href` attribute for the link. | -| button | object`` | false | Settings for the [sign out button](#signoutbutton) in the header used to exit a transactional service | -| navigation | array`` | false | Settings for the [main menu links](#navigation) | -| siteSearchAutosuggest | `Autosuggest` [_(ref)_](/components/autosuggest) | false | Sets the autosuggest functionality in the header | +| Name | Type | Required | Description | +| --------------------- | ------------------------------------------------- | -------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- | +| phase | `PhaseBanner` [_(ref)_](/components/phase-banner) | false | Settings to set the Phase banner component within the HTML `
    ` element | +| wide | boolean | false | Set to “true” to increase the maximum width of the layout container to 1280px | +| fullWidth | boolean | false | Set to “true” to increase the maximum width of the layout container to the full width of the viewport | +| classes | string | false | Classes to add to the wrapping `header` | +| variants | array or string | false | An array of values or single value (string) to adjust the component using available variants: “internal”, "neutral", “description” and "basic" | +| mastheadLogoUrl | string | false | Wraps the masthead logo in a link. Set the URL for the HTML `href` attribute for the link. | +| mastheadLogo | object`` | false | Settings for a [custom organisation logo](#mastheadlogo) in the masthead. Defaults to the ONS logo. | +| language | object`` | false | Settings for the [language selector](#language) | +| serviceLinks | object`` | false | Settings for the [service links](#servicelinks) in the masthead | +| title | string | true (unless `titleLogo` is set or variant is set to basic) | The title for the service | +| description | string | false | Tagline or description for the service | +| titleAsH1 | boolean | false | Override to wrap the header `title` in an `

    ` heading | +| titleLogo | object`` | false | Settings for a [custom title logo](#titlelogo) in the header. | +| titleUrl | string | false | Wraps the title logo in a link. Set the URL for the HTML `href` attribute for the link. | +| button | object`` | false | Settings for the [sign out button](#signoutbutton) in the header used to exit a transactional service | +| navigation | array`` | false | Settings for the [main menu links](#navigation) | +| siteSearchAutosuggest | `Autosuggest` [_(ref)_](/components/autosuggest) | false | Sets the autosuggest functionality in the header | ## MastheadLogo diff --git a/src/components/header/_macro.njk b/src/components/header/_macro.njk index 317e314464..d75d0981b4 100644 --- a/src/components/header/_macro.njk +++ b/src/components/header/_macro.njk @@ -218,118 +218,120 @@ {% endif %}

    -
    -
    -
    -
    - {% if params.titleLogo.large %} + {% if params.variants != "basic" %} +
    +
    +
    +
    + {% if params.titleLogo.large %} - {% set title %} - - {% if params.titleLogo.small %} + {% set title %} - {% endif %} - {% endset %} + {% if params.titleLogo.small %} + + {% endif %} + {% endset %} - {% if params.titleUrl %} - {{ title | safe }} + {% if params.titleUrl %} + {{ title | safe }} + {% else %} + {{ title | safe }} + {% endif %} {% else %} - {{ title | safe }} - {% endif %} - {% else %} - {% set title %} - {{ openingTag | safe }} - class="ons-header__title">{{ params.title }}{{ closingTag | safe }} - {% endset %} + {% set title %} + {{ openingTag | safe }} + class="ons-header__title">{{ params.title }}{{ closingTag | safe }} + {% endset %} - {% if params.titleUrl %} - {{ title | safe }} - {% else %} - {{ title | safe }} + {% if params.titleUrl %} + {{ title | safe }} + {% else %} + {{ title | safe }} + {% endif %} {% endif %} - {% endif %} - {% if params.description %} -

    {{ params.description }}

    - {% endif %} -
    + {% if params.description %} +

    {{ params.description }}

    + {% endif %} +
    - {% if params.button %} - {% if params.variants == 'neutral' %} - {% set buttonVariant = "ghost-dark" %} - {% else %} - {% set buttonVariant = "ghost" %} + {% if params.button %} + {% if params.variants == 'neutral' %} + {% set buttonVariant = "ghost-dark" %} + {% else %} + {% set buttonVariant = "ghost" %} + {% endif %} +
    + {{ + onsButton({ + "text": params.button.text, + "classes": "ons-u-d-no@2xs@l" if params.navigation else "ons-u-d-no@2xs@m", + "variants": buttonVariant, + "name": params.button.name, + "attributes": params.button.attributes, + "url": params.button.url, + "iconType": "exit", + "iconPosition": "after" + }) + }} +
    {% endif %} -
    - {{ - onsButton({ - "text": params.button.text, - "classes": "ons-u-d-no@2xs@l" if params.navigation else "ons-u-d-no@2xs@m", - "variants": buttonVariant, - "name": params.button.name, - "attributes": params.button.attributes, - "url": params.button.url, - "iconType": "exit", - "iconPosition": "after" - }) - }} -
    - {% endif %} - {% if params.navigation or params.siteSearchAutosuggest %} -
    - {% if params.siteSearchAutosuggest %} - {% if params.variants == 'neutral' %} - {% set buttonVariant = ["small", "ghost-dark"] %} - {% else %} - {% set buttonVariant = ["small", "ghost"] %} + {% if params.navigation or params.siteSearchAutosuggest %} +
    + {% if params.siteSearchAutosuggest %} + {% if params.variants == 'neutral' %} + {% set buttonVariant = ["small", "ghost-dark"] %} + {% else %} + {% set buttonVariant = ["small", "ghost"] %} + {% endif %} + + {{ + onsButton({ + "text": "Search", + "classes": "ons-btn--search ons-u-ml-2xs ons-u-d-no ons-js-toggle-search", + "variants": buttonVariant, + "iconType": "search", + "iconPosition": "only", + "attributes": { + "aria-label": "Toggle search" , + "aria-controls": "ons-site-search", + "aria-expanded": "false" + } + }) + }} + {% endif %} - + {% if params.navigation.toggleNavigationButton %} + {% set buttonVariant = ["mobile", "ghost"] %} {{ onsButton({ - "text": "Search", - "classes": "ons-btn--search ons-u-ml-2xs ons-u-d-no ons-js-toggle-search", + "text": params.navigation.toggleNavigationButton.text, + "classes": "ons-u-ml-2xs ons-u-d-no ons-js-navigation-button ons-u-d-no@l", "variants": buttonVariant, - "iconType": "search", - "iconPosition": "only", "attributes": { - "aria-label": "Toggle search" , - "aria-controls": "ons-site-search", + "aria-label": params.navigation.toggleNavigationButton.ariaLabel | default("Toggle main menu") , + "aria-controls": params.navigation.id, "aria-expanded": "false" } }) }} - - {% endif %} - {% if params.navigation.toggleNavigationButton %} - {% set buttonVariant = ["mobile", "ghost"] %} - {{ - onsButton({ - "text": params.navigation.toggleNavigationButton.text, - "classes": "ons-u-ml-2xs ons-u-d-no ons-js-navigation-button ons-u-d-no@l", - "variants": buttonVariant, - "attributes": { - "aria-label": params.navigation.toggleNavigationButton.ariaLabel | default("Toggle main menu") , - "aria-controls": params.navigation.id, - "aria-expanded": "false" - } - }) - }} - {% endif %} -
    - {% endif %} + {% endif %} +
    + {% endif %} +
    -
    + {% endif %} {% if params.navigation %} {{ onsNavigation(params) }} {% endif %} diff --git a/src/components/header/_macro.spec.js b/src/components/header/_macro.spec.js index 1505ab3112..0357aa40de 100644 --- a/src/components/header/_macro.spec.js +++ b/src/components/header/_macro.spec.js @@ -43,6 +43,16 @@ describe('FOR: Macro: Header', () => { expect($('.ons-header--variant-b').length).toBe(1); }); }); + describe('WHEN: variants is set to basic', () => { + test('THEN: does not render the main part of the header', () => { + const $ = cheerio.load( + renderComponent('header', { + variants: 'basic', + }), + ); + expect($('.ons-header > .ons-header__main').length).toBe(0); + }); + }); }); describe('GIVEN: Params: classes', () => { describe('WHEN: classes are provided', () => { @@ -713,7 +723,6 @@ describe('FOR: Macro: Header', () => { ariaMinChars: 'Enter 3 or more characters for suggestions.', ariaNResults: 'There are {n} suggestions available.', ariaOneResult: 'There is one suggestion available.', - ariaResultsLabel: 'Country suggestions', ariaYouHaveSelected: 'You have selected', containerClasses: 'ons-autosuggest--header', id: 'ons-site-search', diff --git a/src/components/header/_test-examples.js b/src/components/header/_test-examples.js index 2668867a75..634dd7c323 100644 --- a/src/components/header/_test-examples.js +++ b/src/components/header/_test-examples.js @@ -139,7 +139,6 @@ export const EXAMPLE_HEADER_NAVIGATION_WITH_SITESEARCHAUTOSUGGEST = { ariaYouHaveSelected: 'You have selected', ariaMinChars: 'Enter 3 or more characters for suggestions.', minChars: 3, - ariaResultsLabel: 'Country suggestions', ariaOneResult: 'There is one suggestion available.', ariaNResults: 'There are {n} suggestions available.', ariaLimitedResults: 'Type more characters to improve your search', diff --git a/src/components/header/example-header-basic.njk b/src/components/header/example-header-basic.njk new file mode 100644 index 0000000000..1204ca4c6a --- /dev/null +++ b/src/components/header/example-header-basic.njk @@ -0,0 +1,11 @@ +--- +'fullWidth': true +--- + +{% from "components/header/_macro.njk" import onsHeader %} + +{{ + onsHeader({ + "variants": 'basic' + }) +}} diff --git a/src/components/header/example-header-external-with-navigation-and-search.njk b/src/components/header/example-header-external-with-navigation-and-search.njk index d31be2f1d7..7a1188976e 100644 --- a/src/components/header/example-header-external-with-navigation-and-search.njk +++ b/src/components/header/example-header-external-with-navigation-and-search.njk @@ -45,7 +45,6 @@ "instructions": "instructions", "ariaYouHaveSelected": "ariaYouHaveSelected", "ariaMinChars": "ariaMinChars", - "ariaResultsLabel": "ariaResultsLabel", "ariaOneResult": "ariaOneResult", "ariaNResults": "ariaNResults", "ariaLimitedResults": "ariaLimitedResults", diff --git a/src/components/hero/_hero.scss b/src/components/hero/_hero.scss index cb5694d852..bead3a4721 100644 --- a/src/components/hero/_hero.scss +++ b/src/components/hero/_hero.scss @@ -28,6 +28,35 @@ } } + &--grey { + background-color: var(--ons-color-grey-10); + &::before { + content: ''; + background-color: var(--ons-color-banner-bg); + border-radius: 0 0 50% 50%; + inset: 0; + left: -40%; + position: absolute; + width: 150%; + @include mq(l) { + border-radius: 0 0 300% 150%; + left: 0; + width: 100%; + } + } + } + &__badge { + @include mq(xs, l) { + margin-top: 2.5rem; + margin-bottom: 1rem; + } + } + + &--topic { + color: var(--ons-color-branded); + @extend .ons-u-mb-no; + } + &__container { align-items: center; display: flex; @@ -43,10 +72,6 @@ height: 100%; } - &__text:has(+ .ons-btn) { - margin-bottom: 2rem; - } - &__pre-title { margin-bottom: 0.5rem; @@ -62,6 +87,10 @@ z-index: 5; } + &__details:has(.ons-breadcrumbs) { + padding-top: 1rem; + } + &--dark & { &__details { color: var(--ons-color-text-inverse) !important; @@ -299,4 +328,16 @@ } } } + + &__title-container { + @include mq(l) { + display: grid; + align-items: start; + justify-content: space-between; + + &.ons-hero__title-badge { + grid-template-columns: 1fr auto; + } + } + } } diff --git a/src/components/hero/_macro-options.md b/src/components/hero/_macro-options.md index 002ceb3008..dbafde84a3 100644 --- a/src/components/hero/_macro-options.md +++ b/src/components/hero/_macro-options.md @@ -1,13 +1,17 @@ -| Name | Type | Required | Description | -| -------------- | ---------------- | -------- | -------------------------------------------------------------------------------------------------------------------- | -| variants | array or string | false | An array of values or single value (string) to adjust the component using available variants, “dark” and "navy-blue" | -| wide | boolean | false | Set to “true” when using the `wide` page layout container | -| title | string | true | Text for the hero title | -| subtitle | string | false | Text for the hero subtitle | -| text | string | false | Text to follow the hero title and subtitle | -| button | `Object