@ons/design-system 50.0.1 → 51.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +35 -13
- package/components/access-code/_macro.njk +1 -1
- package/components/access-code/_macro.spec.js +162 -0
- package/components/access-code/uac.spec.js +26 -0
- package/components/accordion/_macro.spec.js +224 -0
- package/components/accordion/accordion.spec.js +134 -0
- package/components/address-input/_macro.njk +1 -1
- package/components/address-input/_macro.spec.js +465 -0
- package/components/address-input/autosuggest.address.js +5 -4
- package/components/address-input/autosuggest.address.setter.js +3 -1
- package/components/address-input/autosuggest.address.spec.js +733 -0
- package/components/address-output/_macro.njk +6 -6
- package/components/address-output/_macro.spec.js +122 -0
- package/components/autosuggest/_macro.njk +1 -1
- package/components/autosuggest/_macro.spec.js +229 -0
- package/components/autosuggest/autosuggest.helpers.js +2 -3
- package/components/autosuggest/autosuggest.helpers.spec.js +85 -0
- package/components/autosuggest/autosuggest.js +4 -2
- package/components/autosuggest/autosuggest.spec.js +625 -0
- package/components/autosuggest/autosuggest.ui.js +6 -2
- package/components/breadcrumbs/_macro.spec.js +129 -0
- package/components/button/_macro.njk +5 -5
- package/components/button/_macro.spec.js +446 -0
- package/components/button/button.spec.js +290 -0
- package/components/call-to-action/_macro.njk +3 -1
- package/components/call-to-action/_macro.spec.js +52 -0
- package/components/card/_macro.njk +26 -19
- package/components/card/_macro.spec.js +261 -0
- package/components/char-check-limit/_macro.spec.js +73 -0
- package/components/char-check-limit/character-check.spec.js +196 -0
- package/components/char-check-limit/character-limit.js +1 -1
- package/components/checkboxes/_checkbox-macro.spec.js +419 -0
- package/components/checkboxes/_macro.njk +1 -3
- package/components/checkboxes/_macro.spec.js +306 -0
- package/components/checkboxes/checkboxes.spec.js +208 -0
- package/components/code-highlight/_macro.spec.js +56 -0
- package/components/code-highlight/code-highlight.spec.js +18 -0
- package/components/collapsible/_macro.spec.js +204 -0
- package/components/collapsible/collapsible.js +2 -1
- package/components/collapsible/collapsible.spec.js +236 -0
- package/components/content-pagination/_macro.spec.js +199 -0
- package/components/cookies-banner/_macro.njk +1 -1
- package/components/cookies-banner/_macro.spec.js +171 -0
- package/components/cookies-banner/cookies-banner.spec.js +90 -0
- package/components/date-input/_macro.njk +6 -3
- package/components/date-input/_macro.spec.js +286 -0
- package/components/document-list/_macro.njk +3 -5
- package/components/document-list/_macro.spec.js +491 -0
- package/components/download-resources/download-resources.spec.js +540 -0
- package/components/duration/_macro.njk +7 -6
- package/components/duration/_macro.spec.js +251 -0
- package/components/error/_macro.spec.js +97 -0
- package/components/external-link/_macro.spec.js +60 -0
- package/components/feedback/_macro.njk +5 -3
- package/components/feedback/_macro.spec.js +122 -0
- package/components/field/_macro.njk +2 -2
- package/components/field/_macro.spec.js +97 -0
- package/components/fieldset/_macro.njk +3 -3
- package/components/fieldset/_macro.spec.js +173 -0
- package/components/footer/_macro.njk +11 -48
- package/components/footer/_macro.spec.js +549 -0
- package/components/header/_macro.njk +2 -2
- package/components/header/_macro.spec.js +562 -0
- package/components/hero/_hero.scss +0 -3
- package/components/hero/_macro.njk +4 -4
- package/components/hero/_macro.spec.js +224 -0
- package/components/icons/_macro.njk +15 -15
- package/components/icons/_macro.spec.js +140 -0
- package/components/images/_macro.njk +1 -1
- package/components/images/_macro.spec.js +121 -0
- package/components/input/_input-type.scss +12 -5
- package/components/input/_macro.njk +4 -5
- package/components/input/_macro.spec.js +658 -0
- package/components/label/_macro.spec.js +189 -0
- package/components/language-selector/_macro.spec.js +129 -0
- package/components/lists/_list.scss +4 -0
- package/components/lists/_macro.njk +4 -7
- package/components/lists/_macro.spec.js +618 -0
- package/components/message/_macro.spec.js +137 -0
- package/components/message-list/_macro.njk +7 -7
- package/components/message-list/_macro.spec.js +159 -0
- package/components/metadata/_macro.spec.js +167 -0
- package/components/modal/_macro.njk +6 -6
- package/components/modal/_macro.spec.js +87 -0
- package/components/modal/modal.spec.js +59 -0
- package/components/mutually-exclusive/_macro.njk +1 -1
- package/components/mutually-exclusive/_macro.spec.js +182 -0
- package/components/mutually-exclusive/mutually-exclusive.checkboxes.spec.js +203 -0
- package/components/mutually-exclusive/mutually-exclusive.date.spec.js +142 -0
- package/components/mutually-exclusive/mutually-exclusive.duration.spec.js +141 -0
- package/components/mutually-exclusive/mutually-exclusive.email.spec.js +117 -0
- package/components/mutually-exclusive/mutually-exclusive.multiple-options.checkboxes.spec.js +213 -0
- package/components/mutually-exclusive/mutually-exclusive.number.spec.js +125 -0
- package/components/mutually-exclusive/mutually-exclusive.textarea.spec.js +131 -0
- package/components/navigation/_macro.njk +6 -6
- package/components/navigation/_macro.spec.js +327 -0
- package/components/navigation/navigation.dom.js +1 -1
- package/components/navigation/navigation.spec.js +232 -0
- package/components/pagination/_macro.njk +1 -1
- package/components/pagination/_macro.spec.js +411 -0
- package/components/panel/_macro.njk +6 -6
- package/components/panel/_macro.spec.js +423 -0
- package/components/password/_macro.spec.js +137 -0
- package/components/password/password.spec.js +40 -0
- package/components/phase-banner/_macro.spec.js +73 -0
- package/components/promotional-banner/_macro.spec.js +97 -0
- package/components/question/_macro.njk +25 -33
- package/components/question/_macro.spec.js +309 -0
- package/components/quote/_macro.spec.js +81 -0
- package/components/radios/_macro.njk +3 -6
- package/components/radios/_macro.spec.js +575 -0
- package/components/radios/radios.spec.js +180 -0
- package/components/related-content/_macro.njk +1 -0
- package/components/related-content/_macro.spec.js +142 -0
- package/components/relationships/_macro.spec.js +108 -0
- package/components/relationships/relationships.spec.js +84 -0
- package/components/reply/_macro.njk +2 -2
- package/components/reply/_macro.spec.js +69 -0
- package/components/reply/reply.spec.js +78 -0
- package/components/search/_macro.njk +14 -12
- package/components/search/_macro.spec.js +44 -0
- package/components/search/_search.scss +7 -7
- package/components/section-navigation/_macro.njk +7 -2
- package/components/section-navigation/_macro.spec.js +206 -0
- package/components/select/_macro.njk +3 -3
- package/components/select/_macro.spec.js +203 -0
- package/components/select/select.spec.js +56 -0
- package/components/share-page/_macro.njk +2 -2
- package/components/share-page/_macro.spec.js +110 -0
- package/components/skip-to-content/_macro.spec.js +57 -0
- package/components/skip-to-content/skip-to-content.spec.js +44 -0
- package/components/status/_macro.spec.js +77 -0
- package/components/summary/_macro.njk +5 -5
- package/components/summary/_macro.spec.js +472 -0
- package/components/table/_macro.njk +2 -2
- package/components/table/_macro.spec.js +557 -0
- package/components/table/table.spec.js +155 -0
- package/components/table-of-contents/_macro.njk +35 -35
- package/components/table-of-contents/_macro.spec.js +178 -0
- package/components/table-of-contents/toc.js +29 -25
- package/components/table-of-contents/toc.spec.js +61 -0
- package/components/tabs/_macro.njk +1 -1
- package/components/tabs/_macro.spec.js +79 -0
- package/components/tabs/tabs.spec.js +162 -0
- package/components/text-indent/_macro.spec.js +52 -0
- package/components/textarea/_macro.njk +5 -3
- package/components/textarea/_macro.spec.js +300 -0
- package/components/textarea/textarea.spec.js +98 -0
- package/components/timeline/_macro.njk +3 -3
- package/components/timeline/_macro.spec.js +81 -0
- package/components/timeout-modal/_macro.spec.js +68 -0
- package/components/timeout-modal/timeout-modal.spec.js +226 -0
- package/components/timeout-panel/_macro.njk +0 -1
- package/components/timeout-panel/_macro.spec.js +54 -0
- package/components/timeout-panel/timeout-panel.dom.js +1 -2
- package/components/timeout-panel/timeout-panel.spec.js +161 -0
- package/components/upload/_macro.spec.js +75 -0
- package/components/video/_macro.spec.js +34 -0
- package/css/census.css +1 -1
- package/css/main.css +1 -1
- package/js/cookies-settings.spec.js +154 -0
- package/package.json +10 -23
- package/scripts/main.es5.js +1 -1
- package/scripts/main.js +1 -1
|
@@ -3,16 +3,18 @@
|
|
|
3
3
|
|
|
4
4
|
{% set content = caller() %}
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
6
|
+
<div class="ons-search-component">
|
|
7
|
+
{{ content | safe }}
|
|
8
|
+
{{
|
|
9
|
+
onsButton({
|
|
10
|
+
"type": params.searchButton.type,
|
|
11
|
+
"text": params.searchButton.text,
|
|
12
|
+
"id": params.searchButton.id,
|
|
13
|
+
"variants": 'small',
|
|
14
|
+
"classes": 'ons-search__btn ons-u-mt-xs@xxs@s' + (" " + params.searchButton.classes if params.searchButton.classes else ""),
|
|
15
|
+
"attributes": params.searchButton.attributes,
|
|
16
|
+
"iconType": params.searchButton.iconType
|
|
17
|
+
})
|
|
18
|
+
}}
|
|
19
|
+
</div>
|
|
18
20
|
{% endmacro %}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/** @jest-environment jsdom */
|
|
2
|
+
|
|
3
|
+
import * as cheerio from 'cheerio';
|
|
4
|
+
|
|
5
|
+
import axe from '../../tests/helpers/axe';
|
|
6
|
+
import { renderComponent, templateFaker } from '../../tests/helpers/rendering';
|
|
7
|
+
|
|
8
|
+
const EXAMPLE_SEARCH = {
|
|
9
|
+
searchButton: {
|
|
10
|
+
id: 'search-button-id',
|
|
11
|
+
type: 'button',
|
|
12
|
+
text: 'Search for address',
|
|
13
|
+
iconType: 'search',
|
|
14
|
+
classes: 'extra-search-button-class',
|
|
15
|
+
attributes: { a: 42 },
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const FAKE_NESTED_CONTENT = '<span class="test--nested">Nested content...</span>';
|
|
20
|
+
|
|
21
|
+
describe('macro: search', () => {
|
|
22
|
+
it('renders expected nested content', () => {
|
|
23
|
+
const $ = cheerio.load(renderComponent('search', EXAMPLE_SEARCH, FAKE_NESTED_CONTENT));
|
|
24
|
+
|
|
25
|
+
expect($('.ons-search-component .test--nested').text()).toBe('Nested content...');
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('renders button component', () => {
|
|
29
|
+
const faker = templateFaker();
|
|
30
|
+
const buttonSpy = faker.spy('button');
|
|
31
|
+
|
|
32
|
+
faker.renderComponent('input', EXAMPLE_SEARCH);
|
|
33
|
+
|
|
34
|
+
expect(buttonSpy.occurrences[0]).toEqual({
|
|
35
|
+
id: 'search-button-id',
|
|
36
|
+
type: 'button',
|
|
37
|
+
text: 'Search for address',
|
|
38
|
+
variants: 'small',
|
|
39
|
+
classes: 'ons-search__btn ons-u-mt-xs@xxs@s extra-search-button-class',
|
|
40
|
+
attributes: EXAMPLE_SEARCH.searchButton.attributes,
|
|
41
|
+
iconType: 'search',
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
});
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
.ons-search {
|
|
1
|
+
.ons-search-component {
|
|
2
|
+
display: flex;
|
|
2
3
|
flex-flow: row wrap;
|
|
3
|
-
margin-left: -0.5rem;
|
|
4
|
-
margin-top: -0.5rem;
|
|
5
4
|
|
|
6
5
|
@include mq(s) {
|
|
7
6
|
flex-flow: row nowrap !important;
|
|
8
7
|
}
|
|
9
|
-
|
|
8
|
+
.ons-search__btn {
|
|
10
9
|
margin-top: -3px;
|
|
11
10
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
.ons-search__btn {
|
|
12
|
+
@include mq(s) {
|
|
13
|
+
margin-left: 0.5rem;
|
|
14
|
+
}
|
|
15
15
|
}
|
|
16
16
|
}
|
|
@@ -2,8 +2,13 @@
|
|
|
2
2
|
<nav class="ons-section-nav{% if params.variants is defined and params.variants == 'vertical' %} ons-section-nav--vertical{% endif %}" id="{{ params.id }}" aria-label="{{ params.ariaLabel | default("Section menu") }}">
|
|
3
3
|
<ul class="ons-section-nav__list">
|
|
4
4
|
{% for item in (params.itemsList if params.itemsList is iterable else params.itemsList.items()) %}
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
{% if (params.currentPath and (item.url == params.currentPath or item.url in params.currentPath)) or (params.tabQuery and params.tabQuery == item.title|lower) %}
|
|
6
|
+
{% set isCurrent = true %}
|
|
7
|
+
{% else %}
|
|
8
|
+
{% set isCurrent = false %}
|
|
9
|
+
{% endif %}
|
|
10
|
+
<li class="ons-section-nav__item{% if item.classes %} ' ' + {{ item.classes }}{% endif %}{% if isCurrent == true %} ons-section-nav__item--active{% endif %}">
|
|
11
|
+
<a class="ons-section-nav__link" href="{{ item.url }}"{% if isCurrent == true %} aria-current="location"{% endif %}>{{ item.title }}</a>
|
|
7
12
|
{% if item.anchors is defined and item.anchors %}
|
|
8
13
|
<ul class="ons-section-nav__sub-items ons-list ons-list--dashed ons-u-mt-xs ons-u-mb-xs">
|
|
9
14
|
{% for anchor in item.anchors %}
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
/** @jest-environment jsdom */
|
|
2
|
+
|
|
3
|
+
import * as cheerio from 'cheerio';
|
|
4
|
+
|
|
5
|
+
import axe from '../../tests/helpers/axe';
|
|
6
|
+
import { mapAll } from '../../tests/helpers/cheerio';
|
|
7
|
+
import { renderComponent } from '../../tests/helpers/rendering';
|
|
8
|
+
|
|
9
|
+
const EXAMPLE_SECTION_NAVIGATION = {
|
|
10
|
+
id: 'section-menu',
|
|
11
|
+
currentPath: '/results',
|
|
12
|
+
itemsList: [
|
|
13
|
+
{
|
|
14
|
+
title: 'Results',
|
|
15
|
+
url: '/results',
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
title: 'Dashboard',
|
|
19
|
+
url: '/results/dashboard',
|
|
20
|
+
},
|
|
21
|
+
],
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const EXAMPLE_SECTION_NAVIGATION_VERTICAL = {
|
|
25
|
+
variants: 'vertical',
|
|
26
|
+
currentPath: '#section-2',
|
|
27
|
+
itemsList: [
|
|
28
|
+
{
|
|
29
|
+
title: 'Section 1',
|
|
30
|
+
url: '#section-1',
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
title: 'Section 2',
|
|
34
|
+
url: '#section-2',
|
|
35
|
+
anchors: [
|
|
36
|
+
{
|
|
37
|
+
title: 'Sub section 1',
|
|
38
|
+
url: '#sub-section-1',
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
title: 'Sub section 2',
|
|
42
|
+
url: '#sub-section-2',
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
title: 'Sub section 3',
|
|
46
|
+
url: '#sub-section-3',
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
title: 'Section 3',
|
|
52
|
+
url: '#0',
|
|
53
|
+
},
|
|
54
|
+
],
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
describe('macro: section-navigation', () => {
|
|
58
|
+
describe('variant: horizontal', () => {
|
|
59
|
+
it('passes jest-axe checks', async () => {
|
|
60
|
+
const $ = cheerio.load(renderComponent('section-navigation', EXAMPLE_SECTION_NAVIGATION));
|
|
61
|
+
|
|
62
|
+
const results = await axe($.html());
|
|
63
|
+
expect(results).toHaveNoViolations();
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('does not have the `vertical` modifier class', async () => {
|
|
67
|
+
const $ = cheerio.load(renderComponent('section-navigation', EXAMPLE_SECTION_NAVIGATION));
|
|
68
|
+
|
|
69
|
+
expect($('.ons-section-nav').hasClass('ons-section-nav--vertical')).toBe(false);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
describe('variant: vertical', () => {
|
|
74
|
+
it('passes jest-axe checks', async () => {
|
|
75
|
+
const $ = cheerio.load(renderComponent('section-navigation', EXAMPLE_SECTION_NAVIGATION_VERTICAL));
|
|
76
|
+
|
|
77
|
+
const results = await axe($.html());
|
|
78
|
+
expect(results).toHaveNoViolations();
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('has the `vertical` modifier class', async () => {
|
|
82
|
+
const $ = cheerio.load(renderComponent('section-navigation', EXAMPLE_SECTION_NAVIGATION_VERTICAL));
|
|
83
|
+
|
|
84
|
+
expect($('.ons-section-nav').hasClass('ons-section-nav--vertical')).toBe(true);
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('has the provided `id` attribute', () => {
|
|
89
|
+
const $ = cheerio.load(renderComponent('section-navigation', EXAMPLE_SECTION_NAVIGATION));
|
|
90
|
+
|
|
91
|
+
expect($('.ons-section-nav').attr('id')).toBe('section-menu');
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it('has the provided `ariaLabel` parameter', () => {
|
|
95
|
+
const $ = cheerio.load(
|
|
96
|
+
renderComponent('section-navigation', {
|
|
97
|
+
...EXAMPLE_SECTION_NAVIGATION,
|
|
98
|
+
ariaLabel: 'Section navigation menu',
|
|
99
|
+
}),
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
expect($('.ons-section-nav').attr('aria-label')).toBe('Section navigation menu');
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it('assumes a default `ariaLabel` of "Section menu"', () => {
|
|
106
|
+
const $ = cheerio.load(renderComponent('section-navigation', EXAMPLE_SECTION_NAVIGATION));
|
|
107
|
+
|
|
108
|
+
expect($('.ons-section-nav').attr('aria-label')).toBe('Section menu');
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
describe('navigation items', () => {
|
|
112
|
+
it('renders top level navigation items', () => {
|
|
113
|
+
const $ = cheerio.load(renderComponent('section-navigation', EXAMPLE_SECTION_NAVIGATION));
|
|
114
|
+
|
|
115
|
+
const itemLabels = mapAll($('.ons-section-nav__item .ons-section-nav__link'), node => node.text().trim());
|
|
116
|
+
expect(itemLabels).toEqual(['Results', 'Dashboard']);
|
|
117
|
+
|
|
118
|
+
const itemLinks = mapAll($('.ons-section-nav__item .ons-section-nav__link'), node => node.attr('href'));
|
|
119
|
+
expect(itemLinks).toEqual(['/results', '/results/dashboard']);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it('has additionally provided style classes', () => {
|
|
123
|
+
const $ = cheerio.load(
|
|
124
|
+
renderComponent('section-navigation', {
|
|
125
|
+
currentPath: '#section-1',
|
|
126
|
+
itemsList: [
|
|
127
|
+
{
|
|
128
|
+
classes: 'extra-class another-extra-class',
|
|
129
|
+
title: 'Section 1',
|
|
130
|
+
url: '#section-1',
|
|
131
|
+
},
|
|
132
|
+
],
|
|
133
|
+
}),
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
expect($('.ons-section-nav__item').hasClass('extra-class')).toBe(true);
|
|
137
|
+
expect($('.ons-section-nav__item').hasClass('another-extra-class')).toBe(true);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it('marks the current item with a class when `currentPath` is provided', () => {
|
|
141
|
+
const $ = cheerio.load(renderComponent('section-navigation', EXAMPLE_SECTION_NAVIGATION));
|
|
142
|
+
|
|
143
|
+
expect(
|
|
144
|
+
$('.ons-section-nav__item--active')
|
|
145
|
+
.text()
|
|
146
|
+
.trim(),
|
|
147
|
+
).toBe('Results');
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it('marks the current item with a class when `tabQuery` is provided', () => {
|
|
151
|
+
const $ = cheerio.load(
|
|
152
|
+
renderComponent('section-navigation', {
|
|
153
|
+
...EXAMPLE_SECTION_NAVIGATION,
|
|
154
|
+
currentPath: undefined,
|
|
155
|
+
tabQuery: 'dashboard',
|
|
156
|
+
}),
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
expect(
|
|
160
|
+
$('.ons-section-nav__item--active')
|
|
161
|
+
.text()
|
|
162
|
+
.trim(),
|
|
163
|
+
).toBe('Dashboard');
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it('marks the current item with `aria-current` when `currentPath` is provided', () => {
|
|
167
|
+
const $ = cheerio.load(renderComponent('section-navigation', EXAMPLE_SECTION_NAVIGATION));
|
|
168
|
+
|
|
169
|
+
expect($('.ons-section-nav__item--active .ons-section-nav__link').attr('aria-current')).toBe('location');
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it('marks the current item with `aria-current` when `tabQuery` is provided', () => {
|
|
173
|
+
const $ = cheerio.load(
|
|
174
|
+
renderComponent('section-navigation', {
|
|
175
|
+
...EXAMPLE_SECTION_NAVIGATION,
|
|
176
|
+
currentPath: undefined,
|
|
177
|
+
tabQuery: 'dashboard',
|
|
178
|
+
}),
|
|
179
|
+
);
|
|
180
|
+
|
|
181
|
+
expect($('.ons-section-nav__item--active .ons-section-nav__link').attr('aria-current')).toBe('location');
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
describe('nested anchor navigation items', () => {
|
|
185
|
+
it('renders anchor navigation list for top-level items that define `anchors`', () => {
|
|
186
|
+
const $ = cheerio.load(renderComponent('section-navigation', EXAMPLE_SECTION_NAVIGATION_VERTICAL));
|
|
187
|
+
|
|
188
|
+
expect($('.ons-section-nav__list > .ons-section-nav__item:nth-child(1) .ons-section-nav__sub-items').length).toBe(0);
|
|
189
|
+
expect($('.ons-section-nav__list > .ons-section-nav__item:nth-child(2) .ons-section-nav__sub-items').length).toBe(1);
|
|
190
|
+
expect($('.ons-section-nav__list > .ons-section-nav__item:nth-child(3) .ons-section-nav__sub-items').length).toBe(0);
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it('renders the expected anchor navigation items', () => {
|
|
194
|
+
const $ = cheerio.load(renderComponent('section-navigation', EXAMPLE_SECTION_NAVIGATION_VERTICAL));
|
|
195
|
+
|
|
196
|
+
const itemLabels = mapAll($('.ons-section-nav__sub-items .ons-section-nav__item .ons-section-nav__link'), node =>
|
|
197
|
+
node.text().trim(),
|
|
198
|
+
);
|
|
199
|
+
expect(itemLabels).toEqual(['Sub section 1', 'Sub section 2', 'Sub section 3']);
|
|
200
|
+
|
|
201
|
+
const itemLinks = mapAll($('.ons-section-nav__sub-items .ons-section-nav__item .ons-section-nav__link'), node => node.attr('href'));
|
|
202
|
+
expect(itemLinks).toEqual(['#sub-section-1', '#sub-section-2', '#sub-section-3']);
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
});
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
{% call onsField({
|
|
6
6
|
"id": params.fieldId,
|
|
7
|
-
"classes": params.
|
|
7
|
+
"classes": params.fieldClasses,
|
|
8
8
|
"legendClasses": params.legendClasses,
|
|
9
9
|
"dontWrap": params.dontWrap,
|
|
10
10
|
"error": params.error,
|
|
@@ -21,13 +21,13 @@
|
|
|
21
21
|
<select
|
|
22
22
|
id="{{ params.id }}"
|
|
23
23
|
name="{{ params.name }}"
|
|
24
|
-
class="ons-input ons-input--select{% if params.classes %} {{ params.classes }}{% endif %}{% if params.
|
|
24
|
+
class="ons-input ons-input--select{% if params.classes %} {{ params.classes }}{% endif %}{% if params.error is defined and params.error %} ons-input--error{% endif %}"
|
|
25
25
|
{% if params.value is defined and params.value %}value="{{ params.value}}" {% endif %}
|
|
26
26
|
{% if params.attributes is defined and params.attributes %}{% for attribute, value in (params.attributes.items() if params.attributes is mapping and params.attributes.items else params.attributes) %}{{ attribute }}{% if value is defined and value %}="{{ value }}"{% endif %} {% endfor %}{% endif %}
|
|
27
27
|
>
|
|
28
28
|
{% for option in params.options %}
|
|
29
29
|
<option value="{{ option.value | default(option.text) }}"
|
|
30
|
-
{% if option.id is defined and option.id %}
|
|
30
|
+
{% if option.id is defined and option.id %}id="{{ option.id }}" {% endif %}
|
|
31
31
|
{% if option.selected is defined and option.selected %}selected {% endif %}
|
|
32
32
|
{% if option.disabled is defined and option.disabled %}disabled {% endif %}
|
|
33
33
|
{% if params.attributes is defined and params.attributes %}{% for attribute, value in option.attributes %}{{ attribute }}="{{ value }}"{% endfor %}{% endif %}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
/** @jest-environment jsdom */
|
|
2
|
+
|
|
3
|
+
import * as cheerio from 'cheerio';
|
|
4
|
+
|
|
5
|
+
import axe from '../../tests/helpers/axe';
|
|
6
|
+
import { mapAll } from '../../tests/helpers/cheerio';
|
|
7
|
+
import { renderComponent, templateFaker } from '../../tests/helpers/rendering';
|
|
8
|
+
|
|
9
|
+
const EXAMPLE_SELECT_MINIMAL = {
|
|
10
|
+
id: 'example-select',
|
|
11
|
+
name: 'example-select-name',
|
|
12
|
+
label: {
|
|
13
|
+
text: 'Label text',
|
|
14
|
+
description: 'Description text',
|
|
15
|
+
classes: 'extra-label-class',
|
|
16
|
+
},
|
|
17
|
+
options: [
|
|
18
|
+
{
|
|
19
|
+
text: 'First option',
|
|
20
|
+
value: 1,
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
id: 'second-option',
|
|
24
|
+
text: 'Second option',
|
|
25
|
+
value: 2,
|
|
26
|
+
selected: true,
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
text: 'Disabled option',
|
|
30
|
+
value: 3,
|
|
31
|
+
disabled: true,
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const EXAMPLE_SELECT = {
|
|
37
|
+
...EXAMPLE_SELECT_MINIMAL,
|
|
38
|
+
fieldId: 'example-select-field',
|
|
39
|
+
fieldClasses: 'extra-field-class',
|
|
40
|
+
legendClasses: 'extra-legend-class',
|
|
41
|
+
dontWrap: true,
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const EXAMPLE_SELECT_WITH_ERROR = {
|
|
45
|
+
...EXAMPLE_SELECT,
|
|
46
|
+
error: {
|
|
47
|
+
id: 'example-error',
|
|
48
|
+
text: 'Error text...',
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
describe('macro: select', () => {
|
|
53
|
+
it('passes jest-axe checks', async () => {
|
|
54
|
+
const $ = cheerio.load(renderComponent('select', EXAMPLE_SELECT));
|
|
55
|
+
|
|
56
|
+
const results = await axe($.html());
|
|
57
|
+
expect(results).toHaveNoViolations();
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('passes jest-axe checks when error is shown', async () => {
|
|
61
|
+
const $ = cheerio.load(renderComponent('select', EXAMPLE_SELECT_WITH_ERROR));
|
|
62
|
+
|
|
63
|
+
const results = await axe($.html());
|
|
64
|
+
expect(results).toHaveNoViolations();
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('provides expected parameters to the inner `field` component', () => {
|
|
68
|
+
const faker = templateFaker();
|
|
69
|
+
const fieldSpy = faker.spy('field');
|
|
70
|
+
|
|
71
|
+
cheerio.load(faker.renderComponent('select', EXAMPLE_SELECT));
|
|
72
|
+
|
|
73
|
+
expect(fieldSpy.occurrences[0]).toEqual({
|
|
74
|
+
id: 'example-select-field',
|
|
75
|
+
classes: 'extra-field-class',
|
|
76
|
+
legendClasses: 'extra-legend-class',
|
|
77
|
+
dontWrap: true,
|
|
78
|
+
error: undefined,
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('provides expected parameters to the inner `field` component when there is an error', () => {
|
|
83
|
+
const faker = templateFaker();
|
|
84
|
+
const fieldSpy = faker.spy('field');
|
|
85
|
+
|
|
86
|
+
cheerio.load(faker.renderComponent('select', EXAMPLE_SELECT_WITH_ERROR));
|
|
87
|
+
|
|
88
|
+
expect(fieldSpy.occurrences[0]).toEqual({
|
|
89
|
+
id: 'example-select-field',
|
|
90
|
+
classes: 'extra-field-class',
|
|
91
|
+
legendClasses: 'extra-legend-class',
|
|
92
|
+
dontWrap: true,
|
|
93
|
+
error: {
|
|
94
|
+
id: 'example-error',
|
|
95
|
+
text: 'Error text...',
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('provides expected parameters to the inner `label` component', () => {
|
|
101
|
+
const faker = templateFaker();
|
|
102
|
+
const labelSpy = faker.spy('label');
|
|
103
|
+
|
|
104
|
+
cheerio.load(faker.renderComponent('select', EXAMPLE_SELECT));
|
|
105
|
+
|
|
106
|
+
expect(labelSpy.occurrences[0]).toEqual({
|
|
107
|
+
for: 'example-select',
|
|
108
|
+
text: 'Label text',
|
|
109
|
+
description: 'Description text',
|
|
110
|
+
classes: 'extra-label-class',
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
describe('select element', () => {
|
|
115
|
+
it('has the provided `id` attribute', () => {
|
|
116
|
+
const $ = cheerio.load(renderComponent('select', EXAMPLE_SELECT));
|
|
117
|
+
|
|
118
|
+
expect($('select').attr('id')).toBe('example-select');
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('has the provided `name` attribute', () => {
|
|
122
|
+
const $ = cheerio.load(renderComponent('select', EXAMPLE_SELECT));
|
|
123
|
+
|
|
124
|
+
expect($('select').attr('name')).toBe('example-select-name');
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it('has additionally provided style classes', () => {
|
|
128
|
+
const $ = cheerio.load(
|
|
129
|
+
renderComponent('select', {
|
|
130
|
+
...EXAMPLE_SELECT,
|
|
131
|
+
classes: 'extra-class another-extra-class',
|
|
132
|
+
}),
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
expect($('select').hasClass('extra-class')).toBe(true);
|
|
136
|
+
expect($('select').hasClass('another-extra-class')).toBe(true);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it('has additionally provided `attributes`', () => {
|
|
140
|
+
const $ = cheerio.load(
|
|
141
|
+
renderComponent('select', {
|
|
142
|
+
...EXAMPLE_SELECT,
|
|
143
|
+
attributes: {
|
|
144
|
+
a: 123,
|
|
145
|
+
b: 456,
|
|
146
|
+
},
|
|
147
|
+
}),
|
|
148
|
+
);
|
|
149
|
+
|
|
150
|
+
expect($('select').attr('a')).toBe('123');
|
|
151
|
+
expect($('select').attr('b')).toBe('456');
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
describe('option element', () => {
|
|
155
|
+
it('has expected text', () => {
|
|
156
|
+
const $ = cheerio.load(renderComponent('select', EXAMPLE_SELECT));
|
|
157
|
+
|
|
158
|
+
const values = mapAll($('select > option'), node => node.text().trim());
|
|
159
|
+
expect(values).toEqual(['First option', 'Second option', 'Disabled option']);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it('has a provided `id` attribute', () => {
|
|
163
|
+
const $ = cheerio.load(renderComponent('select', EXAMPLE_SELECT));
|
|
164
|
+
|
|
165
|
+
const values = mapAll($('select > option'), node => node.attr('id'));
|
|
166
|
+
expect(values).toEqual([undefined, 'second-option', undefined]);
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it('marks the correct option as selected', () => {
|
|
170
|
+
const $ = cheerio.load(renderComponent('select', EXAMPLE_SELECT));
|
|
171
|
+
|
|
172
|
+
const values = mapAll($('select > option'), node => node.attr('selected'));
|
|
173
|
+
expect(values).toEqual([undefined, 'selected', undefined]);
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
it('marks the correct option as disabled', () => {
|
|
177
|
+
const $ = cheerio.load(renderComponent('select', EXAMPLE_SELECT));
|
|
178
|
+
|
|
179
|
+
const values = mapAll($('select > option'), node => node.attr('disabled'));
|
|
180
|
+
expect(values).toEqual([undefined, undefined, 'disabled']);
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it('has a provided `value` attribute', () => {
|
|
184
|
+
const $ = cheerio.load(renderComponent('select', EXAMPLE_SELECT));
|
|
185
|
+
|
|
186
|
+
const values = mapAll($('select > option'), node => node.attr('value'));
|
|
187
|
+
expect(values).toEqual(['1', '2', '3']);
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
it('uses option text as a default `value` attribute', () => {
|
|
191
|
+
const $ = cheerio.load(
|
|
192
|
+
renderComponent('select', {
|
|
193
|
+
...EXAMPLE_SELECT,
|
|
194
|
+
options: [{ text: 'First option' }, { text: 'Second option' }],
|
|
195
|
+
}),
|
|
196
|
+
);
|
|
197
|
+
|
|
198
|
+
const values = mapAll($('select > option'), node => node.attr('value'));
|
|
199
|
+
expect(values).toEqual(['First option', 'Second option']);
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
});
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { renderComponent, setTestPage } from '../../tests/helpers/rendering';
|
|
2
|
+
|
|
3
|
+
const EXAMPLE_LANGUAGE_FILTER_PAGE = `
|
|
4
|
+
<div class="ons-js-language-filter">
|
|
5
|
+
${renderComponent('select', {
|
|
6
|
+
classes: 'ons-js-language-filter__select',
|
|
7
|
+
id: 'language-filter-select',
|
|
8
|
+
options: [
|
|
9
|
+
{
|
|
10
|
+
text: 'Native language',
|
|
11
|
+
value: 'language-native',
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
text: 'English',
|
|
15
|
+
value: 'language-english',
|
|
16
|
+
},
|
|
17
|
+
],
|
|
18
|
+
})}
|
|
19
|
+
<div class="ons-js-language-filter__content" id="language-native"></div>
|
|
20
|
+
<div class="ons-js-language-filter__content ons-u-hidden" id="language-english"></div>
|
|
21
|
+
</div>
|
|
22
|
+
`;
|
|
23
|
+
|
|
24
|
+
describe('script: select', () => {
|
|
25
|
+
beforeEach(async () => {
|
|
26
|
+
await setTestPage('/test', EXAMPLE_LANGUAGE_FILTER_PAGE);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
describe('language filter page with multiple views', () => {
|
|
30
|
+
it('shows first view by default', async () => {
|
|
31
|
+
const isFirstHidden = await page.$eval('#language-native', node => node.classList.contains('ons-u-hidden'));
|
|
32
|
+
expect(isFirstHidden).toBe(false);
|
|
33
|
+
const isSecondHidden = await page.$eval('#language-english', node => node.classList.contains('ons-u-hidden'));
|
|
34
|
+
expect(isSecondHidden).toBe(true);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('shows second view when selection is changed to the second item', async () => {
|
|
38
|
+
await page.select('#language-filter-select', 'language-english');
|
|
39
|
+
|
|
40
|
+
const isFirstHidden = await page.$eval('#language-native', node => node.classList.contains('ons-u-hidden'));
|
|
41
|
+
expect(isFirstHidden).toBe(true);
|
|
42
|
+
const isSecondHidden = await page.$eval('#language-english', node => node.classList.contains('ons-u-hidden'));
|
|
43
|
+
expect(isSecondHidden).toBe(false);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('shows first view when selection is changed back to the first item', async () => {
|
|
47
|
+
await page.select('#language-filter-select', 'language-english');
|
|
48
|
+
await page.select('#language-filter-select', 'language-native');
|
|
49
|
+
|
|
50
|
+
const isFirstHidden = await page.$eval('#language-native', node => node.classList.contains('ons-u-hidden'));
|
|
51
|
+
expect(isFirstHidden).toBe(false);
|
|
52
|
+
const isSecondHidden = await page.$eval('#language-english', node => node.classList.contains('ons-u-hidden'));
|
|
53
|
+
expect(isSecondHidden).toBe(true);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
});
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
{% if params.facebook is defined and params.facebook and params.facebook == true %}
|
|
9
9
|
{% set facebook =
|
|
10
10
|
{
|
|
11
|
-
"url": 'https://www.facebook.com/sharer/sharer.php?u=' ~ params.pageURL,
|
|
11
|
+
"url": 'https://www.facebook.com/sharer/sharer.php?u=' ~ params.pageURL|urlencode,
|
|
12
12
|
"text": 'Facebook',
|
|
13
13
|
"iconType": 'facebook',
|
|
14
14
|
"rel": 'noreferrer external',
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
{% if params.twitter is defined and params.twitter and params.twitter == true %}
|
|
22
22
|
{% set twitter =
|
|
23
23
|
{
|
|
24
|
-
"url": 'https://twitter.com/intent/tweet?original_referer&text=' ~ params.pageTitle ~ '&url=' ~ params.pageURL,
|
|
24
|
+
"url": 'https://twitter.com/intent/tweet?original_referer&text=' ~ params.pageTitle|urlencode ~ '&url=' ~ params.pageURL|urlencode,
|
|
25
25
|
"text": 'Twitter',
|
|
26
26
|
"iconType": 'twitter',
|
|
27
27
|
"rel": 'noreferrer external',
|