@scottish-government/designsystem-react 0.6.0 → 0.7.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/@types/components/Accordion.d.ts +2 -2
- package/@types/components/ConfirmationMessage.d.ts +1 -1
- package/@types/components/NotificationPanel.d.ts +1 -1
- package/@types/components/SummaryCard.d.ts +1 -1
- package/@types/components/Tabs.d.ts +1 -1
- package/@types/sgds.d.ts +1 -1
- package/CHANGELOG.md +81 -0
- package/README.md +4 -0
- package/dist/common/AbstractNotificationBanner.jsx +63 -0
- package/dist/common/ConditionalWrapper.jsx +8 -0
- package/dist/common/FileIcon.jsx +51 -0
- package/dist/common/HintText.jsx +9 -0
- package/dist/common/Icon.jsx +57 -0
- package/dist/common/ScreenReaderText.jsx +9 -0
- package/dist/common/WrapperTag.jsx +11 -0
- package/dist/components/Accordion/Accordion.jsx +102 -0
- package/dist/components/AspectBox/AspectBox.jsx +79 -0
- package/dist/components/BackToTop/BackToTop.jsx +27 -0
- package/dist/components/Breadcrumbs/Breadcrumbs.jsx +28 -0
- package/dist/components/Button/Button.jsx +30 -0
- package/dist/components/Checkbox/Checkbox.jsx +62 -0
- package/dist/components/ConfirmationMessage/ConfirmationMessage.jsx +24 -0
- package/dist/components/ContentsNav/ContentsNav.jsx +33 -0
- package/dist/components/CookieBanner/CookieBanner.jsx +21 -0
- package/dist/components/DatePicker/DatePicker.jsx +54 -0
- package/dist/components/Details/Details.jsx +17 -0
- package/dist/components/ErrorMessage/ErrorMessage.jsx +12 -0
- package/dist/components/ErrorSummary/ErrorSummary.jsx +27 -0
- package/dist/components/FileDownload/FileDownload.jsx +50 -0
- package/dist/components/HideThisPage/HideThisPage.jsx +71 -0
- package/dist/components/InsetText/InsetText.jsx +14 -0
- package/dist/components/NotificationBanner/NotificationBanner.jsx +26 -0
- package/dist/components/NotificationPanel/NotificationPanel.jsx +21 -0
- package/dist/components/PageHeader/PageHeader.jsx +15 -0
- package/dist/components/PageMetadata/PageMetadata.jsx +26 -0
- package/dist/components/Pagination/Pagination.jsx +97 -0
- package/dist/components/PhaseBanner/PhaseBanner.jsx +23 -0
- package/dist/components/Question/Question.jsx +22 -0
- package/dist/components/RadioButton/RadioButton.jsx +43 -0
- package/dist/components/Select/Select.jsx +52 -0
- package/dist/components/SequentialNavigation/SequentialNavigation.jsx +31 -0
- package/dist/components/SideNavigation/SideNavigation.jsx +52 -0
- package/dist/components/SiteHeader/SiteHeader.jsx +68 -0
- package/dist/components/SiteNavigation/SiteNavigation.jsx +22 -0
- package/dist/components/SiteSearch/SiteSearch.jsx +55 -0
- package/dist/components/SkipLinks/SkipLinks.jsx +21 -0
- package/dist/components/SummaryCard/SummaryCard.jsx +67 -0
- package/dist/components/SummaryList/SummaryList.jsx +75 -0
- package/dist/components/Table/Table.jsx +24 -0
- package/dist/components/Tabs/Tabs.jsx +99 -0
- package/dist/components/Tag/Tag.jsx +13 -0
- package/dist/components/TaskList/TaskList.jsx +95 -0
- package/dist/components/TextInput/TextInput.jsx +58 -0
- package/dist/components/Textarea/Textarea.jsx +54 -0
- package/dist/components/WarningText/WarningText.jsx +16 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/common/{abstract-notification-banner.test.tsx → AbstractNotificationBanner.test.tsx} +11 -11
- package/src/common/{abstract-notification-banner.tsx → AbstractNotificationBanner.tsx} +2 -2
- package/src/common/{conditional-wrapper.test.tsx → ConditionalWrapper.test.tsx} +1 -1
- package/src/common/{file-icon.test.tsx → FileIcon.test.tsx} +10 -10
- package/src/common/{hint-text.test.tsx → HintText.test.tsx} +12 -12
- package/src/common/{icon.test.tsx → Icon.test.tsx} +16 -16
- package/src/common/{screen-reader-text.test.tsx → ScreenReaderText.test.tsx} +5 -5
- package/src/common/{wrapper-tag.test.tsx → WrapperTag.test.tsx} +5 -5
- package/src/components/{accordion/accordion.test.tsx → Accordion/Accordion.test.tsx} +35 -35
- package/src/components/{accordion/accordion.tsx → Accordion/Accordion.tsx} +5 -5
- package/src/components/{aspect-box/aspect-box.test.tsx → AspectBox/AspectBox.test.tsx} +2 -2
- package/src/components/{back-to-top/back-to-top.test.tsx → BackToTop/BackToTop.test.tsx} +1 -1
- package/src/components/{back-to-top/back-to-top.tsx → BackToTop/BackToTop.tsx} +1 -1
- package/src/components/{breadcrumbs/breadcrumbs.test.tsx → Breadcrumbs/Breadcrumbs.test.tsx} +7 -7
- package/src/components/{button/button.test.tsx → Button/Button.test.tsx} +1 -1
- package/src/components/{button/button.tsx → Button/Button.tsx} +3 -3
- package/src/components/{checkbox/checkbox.test.tsx → Checkbox/Checkbox.test.tsx} +16 -16
- package/src/components/{checkbox/checkbox.tsx → Checkbox/Checkbox.tsx} +1 -1
- package/src/components/{confirmation-message/confirmation-message.test.tsx → ConfirmationMessage/ConfirmationMessage.test.tsx} +12 -14
- package/src/components/{confirmation-message/confirmation-message.tsx → ConfirmationMessage/ConfirmationMessage.tsx} +4 -4
- package/src/components/{contents-nav/contents-nav.test.tsx → ContentsNav/ContentsNav.test.tsx} +21 -28
- package/src/components/{contents-nav/contents-nav.tsx → ContentsNav/ContentsNav.tsx} +1 -1
- package/src/components/{cookie-banner/cookie-banner.test.tsx → CookieBanner/CookieBanner.test.tsx} +3 -3
- package/src/components/{cookie-banner/cookie-banner.tsx → CookieBanner/CookieBanner.tsx} +1 -1
- package/src/components/{date-picker/date-picker.test.tsx → DatePicker/DatePicker.test.tsx} +76 -66
- package/src/components/{date-picker/date-picker.tsx → DatePicker/DatePicker.tsx} +2 -2
- package/src/components/{details/details.test.tsx → Details/Details.test.tsx} +10 -10
- package/src/components/{error-message/error-message.test.tsx → ErrorMessage/ErrorMessage.test.tsx} +10 -10
- package/src/components/{error-summary/error-summary.test.tsx → ErrorSummary/ErrorSummary.test.tsx} +13 -14
- package/src/components/{error-summary/error-summary.tsx → ErrorSummary/ErrorSummary.tsx} +1 -1
- package/src/components/{file-download/file-download.test.tsx → FileDownload/FileDownload.test.tsx} +21 -21
- package/src/components/{file-download/file-download.tsx → FileDownload/FileDownload.tsx} +1 -1
- package/src/components/{hide-this-page/hide-this-page.test.tsx → HideThisPage/HideThisPage.test.tsx} +4 -4
- package/src/components/{hide-this-page/hide-this-page.tsx → HideThisPage/HideThisPage.tsx} +3 -3
- package/src/components/{inset-text/inset-text.test.tsx → InsetText/InsetText.test.tsx} +1 -1
- package/src/components/{notification-banner/notification-banner.test.tsx → NotificationBanner/NotificationBanner.test.tsx} +4 -4
- package/src/components/{notification-banner/notification-banner.tsx → NotificationBanner/NotificationBanner.tsx} +1 -1
- package/src/components/{notification-panel/notification-panel.test.tsx → NotificationPanel/NotificationPanel.test.tsx} +24 -23
- package/src/components/{notification-panel/notification-panel.tsx → NotificationPanel/NotificationPanel.tsx} +3 -3
- package/src/components/{page-header/page-header.test.tsx → PageHeader/PageHeader.test.tsx} +9 -9
- package/src/components/{page-metadata/page-metadata.test.tsx → PageMetadata/PageMetadata.test.tsx} +9 -9
- package/src/components/{pagination/pagination.test.tsx → Pagination/Pagination.test.tsx} +56 -56
- package/src/components/{pagination/pagination.tsx → Pagination/Pagination.tsx} +1 -1
- package/src/components/{phase-banner/phase-banner.test.tsx → PhaseBanner/PhaseBanner.test.tsx} +9 -9
- package/src/components/{phase-banner/phase-banner.tsx → PhaseBanner/PhaseBanner.tsx} +1 -1
- package/src/components/{question/question.test.tsx → Question/Question.test.tsx} +10 -10
- package/src/components/{question/question.tsx → Question/Question.tsx} +3 -3
- package/src/components/{radio-button/radio-button.test.tsx → RadioButton/RadioButton.test.tsx} +23 -23
- package/src/components/{radio-button/radio-button.tsx → RadioButton/RadioButton.tsx} +1 -1
- package/src/components/{select/select.test.tsx → Select/Select.test.tsx} +67 -64
- package/src/components/{select/select.tsx → Select/Select.tsx} +2 -2
- package/src/components/{sequential-navigation/sequential-navigation.test.tsx → SequentialNavigation/SequentialNavigation.test.tsx} +18 -18
- package/src/components/{side-navigation/side-navigation.test.tsx → SideNavigation/SideNavigation.test.tsx} +8 -8
- package/src/components/{site-header/site-header.test.tsx → SiteHeader/SiteHeader.test.tsx} +25 -25
- package/src/components/{site-header/site-header.tsx → SiteHeader/SiteHeader.tsx} +4 -4
- package/src/components/{site-navigation/site-navigation.test.tsx → SiteNavigation/SiteNavigation.test.tsx} +8 -8
- package/src/components/{site-search/site-search.test.tsx → SiteSearch/SiteSearch.test.tsx} +16 -16
- package/src/components/{site-search/site-search.tsx → SiteSearch/SiteSearch.tsx} +1 -1
- package/src/components/{skip-links/skip-links.test.tsx → SkipLinks/SkipLinks.test.tsx} +15 -15
- package/src/components/{summary-card/summary-card.test.tsx → SummaryCard/SummaryCard.test.tsx} +28 -28
- package/src/components/{summary-card/summary-card.tsx → SummaryCard/SummaryCard.tsx} +4 -4
- package/src/components/{summary-list/summary-list.test.tsx → SummaryList/SummaryList.test.tsx} +55 -56
- package/src/components/{summary-list/summary-list.tsx → SummaryList/SummaryList.tsx} +2 -2
- package/src/components/{table/table.test.tsx → Table/Table.test.tsx} +4 -4
- package/src/components/{tabs/tabs.test.tsx → Tabs/Tabs.test.tsx} +22 -42
- package/src/components/{tabs/tabs.tsx → Tabs/Tabs.tsx} +3 -3
- package/src/components/{tag/tag.test.tsx → Tag/Tag.test.tsx} +10 -10
- package/src/components/{task-list/task-list.test.tsx → TaskList/TaskList.test.tsx} +109 -108
- package/src/components/{task-list/task-list.tsx → TaskList/TaskList.tsx} +4 -4
- package/src/components/{text-input/text-input.test.tsx → TextInput/TextInput.test.tsx} +92 -87
- package/src/components/{text-input/text-input.tsx → TextInput/TextInput.tsx} +4 -4
- package/src/components/{textarea/textarea.test.tsx → Textarea/Textarea.test.tsx} +71 -67
- package/src/components/{textarea/textarea.tsx → Textarea/Textarea.tsx} +3 -3
- package/src/components/{warning-text/warning-text.test.tsx → WarningText/WarningText.test.tsx} +1 -1
- /package/src/common/{conditional-wrapper.tsx → ConditionalWrapper.tsx} +0 -0
- /package/src/common/{file-icon.tsx → FileIcon.tsx} +0 -0
- /package/src/common/{hint-text.tsx → HintText.tsx} +0 -0
- /package/src/common/{icon.tsx → Icon.tsx} +0 -0
- /package/src/common/{screen-reader-text.tsx → ScreenReaderText.tsx} +0 -0
- /package/src/common/{wrapper-tag.tsx → WrapperTag.tsx} +0 -0
- /package/src/components/{aspect-box/aspect-box.tsx → AspectBox/AspectBox.tsx} +0 -0
- /package/src/components/{breadcrumbs/breadcrumbs.tsx → Breadcrumbs/Breadcrumbs.tsx} +0 -0
- /package/src/components/{details/details.tsx → Details/Details.tsx} +0 -0
- /package/src/components/{error-message/error-message.tsx → ErrorMessage/ErrorMessage.tsx} +0 -0
- /package/src/components/{inset-text/inset-text.tsx → InsetText/InsetText.tsx} +0 -0
- /package/src/components/{page-header/page-header.tsx → PageHeader/PageHeader.tsx} +0 -0
- /package/src/components/{page-metadata/page-metadata.tsx → PageMetadata/PageMetadata.tsx} +0 -0
- /package/src/components/{sequential-navigation/sequential-navigation.tsx → SequentialNavigation/SequentialNavigation.tsx} +0 -0
- /package/src/components/{side-navigation/side-navigation.tsx → SideNavigation/SideNavigation.tsx} +0 -0
- /package/src/components/{site-navigation/site-navigation.tsx → SiteNavigation/SiteNavigation.tsx} +0 -0
- /package/src/components/{skip-links/skip-links.tsx → SkipLinks/SkipLinks.tsx} +0 -0
- /package/src/components/{table/table.tsx → Table/Table.tsx} +0 -0
- /package/src/components/{tag/tag.tsx → Tag/Tag.tsx} +0 -0
- /package/src/components/{warning-text/warning-text.tsx → WarningText/WarningText.tsx} +0 -0
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { test, expect, vi } from 'vitest';
|
|
2
2
|
import { render, screen, within } from '@testing-library/react';
|
|
3
|
-
import SiteSearch from './
|
|
3
|
+
import SiteSearch from './SiteSearch';
|
|
4
4
|
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
5
|
+
const SITE_SEARCH_ID = 'site-search';
|
|
6
|
+
const LABEL_TEXT = 'Search';
|
|
7
|
+
const PLACEHOLDER_TEXT = 'Search';
|
|
8
8
|
|
|
9
9
|
test('site search renders correctly', () => {
|
|
10
10
|
render(
|
|
@@ -26,17 +26,17 @@ test('site search renders correctly', () => {
|
|
|
26
26
|
expect(searchForm).toHaveAttribute('method', 'GET');
|
|
27
27
|
expect(searchForm).toHaveAttribute('action', '/search');
|
|
28
28
|
|
|
29
|
-
expect(searchLabel?.textContent).toEqual(
|
|
30
|
-
expect(searchLabel).toHaveAttribute('for',
|
|
31
|
-
expect(searchLabel).toHaveAttribute('id', `${
|
|
29
|
+
expect(searchLabel?.textContent).toEqual(LABEL_TEXT);
|
|
30
|
+
expect(searchLabel).toHaveAttribute('for', SITE_SEARCH_ID);
|
|
31
|
+
expect(searchLabel).toHaveAttribute('id', `${SITE_SEARCH_ID}-label`);
|
|
32
32
|
expect(searchLabel).toHaveClass('ds_label', 'visually-hidden');
|
|
33
33
|
|
|
34
34
|
expect(inputWrapper).toHaveClass('ds_input__wrapper ds_input__wrapper--has-icon');
|
|
35
35
|
expect(inputWrapper?.tagName).toEqual('DIV');
|
|
36
36
|
|
|
37
37
|
expect(searchInput).toHaveClass('ds_input', 'ds_site-search__input');
|
|
38
|
-
expect(searchInput).toHaveAttribute('id',
|
|
39
|
-
expect(searchInput).toHaveAttribute('placeholder',
|
|
38
|
+
expect(searchInput).toHaveAttribute('id', SITE_SEARCH_ID);
|
|
39
|
+
expect(searchInput).toHaveAttribute('placeholder', PLACEHOLDER_TEXT);
|
|
40
40
|
expect(searchInput).toHaveAttribute('required');
|
|
41
41
|
expect(searchInput).toHaveAttribute('spellcheck', 'false');
|
|
42
42
|
expect(searchInput).toHaveAttribute('type', 'search');
|
|
@@ -102,13 +102,13 @@ test('custom placeholder', () => {
|
|
|
102
102
|
});
|
|
103
103
|
|
|
104
104
|
test('autocomplete', () => {
|
|
105
|
-
const
|
|
106
|
-
const
|
|
105
|
+
const AUTOCOMPLETE_SUGGESTION_MAPPING_FUNCTION = vi.fn();
|
|
106
|
+
const SUGGESTIONS_ID = 'autocomplete-suggestions';
|
|
107
107
|
|
|
108
108
|
render(
|
|
109
109
|
<SiteSearch
|
|
110
110
|
autocompleteEndpoint="/endpoint"
|
|
111
|
-
autocompleteSuggestionMappingFunction={
|
|
111
|
+
autocompleteSuggestionMappingFunction={AUTOCOMPLETE_SUGGESTION_MAPPING_FUNCTION}
|
|
112
112
|
/>
|
|
113
113
|
)
|
|
114
114
|
|
|
@@ -120,7 +120,7 @@ test('autocomplete', () => {
|
|
|
120
120
|
const suggestionsList = within(searchForm).getByRole('listbox');
|
|
121
121
|
|
|
122
122
|
expect(searchFormContainer).toHaveClass('ds_autocomplete');
|
|
123
|
-
expect(searchFormContainer).toHaveAttribute('id', `${
|
|
123
|
+
expect(searchFormContainer).toHaveAttribute('id', `${SITE_SEARCH_ID}-autocomplete`);
|
|
124
124
|
|
|
125
125
|
expect(autocompleteStatus).toBeInTheDocument();
|
|
126
126
|
expect(autocompleteStatus).toHaveClass('visually-hidden');
|
|
@@ -129,15 +129,15 @@ test('autocomplete', () => {
|
|
|
129
129
|
expect(autocompleteStatus.tagName).toEqual('DIV');
|
|
130
130
|
|
|
131
131
|
expect(searchInput).toHaveAttribute('aria-autocomplete', 'list');
|
|
132
|
-
expect(searchInput).toHaveAttribute('aria-owns',
|
|
132
|
+
expect(searchInput).toHaveAttribute('aria-owns', SUGGESTIONS_ID);
|
|
133
133
|
expect(searchInput).toHaveAttribute('autocomplete', 'off');
|
|
134
134
|
expect(searchInput).toHaveClass('js-autocomplete-input');
|
|
135
135
|
|
|
136
|
-
expect(suggestionsContainer).toHaveAttribute('id',
|
|
136
|
+
expect(suggestionsContainer).toHaveAttribute('id', SUGGESTIONS_ID);
|
|
137
137
|
expect(suggestionsContainer?.tagName).toEqual('DIV');
|
|
138
138
|
|
|
139
139
|
expect(suggestionsList).toHaveClass('ds_autocomplete__suggestions-list');
|
|
140
|
-
expect(suggestionsList).toHaveAttribute('aria-labelledby', `${
|
|
140
|
+
expect(suggestionsList).toHaveAttribute('aria-labelledby', `${SITE_SEARCH_ID}-label`);
|
|
141
141
|
expect(suggestionsList.tagName).toEqual('OL');
|
|
142
142
|
|
|
143
143
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useEffect, useRef } from 'react';
|
|
2
2
|
// @ts-ignore
|
|
3
3
|
import DSAutocomplete from '@scottish-government/design-system/src/components/autocomplete/autocomplete';
|
|
4
|
-
import Button from '../
|
|
4
|
+
import Button from '../Button/Button';
|
|
5
5
|
|
|
6
6
|
const SiteSearch: React.FC<SGDS.Component.SiteSearch> = function ({
|
|
7
7
|
action = '/search',
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { test, expect } from 'vitest';
|
|
2
2
|
import { render, screen, within } from '@testing-library/react';
|
|
3
|
-
import SkipLinks from './
|
|
3
|
+
import SkipLinks from './SkipLinks';
|
|
4
4
|
|
|
5
|
-
const
|
|
6
|
-
const
|
|
5
|
+
const MAIN_CONTENT_ID = 'main-content';
|
|
6
|
+
const LINK_TEXT = 'Skip to main content';
|
|
7
7
|
|
|
8
8
|
test('skip links renders correctly', () => {
|
|
9
9
|
render(
|
|
@@ -24,43 +24,43 @@ test('skip links renders correctly', () => {
|
|
|
24
24
|
expect(skipLinksListItem).toHaveClass('ds_skip-links__item');
|
|
25
25
|
|
|
26
26
|
expect(skipLinksLink).toHaveClass('ds_skip-links__link');
|
|
27
|
-
expect(skipLinksLink).toHaveAttribute('href', `#${
|
|
28
|
-
expect(skipLinksLink.textContent).toEqual(
|
|
27
|
+
expect(skipLinksLink).toHaveAttribute('href', `#${MAIN_CONTENT_ID}`);
|
|
28
|
+
expect(skipLinksLink.textContent).toEqual(LINK_TEXT);
|
|
29
29
|
});
|
|
30
30
|
|
|
31
31
|
test('custom link text', () => {
|
|
32
|
-
const
|
|
32
|
+
const MAIN_LINK_TEXT = 'foo';
|
|
33
33
|
|
|
34
34
|
render(
|
|
35
|
-
<SkipLinks mainLinkText={
|
|
35
|
+
<SkipLinks mainLinkText={MAIN_LINK_TEXT} />
|
|
36
36
|
);
|
|
37
37
|
|
|
38
38
|
const skipLinksList = screen.getByRole('list');
|
|
39
39
|
const skipLinksLink = within(skipLinksList).getByRole('link');
|
|
40
40
|
|
|
41
|
-
expect(skipLinksLink.textContent).toEqual(
|
|
41
|
+
expect(skipLinksLink.textContent).toEqual(MAIN_LINK_TEXT);
|
|
42
42
|
});
|
|
43
43
|
|
|
44
44
|
test('custom link target', () => {
|
|
45
|
-
const
|
|
45
|
+
const CUSTOM_ID = 'bar'
|
|
46
46
|
|
|
47
47
|
render(
|
|
48
|
-
<SkipLinks mainContentId={
|
|
48
|
+
<SkipLinks mainContentId={CUSTOM_ID} />
|
|
49
49
|
);
|
|
50
50
|
|
|
51
51
|
const skipLinksList = screen.getByRole('list');
|
|
52
52
|
const skipLinksLink = within(skipLinksList).getByRole('link');
|
|
53
53
|
|
|
54
|
-
expect(skipLinksLink).toHaveAttribute('href', `#${
|
|
54
|
+
expect(skipLinksLink).toHaveAttribute('href', `#${CUSTOM_ID}`)
|
|
55
55
|
});
|
|
56
56
|
|
|
57
57
|
test('additional links', () => {
|
|
58
|
-
const
|
|
58
|
+
const ITEMS = [
|
|
59
59
|
{ title: 'foo', targetId: 'bar' }
|
|
60
60
|
];
|
|
61
61
|
|
|
62
62
|
render(
|
|
63
|
-
<SkipLinks items={
|
|
63
|
+
<SkipLinks items={ITEMS} />
|
|
64
64
|
);
|
|
65
65
|
|
|
66
66
|
const skipLinksList = screen.getByRole('list');
|
|
@@ -68,8 +68,8 @@ test('additional links', () => {
|
|
|
68
68
|
const skipLinksSecondLink = within(skipLinksList).getAllByRole('link')[1];
|
|
69
69
|
|
|
70
70
|
expect(skipLinksListItems.length).toEqual(2);
|
|
71
|
-
expect(skipLinksSecondLink).toHaveAttribute('href', `#${
|
|
72
|
-
expect(skipLinksSecondLink.textContent).toEqual(
|
|
71
|
+
expect(skipLinksSecondLink).toHaveAttribute('href', `#${ITEMS[0].targetId}`);
|
|
72
|
+
expect(skipLinksSecondLink.textContent).toEqual(ITEMS[0].title);
|
|
73
73
|
})
|
|
74
74
|
|
|
75
75
|
test('passing additional props', () => {
|
package/src/components/{summary-card/summary-card.test.tsx → SummaryCard/SummaryCard.test.tsx}
RENAMED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import { test, expect, vi } from 'vitest';
|
|
2
2
|
import { render, screen, within, fireEvent } from '@testing-library/react';
|
|
3
|
-
import SummaryCard from './
|
|
4
|
-
import SummaryList from '../
|
|
3
|
+
import SummaryCard from './SummaryCard';
|
|
4
|
+
import SummaryList from '../SummaryList/SummaryList';
|
|
5
5
|
|
|
6
|
-
const
|
|
6
|
+
const ONCLICK_FUNCTION = vi.fn();
|
|
7
7
|
|
|
8
|
-
const
|
|
8
|
+
const ACTIONS = [
|
|
9
9
|
{
|
|
10
10
|
title: 'Change',
|
|
11
11
|
href: '#foo'
|
|
12
12
|
},
|
|
13
13
|
{
|
|
14
14
|
title: 'Delete',
|
|
15
|
-
onclick:
|
|
15
|
+
onclick: ONCLICK_FUNCTION
|
|
16
16
|
}
|
|
17
17
|
];
|
|
18
18
|
|
|
19
|
-
const
|
|
19
|
+
const ITEMS = [
|
|
20
20
|
{
|
|
21
21
|
title: 'Phone number',
|
|
22
22
|
value: '0123 456 7890'
|
|
@@ -27,19 +27,21 @@ const items = [
|
|
|
27
27
|
}
|
|
28
28
|
];
|
|
29
29
|
|
|
30
|
-
const
|
|
30
|
+
const TITLE_TEXT = 'Joe Bloggs';
|
|
31
31
|
|
|
32
32
|
test('summary card renders correctly', () => {
|
|
33
|
+
const DESCRIBEDBY_ID = 'summary-card-joe-bloggs';
|
|
34
|
+
|
|
33
35
|
render(
|
|
34
36
|
<>
|
|
35
37
|
<SummaryCard
|
|
36
38
|
data-testid="foo"
|
|
37
|
-
actions={
|
|
38
|
-
items={
|
|
39
|
-
title={
|
|
39
|
+
actions={ACTIONS}
|
|
40
|
+
items={ITEMS}
|
|
41
|
+
title={TITLE_TEXT}
|
|
40
42
|
/>
|
|
41
43
|
|
|
42
|
-
<SummaryList data-testid="bar" items={
|
|
44
|
+
<SummaryList data-testid="bar" items={ITEMS}/>
|
|
43
45
|
</>
|
|
44
46
|
);
|
|
45
47
|
|
|
@@ -52,20 +54,18 @@ test('summary card renders correctly', () => {
|
|
|
52
54
|
const thisList = within(content).getByRole('list');
|
|
53
55
|
const comparisonList = screen.getByTestId('bar');
|
|
54
56
|
|
|
55
|
-
const describedById = 'summary-card-joe-bloggs';
|
|
56
|
-
|
|
57
57
|
expect(summaryCard).toHaveClass('ds_summary-card');
|
|
58
58
|
|
|
59
59
|
expect(header).toHaveClass('ds_summary-card__header');
|
|
60
60
|
expect(header?.tagName).toEqual('DIV');
|
|
61
61
|
|
|
62
62
|
expect(title).toHaveClass('ds_summary-card__header-title');
|
|
63
|
-
expect(title).toHaveAttribute('id',
|
|
63
|
+
expect(title).toHaveAttribute('id', DESCRIBEDBY_ID);
|
|
64
64
|
expect(title?.tagName).toEqual('H3');
|
|
65
|
-
expect(title.textContent).toEqual(
|
|
65
|
+
expect(title.textContent).toEqual(TITLE_TEXT);
|
|
66
66
|
|
|
67
67
|
expect(actionsList?.tagName).toEqual('UL');
|
|
68
|
-
expect(actionsList.children.length).toEqual(
|
|
68
|
+
expect(actionsList.children.length).toEqual(ACTIONS.length);
|
|
69
69
|
expect(actionsList.children[0]).toHaveClass('ds_summary-card__actions-list-item');
|
|
70
70
|
expect(actionsList.children[0].tagName).toEqual('LI');
|
|
71
71
|
expect(actionsList.children[0].innerHTML).toEqual('<a aria-describedby="summary-card-joe-bloggs" class="ds_link" href="#foo">Change</a>');
|
|
@@ -73,7 +73,7 @@ test('summary card renders correctly', () => {
|
|
|
73
73
|
|
|
74
74
|
fireEvent.click(actionsList.children[1].children[0]);
|
|
75
75
|
|
|
76
|
-
expect(
|
|
76
|
+
expect(ONCLICK_FUNCTION).toHaveBeenCalled();
|
|
77
77
|
|
|
78
78
|
expect(content).toHaveClass('ds_summary-card__content');
|
|
79
79
|
expect(content?.tagName).toEqual('DIV');
|
|
@@ -81,14 +81,14 @@ test('summary card renders correctly', () => {
|
|
|
81
81
|
expect(thisList?.innerHTML).toEqual(comparisonList?.innerHTML);
|
|
82
82
|
});
|
|
83
83
|
|
|
84
|
-
test('custom
|
|
84
|
+
test('custom heading level', () => {
|
|
85
85
|
render(
|
|
86
86
|
<SummaryCard
|
|
87
87
|
data-testid="foo"
|
|
88
|
-
actions={
|
|
89
|
-
|
|
90
|
-
items={
|
|
91
|
-
title={
|
|
88
|
+
actions={ACTIONS}
|
|
89
|
+
headingLevel="h2"
|
|
90
|
+
items={ITEMS}
|
|
91
|
+
title={TITLE_TEXT}
|
|
92
92
|
/>
|
|
93
93
|
);
|
|
94
94
|
|
|
@@ -102,9 +102,9 @@ test('passing additional props', () => {
|
|
|
102
102
|
render(
|
|
103
103
|
<SummaryCard
|
|
104
104
|
data-testid="foo"
|
|
105
|
-
actions={
|
|
106
|
-
items={
|
|
107
|
-
title={
|
|
105
|
+
actions={ACTIONS}
|
|
106
|
+
items={ITEMS}
|
|
107
|
+
title={TITLE_TEXT}
|
|
108
108
|
data-test="foo"
|
|
109
109
|
/>
|
|
110
110
|
);
|
|
@@ -117,9 +117,9 @@ test('passing additional CSS classes', () => {
|
|
|
117
117
|
render(
|
|
118
118
|
<SummaryCard
|
|
119
119
|
data-testid="foo"
|
|
120
|
-
actions={
|
|
121
|
-
items={
|
|
122
|
-
title={
|
|
120
|
+
actions={ACTIONS}
|
|
121
|
+
items={ITEMS}
|
|
122
|
+
title={TITLE_TEXT}
|
|
123
123
|
className="foo"
|
|
124
124
|
/>
|
|
125
125
|
);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import SummaryList, { Action } from "../
|
|
2
|
-
import WrapperTag from "../../common/
|
|
1
|
+
import SummaryList, { Action } from "../SummaryList/SummaryList";
|
|
2
|
+
import WrapperTag from "../../common/WrapperTag";
|
|
3
3
|
|
|
4
4
|
function convertToSlug(string: string) {
|
|
5
5
|
return string.toLowerCase()
|
|
@@ -10,7 +10,7 @@ function convertToSlug(string: string) {
|
|
|
10
10
|
const SummaryCard: React.FC<SGDS.Component.SummaryCard> = ({
|
|
11
11
|
actions,
|
|
12
12
|
className,
|
|
13
|
-
|
|
13
|
+
headingLevel = 'h3',
|
|
14
14
|
items,
|
|
15
15
|
title,
|
|
16
16
|
...props
|
|
@@ -29,7 +29,7 @@ const SummaryCard: React.FC<SGDS.Component.SummaryCard> = ({
|
|
|
29
29
|
<WrapperTag
|
|
30
30
|
className="ds_summary-card__header-title"
|
|
31
31
|
id={describedById}
|
|
32
|
-
tagName={
|
|
32
|
+
tagName={headingLevel}
|
|
33
33
|
>{title}</WrapperTag>
|
|
34
34
|
|
|
35
35
|
<ul className="ds_summary-card__actions-list">
|
package/src/components/{summary-list/summary-list.test.tsx → SummaryList/SummaryList.test.tsx}
RENAMED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { test, expect, vi } from 'vitest';
|
|
2
2
|
import { render, screen, fireEvent } from '@testing-library/react';
|
|
3
|
-
import SummaryList, { Item, Action, Answer } from './
|
|
3
|
+
import SummaryList, { Item, Action, Answer } from './SummaryList';
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const ONCLICK_FUNCTION = vi.fn();
|
|
6
6
|
|
|
7
|
-
const
|
|
7
|
+
const SUMMARY_ITEMS = [
|
|
8
8
|
{
|
|
9
9
|
title: 'Name',
|
|
10
10
|
value: 'Jane Smith',
|
|
@@ -15,7 +15,7 @@ const items = [
|
|
|
15
15
|
},
|
|
16
16
|
{
|
|
17
17
|
title: 'Delete',
|
|
18
|
-
onclick:
|
|
18
|
+
onclick: ONCLICK_FUNCTION
|
|
19
19
|
}
|
|
20
20
|
]
|
|
21
21
|
},
|
|
@@ -50,7 +50,7 @@ const items = [
|
|
|
50
50
|
|
|
51
51
|
test('summary list renders correctly', () => {
|
|
52
52
|
render(
|
|
53
|
-
<SummaryList items={
|
|
53
|
+
<SummaryList items={SUMMARY_ITEMS} />
|
|
54
54
|
);
|
|
55
55
|
|
|
56
56
|
const summaryList = screen.getAllByRole('list')[0];
|
|
@@ -58,12 +58,12 @@ test('summary list renders correctly', () => {
|
|
|
58
58
|
|
|
59
59
|
expect(summaryList).toHaveClass('ds_summary-list');
|
|
60
60
|
expect(summaryList.tagName).toEqual('OL');
|
|
61
|
-
expect(summaryListItems.length).toEqual(
|
|
61
|
+
expect(summaryListItems.length).toEqual(SUMMARY_ITEMS.length);
|
|
62
62
|
});
|
|
63
63
|
|
|
64
64
|
test('summary list without border', () => {
|
|
65
65
|
render(
|
|
66
|
-
<SummaryList noBorder items={
|
|
66
|
+
<SummaryList noBorder items={SUMMARY_ITEMS} />
|
|
67
67
|
);
|
|
68
68
|
|
|
69
69
|
const summaryList = screen.getAllByRole('list')[0];
|
|
@@ -72,11 +72,13 @@ test('summary list without border', () => {
|
|
|
72
72
|
});
|
|
73
73
|
|
|
74
74
|
test('summary list item renders correctly', () => {
|
|
75
|
+
const DESCRIBEDBY_ID = 'q2-date-of-birth';
|
|
76
|
+
|
|
75
77
|
render(
|
|
76
78
|
<Item
|
|
77
|
-
actions={
|
|
78
|
-
title={
|
|
79
|
-
value={
|
|
79
|
+
actions={SUMMARY_ITEMS[1].actions}
|
|
80
|
+
title={SUMMARY_ITEMS[1].title}
|
|
81
|
+
value={SUMMARY_ITEMS[1].value}
|
|
80
82
|
/>
|
|
81
83
|
);
|
|
82
84
|
|
|
@@ -86,13 +88,11 @@ test('summary list item renders correctly', () => {
|
|
|
86
88
|
const answer = value?.children[0];
|
|
87
89
|
const actions = item.querySelector('.ds_summary-list__actions');
|
|
88
90
|
|
|
89
|
-
const describedById = 'q2-date-of-birth';
|
|
90
|
-
|
|
91
91
|
expect(item).toHaveClass('ds_summary-list__item');
|
|
92
92
|
|
|
93
93
|
expect(key?.tagName).toEqual('SPAN');
|
|
94
94
|
expect(key?.textContent).toEqual('Date of birth');
|
|
95
|
-
expect(key).toHaveAttribute('id',
|
|
95
|
+
expect(key).toHaveAttribute('id', DESCRIBEDBY_ID);
|
|
96
96
|
|
|
97
97
|
expect(value?.tagName).toEqual('SPAN');
|
|
98
98
|
|
|
@@ -101,15 +101,15 @@ test('summary list item renders correctly', () => {
|
|
|
101
101
|
|
|
102
102
|
expect(actions?.tagName).toEqual('DIV');
|
|
103
103
|
|
|
104
|
-
expect(actions?.querySelector('.ds_link')).toHaveAttribute('aria-describedby',
|
|
104
|
+
expect(actions?.querySelector('.ds_link')).toHaveAttribute('aria-describedby', DESCRIBEDBY_ID);
|
|
105
105
|
});
|
|
106
106
|
|
|
107
107
|
test('summary list item with multiple values', () => {
|
|
108
108
|
render(
|
|
109
109
|
<Item
|
|
110
|
-
actions={
|
|
111
|
-
title={
|
|
112
|
-
value={
|
|
110
|
+
actions={SUMMARY_ITEMS[3].actions}
|
|
111
|
+
title={SUMMARY_ITEMS[3].title}
|
|
112
|
+
value={SUMMARY_ITEMS[3].value}
|
|
113
113
|
/>
|
|
114
114
|
);
|
|
115
115
|
|
|
@@ -121,17 +121,17 @@ test('summary list item with multiple values', () => {
|
|
|
121
121
|
expect(valueList).toHaveClass('ds_no-bullets');
|
|
122
122
|
expect(valueList?.tagName).toEqual('UL');
|
|
123
123
|
|
|
124
|
-
expect(valueListItems?.length).toEqual(
|
|
124
|
+
expect(valueListItems?.length).toEqual(SUMMARY_ITEMS[3].value.length);
|
|
125
125
|
|
|
126
126
|
expect(valueListItems[0].tagName).toEqual('LI');
|
|
127
|
-
expect(valueListItems[0].innerHTML).toEqual(`<q class="ds_summary-list__answer">${
|
|
127
|
+
expect(valueListItems[0].innerHTML).toEqual(`<q class="ds_summary-list__answer">${SUMMARY_ITEMS[3].value[0]}</q>`);
|
|
128
128
|
});
|
|
129
129
|
|
|
130
130
|
test('summary list item with no value', () => {
|
|
131
131
|
render(
|
|
132
132
|
<Item
|
|
133
|
-
actions={
|
|
134
|
-
title={
|
|
133
|
+
actions={SUMMARY_ITEMS[3].actions}
|
|
134
|
+
title={SUMMARY_ITEMS[3].title}
|
|
135
135
|
/>
|
|
136
136
|
);
|
|
137
137
|
|
|
@@ -143,92 +143,91 @@ test('summary list item with no value', () => {
|
|
|
143
143
|
});
|
|
144
144
|
|
|
145
145
|
test('summary list item with multiple actions', () => {
|
|
146
|
-
const
|
|
147
|
-
const
|
|
148
|
-
const
|
|
146
|
+
const ITEM_TITLE = 'Name';
|
|
147
|
+
const ITEM_VALUE = 'Jane Smith';
|
|
148
|
+
const ITEM_ACTIONS = [
|
|
149
149
|
{
|
|
150
150
|
title: 'Change',
|
|
151
151
|
href: '#foo'
|
|
152
152
|
},
|
|
153
153
|
{
|
|
154
154
|
title: 'Delete',
|
|
155
|
-
onclick:
|
|
155
|
+
onclick: ONCLICK_FUNCTION
|
|
156
156
|
}
|
|
157
157
|
];
|
|
158
158
|
|
|
159
159
|
render(
|
|
160
160
|
<Item
|
|
161
|
-
actions={
|
|
162
|
-
title={
|
|
163
|
-
value={
|
|
161
|
+
actions={SUMMARY_ITEMS[0].actions}
|
|
162
|
+
title={ITEM_TITLE}
|
|
163
|
+
value={ITEM_VALUE}
|
|
164
164
|
/>
|
|
165
165
|
);
|
|
166
166
|
|
|
167
167
|
const item = screen.getAllByRole('listitem')[0];
|
|
168
168
|
const actionsElement = item.querySelector('.ds_summary-list__actions');
|
|
169
169
|
|
|
170
|
-
expect(actionsElement?.children.length).toEqual(
|
|
171
|
-
expect(actionsElement?.children[0].textContent).toEqual(
|
|
172
|
-
expect(actionsElement?.children[1].textContent).toEqual(
|
|
170
|
+
expect(actionsElement?.children.length).toEqual(ITEM_ACTIONS.length);
|
|
171
|
+
expect(actionsElement?.children[0].textContent).toEqual(ITEM_ACTIONS[0].title);
|
|
172
|
+
expect(actionsElement?.children[1].textContent).toEqual(ITEM_ACTIONS[1].title);
|
|
173
173
|
});
|
|
174
174
|
|
|
175
175
|
test('button action', () => {
|
|
176
|
-
const
|
|
177
|
-
const
|
|
178
|
-
const
|
|
179
|
-
const onClick = onClickFn;
|
|
176
|
+
const DESCRIBEDBY_ID = 'q1-name';
|
|
177
|
+
const ACTION_TITLE = 'Name';
|
|
178
|
+
const ACTION_ONCLICK = ONCLICK_FUNCTION;
|
|
180
179
|
|
|
181
180
|
render(
|
|
182
181
|
<Action
|
|
183
|
-
describedby={
|
|
184
|
-
href={
|
|
185
|
-
onclick={
|
|
186
|
-
title={
|
|
182
|
+
describedby={DESCRIBEDBY_ID}
|
|
183
|
+
href={undefined}
|
|
184
|
+
onclick={ACTION_ONCLICK}
|
|
185
|
+
title={ACTION_TITLE}
|
|
187
186
|
/>
|
|
188
187
|
);
|
|
189
188
|
|
|
190
189
|
const action = screen.getByRole('button');
|
|
191
190
|
|
|
192
191
|
expect(action).toHaveClass('ds_link');
|
|
193
|
-
expect(action).toHaveAttribute('aria-describedby',
|
|
192
|
+
expect(action).toHaveAttribute('aria-describedby', DESCRIBEDBY_ID);
|
|
194
193
|
expect(action).toHaveAttribute('type', 'button');
|
|
195
194
|
expect(action).not.toHaveAttribute('href');
|
|
196
195
|
expect(action.tagName).toEqual('BUTTON');
|
|
197
|
-
expect(action.textContent).toEqual(
|
|
196
|
+
expect(action.textContent).toEqual(ACTION_TITLE);
|
|
198
197
|
|
|
199
198
|
fireEvent.click(action);
|
|
200
199
|
|
|
201
|
-
expect(
|
|
200
|
+
expect(ONCLICK_FUNCTION).toHaveBeenCalled();
|
|
202
201
|
});
|
|
203
202
|
|
|
204
203
|
test('link action', () => {
|
|
205
|
-
const
|
|
206
|
-
const
|
|
207
|
-
const
|
|
208
|
-
const
|
|
204
|
+
const DESCRIBEDBY_ID = 'q1-name';
|
|
205
|
+
const ACTION_TITLE = 'Name';
|
|
206
|
+
const ACTION_HREF = "#foo"
|
|
207
|
+
const ACTION_ONCLICK = ONCLICK_FUNCTION;
|
|
209
208
|
|
|
210
209
|
render(
|
|
211
210
|
<Action
|
|
212
|
-
describedby={
|
|
213
|
-
href={
|
|
214
|
-
onclick={
|
|
215
|
-
title={
|
|
211
|
+
describedby={DESCRIBEDBY_ID}
|
|
212
|
+
href={ACTION_HREF}
|
|
213
|
+
onclick={ACTION_ONCLICK}
|
|
214
|
+
title={ACTION_TITLE}
|
|
216
215
|
/>
|
|
217
216
|
);
|
|
218
217
|
|
|
219
218
|
const action = screen.getByRole('link');
|
|
220
219
|
|
|
221
220
|
expect(action).toHaveClass('ds_link');
|
|
222
|
-
expect(action).toHaveAttribute('aria-describedby',
|
|
223
|
-
expect(action).toHaveAttribute('href',
|
|
221
|
+
expect(action).toHaveAttribute('aria-describedby', DESCRIBEDBY_ID);
|
|
222
|
+
expect(action).toHaveAttribute('href', ACTION_HREF);
|
|
224
223
|
expect(action).not.toHaveAttribute('type');
|
|
225
224
|
expect(action.tagName).toEqual('A');
|
|
226
|
-
expect(action.textContent).toEqual(
|
|
225
|
+
expect(action.textContent).toEqual(ACTION_TITLE);
|
|
227
226
|
});
|
|
228
227
|
|
|
229
228
|
test('multiline answer', () => {
|
|
230
229
|
render(
|
|
231
|
-
<Answer value={
|
|
230
|
+
<Answer value={SUMMARY_ITEMS[2].value} />
|
|
232
231
|
);
|
|
233
232
|
|
|
234
233
|
const answer = document.querySelector('.ds_summary-list__answer');
|
|
@@ -238,7 +237,7 @@ test('multiline answer', () => {
|
|
|
238
237
|
|
|
239
238
|
test('passing additional props', () => {
|
|
240
239
|
render(
|
|
241
|
-
<SummaryList data-test="foo" items={
|
|
240
|
+
<SummaryList data-test="foo" items={SUMMARY_ITEMS} />
|
|
242
241
|
);
|
|
243
242
|
|
|
244
243
|
const summaryList = screen.getAllByRole('list')[0];
|
|
@@ -247,7 +246,7 @@ test('passing additional props', () => {
|
|
|
247
246
|
|
|
248
247
|
test('passing additional CSS classes', () => {
|
|
249
248
|
render(
|
|
250
|
-
<SummaryList className="foo" items={
|
|
249
|
+
<SummaryList className="foo" items={SUMMARY_ITEMS} />
|
|
251
250
|
);
|
|
252
251
|
|
|
253
252
|
const summaryList = screen.getAllByRole('list')[0];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import ConditionalWrapper from '../../common/
|
|
2
|
-
import WrapperTag from '../../common/
|
|
1
|
+
import ConditionalWrapper from '../../common/ConditionalWrapper';
|
|
2
|
+
import WrapperTag from '../../common/WrapperTag';
|
|
3
3
|
|
|
4
4
|
function escapedNewLineToLineBreakTag (string: string) {
|
|
5
5
|
if (typeof string === 'string') {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { test, expect } from 'vitest';
|
|
2
2
|
import { render, screen } from '@testing-library/react';
|
|
3
|
-
import Table from './
|
|
3
|
+
import Table from './Table';
|
|
4
4
|
|
|
5
5
|
test('table renders correctly', () => {
|
|
6
6
|
render(
|
|
@@ -30,10 +30,10 @@ test('table renders correctly', () => {
|
|
|
30
30
|
});
|
|
31
31
|
|
|
32
32
|
test('table with smallscreen behaviour', () => {
|
|
33
|
-
const
|
|
33
|
+
const SMALL_SCREEN_BEHAVIOUR = 'scrolling';
|
|
34
34
|
|
|
35
35
|
render(
|
|
36
|
-
<Table smallscreen={
|
|
36
|
+
<Table smallscreen={SMALL_SCREEN_BEHAVIOUR}>
|
|
37
37
|
<caption>Public holidays in 2020</caption>
|
|
38
38
|
<thead>
|
|
39
39
|
<tr>
|
|
@@ -54,7 +54,7 @@ test('table with smallscreen behaviour', () => {
|
|
|
54
54
|
|
|
55
55
|
const table = screen.getByRole('table');
|
|
56
56
|
|
|
57
|
-
expect(table).toHaveAttribute('data-smallscreen',
|
|
57
|
+
expect(table).toHaveAttribute('data-smallscreen', SMALL_SCREEN_BEHAVIOUR);
|
|
58
58
|
expect(table.nodeName).toEqual('TABLE');
|
|
59
59
|
});
|
|
60
60
|
|