Skip to content

Commit

Permalink
Merge branch 'main' into improvements/2868/onscollapsible-removal
Browse files Browse the repository at this point in the history
  • Loading branch information
rmccar authored Nov 16, 2023
2 parents 6ebed07 + 03ff7c8 commit eeeaf6b
Show file tree
Hide file tree
Showing 24 changed files with 395 additions and 190 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/lighthouse-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,10 @@ jobs:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Read .nvmrc file
id: read-nvmrc-file
run: echo "nvmrc=$(cat .nvmrc)" >> $GITHUB_OUTPUT
- name: Install Node
uses: actions/setup-node@v3
with:
node-version: "${{ steps.read-nvmrc-file.outputs.nvmrc }}"
node-version-file: ".nvmrc"
- name: Install dependencies
run: yarn install
- name: Build pages
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/macro-and-script-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,10 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Read .nvmrc file
id: read-nvmrc-file
run: echo "nvmrc=$(cat .nvmrc)" >> $GITHUB_OUTPUT
- name: Install Node
uses: actions/setup-node@v3
with:
node-version: "${{ steps.read-nvmrc-file.outputs.nvmrc }}"
node-version-file: ".nvmrc"
- name: Install dependencies
run: yarn install
- name: Run macro and script tests
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/npm-bundle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,14 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Read .nvmrc file
id: read-nvmrc-file
run: echo "nvmrc=$(cat .nvmrc)" >> $GITHUB_OUTPUT
- name: Use Node.js
uses: actions/checkout@v3
with:
ref: ${{ github.event.release.target_commitish }}
- name: Install Node
uses: actions/setup-node@v3
with:
node-version: "${{ steps.read-nvmrc-file.outputs.nvmrc }}"
node-version-file: ".nvmrc"
registry-url: https://registry.npmjs.org/
- run: yarn install
- run: git config --global user.name "${{ github.actor }}"
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Read .nvmrc file
id: read-nvmrc-file
run: echo "nvmrc=$(cat .nvmrc)" >> $GITHUB_OUTPUT
- name: Install Node
uses: actions/setup-node@v3
with:
node-version: "${{ steps.read-nvmrc-file.outputs.nvmrc }}"
node-version-file: ".nvmrc"
- name: Install dependencies
run: yarn install
- name: Build templates
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/visual-regression-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,10 @@ jobs:
with:
lfs: true
url: https://github.com/ONSdigital/design-system.git
- name: Read .nvmrc file
id: read-nvmrc-file
run: echo "nvmrc=$(cat .nvmrc)" >> $GITHUB_OUTPUT
- name: Install Node
uses: actions/setup-node@v3
with:
node-version: "${{ steps.read-nvmrc-file.outputs.nvmrc }}"
node-version-file: ".nvmrc"
- name: Install dependencies
run: yarn install
- name: Install Docker
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions src/components/accordion/example-accordion-open.njk
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"text": "Areas (0)"
},
"value": "areas"
}
}
]
})
}}
Expand Down Expand Up @@ -98,7 +98,7 @@
"text": "Disability (67)"
},
"value": "disability"
}
}
]
})
}}
Expand Down
2 changes: 1 addition & 1 deletion src/components/checkboxes/_macro.njk
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{% set fields %}
{% if params.checkboxesLabel is defined %}
<p class="ons-checkboxes__label{{ " " + params.checkboxesLabelClasses if params.checkboxesLabelClasses }}">{{ params.checkboxesLabel }}</p>
{% endif %}
{% endif %}
{% set hasOther = false %}
{% for checkbox in params.checkboxes %}
{% if checkbox.other %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
"text": "Areas (0)"
},
"value": "areas"
}
}
]
})
}}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"text": "Areas (0)"
},
"value": "areas"
}
}
]
})
}}
2 changes: 1 addition & 1 deletion src/components/footer/_macro.njk
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@
{% endif %}
{% if params.copyrightDeclaration %}
<!-- Copyright -->
<div class="ons-grid ons-grid--flex ons-grid--vertical-bottom ons-grid--between">
<div class="ons-grid ons-grid--flex ons-grid--vertical-bottom ons-grid--between">
<div class="ons-grid__col">
<p class="ons-u-fs-s ons-u-mb-no ons-footer__copyright">&copy; {{ params.copyrightDeclaration.copyright }} <br> {{ params.copyrightDeclaration.text }}</p>
</div>
Expand Down
133 changes: 128 additions & 5 deletions src/components/header/_macro.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,45 @@ const EXAMPLE_HEADER_NAVIGATION_WITH_SUBNAVIGATION_CONFIG = {
},
};

const EXAMPLE_HEADER_NAVIGATION_WITH_SITESEARCHAUTOSUGGEST = {
navigation: {
id: 'main-nav',
ariaLabel: 'Main menu',
currentPath: '#home',
itemsList: [
{
title: 'Home',
url: '#home',
},
{
title: 'Guidance',
url: '#0',
},
],
toggleNavigationButton: {
text: 'Menu',
ariaLabel: 'Toggle main menu',
},
},
siteSearchAutosuggest: {
label: 'label',
instructions: 'Use up and down keys to navigate.',
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',
moreResults: 'Continue entering to improve suggestions',
resultsTitle: 'Suggestions',
resultsTitleId: 'country-of-birth-suggestions',
noResults: 'No suggestions found.',
typeMore: 'Continue entering to get suggestions',
language: 'en-gb',
},
};

describe('macro: header', () => {
describe('mode: basic', () => {
it('passes jest-axe checks', async () => {
Expand Down Expand Up @@ -453,21 +492,21 @@ describe('macro: header', () => {
it('has the text for each list item', () => {
const $ = cheerio.load(renderComponent('header', EXAMPLE_HEADER_SERVICE_LIST_ITEMS));

const values = mapAll($('.ons-header-service-nav--main .ons-header-service-nav__item'), node => node.text().trim());
const values = mapAll($('.ons-header-service-nav--main .ons-header-service-nav__item'), (node) => node.text().trim());
expect(values).toEqual(['Title 1', 'Title 2', 'Title 3']);
});

it('has the link text for each list item', () => {
const $ = cheerio.load(renderComponent('header', EXAMPLE_HEADER_SERVICE_LINKS_MULTIPLE));

const values = mapAll($('.ons-header-service-nav--main .ons-header-service-nav__link'), node => node.text().trim());
const values = mapAll($('.ons-header-service-nav--main .ons-header-service-nav__link'), (node) => node.text().trim());
expect(values).toEqual(['Title 1', 'Title 2', 'Title 3']);
});

it('has the link href for each list item', () => {
const $ = cheerio.load(renderComponent('header', EXAMPLE_HEADER_SERVICE_LINKS_MULTIPLE));

const values = mapAll($('.ons-header-service-nav--main .ons-header-service-nav__link'), node => node.attr('href'));
const values = mapAll($('.ons-header-service-nav--main .ons-header-service-nav__link'), (node) => node.attr('href'));
expect(values).toEqual(['#1', '#2', '#3']);
});

Expand All @@ -486,14 +525,14 @@ describe('macro: header', () => {
it('has the link text for each list item for mobile', () => {
const $ = cheerio.load(renderComponent('header', EXAMPLE_HEADER_SERVICE_LINKS_MULTIPLE));

const values = mapAll($('.ons-header-service-nav--mobile .ons-header-service-nav__link'), node => node.text().trim());
const values = mapAll($('.ons-header-service-nav--mobile .ons-header-service-nav__link'), (node) => node.text().trim());
expect(values).toEqual(['Title 1', 'Title 2', 'Title 3']);
});

it('has the link href for each list item for mobile', () => {
const $ = cheerio.load(renderComponent('header', EXAMPLE_HEADER_SERVICE_LINKS_MULTIPLE));

const values = mapAll($('.ons-header-service-nav--mobile .ons-header-service-nav__link'), node => node.attr('href'));
const values = mapAll($('.ons-header-service-nav--mobile .ons-header-service-nav__link'), (node) => node.attr('href'));
expect(values).toEqual(['#1', '#2', '#3']);
});

Expand Down Expand Up @@ -742,3 +781,87 @@ describe('macro: header', () => {
});
});
});

describe('mode: with site search autosuggest', () => {
it('renders the search with expected parameters', () => {
const faker = templateFaker();
const buttonSpy = faker.spy('autosuggest');

faker.renderComponent('header', EXAMPLE_HEADER_NAVIGATION_WITH_SITESEARCHAUTOSUGGEST);

expect(buttonSpy.occurrences[0]).toEqual({
ariaLimitedResults: 'Type more characters to improve your search',
minChars: 3,
language: 'en-gb',
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',
input: {
accessiblePlaceholder: true,
autocomplete: 'off',
classes: 'ons-input-search ons-input-search--icon',
label: {
classes: 'ons-u-pl-m ons-label--white',
id: 'ons-site-search-label',
text: 'label',
},
},
instructions: 'Use up and down keys to navigate.',
moreResults: 'Continue entering to improve suggestions',
noResults: 'No suggestions found.',
resultsTitle: 'Suggestions',
typeMore: 'Continue entering to get suggestions',
});
});

describe('when the user inputs text', () => {
let $; // Initialize a Cheerio instance

const mockData = [
{ en: 'England' },
{ en: 'Wales' },
{ en: 'Scotland' },
{ en: 'United States of America' },
{ en: 'United States Virgin Islands' },
{ en: 'Åland Islands' },
];

beforeEach(() => {
$ = cheerio.load(
renderComponent('header', {
...EXAMPLE_HEADER_NAVIGATION_WITH_SITESEARCHAUTOSUGGEST,
autosuggestData: mockData,
}),
);
});

it('does not show suggestions when input length < minimum characters', () => {
$('.ons-js-autosuggest-input').val('En');

setTimeout(() => {
const suggestionCount = $('.ons-autosuggest__option').length;
expect(suggestionCount).toBe(0);
}, 20);
});

it('shows suggestions when input length >= minimum characters', () => {
$('.ons-js-autosuggest-input').val('Eng');

setTimeout(() => {
const suggestionCount = $('.ons-autosuggest__option').length;
expect(suggestionCount).toBe(1);
}, 20);
});

it('gets the language if set', () => {
$('.ons-js-autosuggest-input').val('Eng');

const autosuggestElement = $('.ons-js-autosuggest').attr('data-lang');
expect(autosuggestElement).toBe('en-gb');
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
"fullWidth": true
---
{% from "components/header/_macro.njk" import onsHeader %}

{{
onsHeader({
"title": 'Design system',
"titleUrl": '#0',
"navigation": {
"id": 'main-nav',
"ariaLabel": 'Main menu',
"currentPath": '#home',
"itemsList": [
{
"text": 'Home',
"url": '#home'
},
{
"text": 'Guidance',
"url": '#0'
},
{
"text": 'Foundations',
"url": '#0'
},
{
"text": 'Components',
"url": '#0'
},
{
"text": 'Patterns',
"url": '#0'
}
],
"toggleNavigationButton": {
"text": 'Menu',
"ariaLabel": 'Toggle main menu'
}
},
'siteSearchAutosuggest': {
"autosuggestData": "/examples/data/country-of-birth.json",
"label": "search",
"instructions": "instructions",
"ariaYouHaveSelected": "ariaYouHaveSelected",
"ariaMinChars": "ariaMinChars",
"ariaResultsLabel": "ariaResultsLabel",
"ariaOneResult": "ariaOneResult",
"ariaNResults": "ariaNResults",
"ariaLimitedResults": "ariaLimitedResults",
"moreResults": "moreResults",
"resultsTitle": "resultsTitle",
"noResults": "noResults",
"typeMore": "typeMore"
}
})
}}
4 changes: 2 additions & 2 deletions src/components/label/_macro.njk
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{% macro onsLabel(params) %}
{% if params.id %}
{% set descriptionID = params.id ~ "-description-hint" %}
{% set descriptionID = params.id ~ "-description-hint" %}
{% else %}
{% set descriptionID = "description-hint" %}
{% set descriptionID = "description-hint" %}
{% endif %}

{% if params.inputType == "checkbox" or params.inputType == "radio" %}
Expand Down
Loading

0 comments on commit eeeaf6b

Please sign in to comment.