@scottish-government/designsystem-react 0.5.1 → 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/.svgrrc +2 -1
- package/.svgrrc_documents +15 -0
- package/@types/common/FileIcon.d.ts +7 -0
- package/@types/components/Accordion.d.ts +2 -2
- package/@types/components/ConfirmationMessage.d.ts +1 -1
- package/@types/components/FileDownload.d.ts +11 -0
- 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 +2 -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/common/file-icon.jsx +51 -0
- package/dist/common/icon.jsx +1 -1
- 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/components/file-download/file-download.jsx +50 -0
- package/dist/images/documents/audio.jsx +47 -0
- package/dist/images/documents/csv.jsx +57 -0
- package/dist/images/documents/excel.jsx +57 -0
- package/dist/images/documents/file.jsx +48 -0
- package/dist/images/documents/generic.jsx +47 -0
- package/dist/images/documents/geodata.jsx +44 -0
- package/dist/images/documents/ical.jsx +48 -0
- package/dist/images/documents/ico.jsx +48 -0
- package/dist/images/documents/image.jsx +43 -0
- package/dist/images/documents/index.js +50 -0
- package/dist/images/documents/odf.jsx +46 -0
- package/dist/images/documents/odg.jsx +46 -0
- package/dist/images/documents/odp.jsx +45 -0
- package/dist/images/documents/ods.jsx +55 -0
- package/dist/images/documents/odt.jsx +46 -0
- package/dist/images/documents/pdf.jsx +48 -0
- package/dist/images/documents/ppt.jsx +47 -0
- package/dist/images/documents/rtf.jsx +48 -0
- package/dist/images/documents/text.jsx +48 -0
- package/dist/images/documents/video.jsx +47 -0
- package/dist/images/documents/word.jsx +48 -0
- package/dist/images/documents/xml.jsx +48 -0
- package/dist/images/documents/zip.jsx +48 -0
- package/dist/images/icons/arrow_upward.jsx +41 -0
- package/dist/images/icons/calendar_today.jsx +41 -0
- package/dist/images/icons/cancel.jsx +40 -0
- package/dist/images/icons/check_circle.jsx +41 -0
- package/dist/images/icons/chevron_left.jsx +41 -0
- package/dist/images/icons/chevron_right.jsx +41 -0
- package/dist/images/icons/close.jsx +41 -0
- package/dist/images/icons/description.jsx +41 -0
- package/dist/images/icons/double_chevron_left.jsx +40 -0
- package/dist/images/icons/double_chevron_right.jsx +40 -0
- package/dist/images/icons/error.jsx +41 -0
- package/dist/images/icons/expand_less.jsx +41 -0
- package/dist/images/icons/expand_more.jsx +41 -0
- package/dist/images/icons/index.js +40 -0
- package/dist/images/icons/list.jsx +44 -0
- package/dist/images/icons/menu.jsx +41 -0
- package/dist/images/icons/priority_high.jsx +42 -0
- package/dist/images/icons/search.jsx +41 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -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/FileIcon.test.tsx +50 -0
- package/src/common/FileIcon.tsx +25 -0
- 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/{icon.tsx → Icon.tsx} +1 -1
- 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/FileDownload/FileDownload.test.tsx +167 -0
- package/src/components/FileDownload/FileDownload.tsx +67 -0
- 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/images/documents/audio.tsx +34 -0
- package/src/images/documents/csv.tsx +39 -0
- package/src/images/documents/excel.tsx +39 -0
- package/src/images/documents/file.tsx +30 -0
- package/src/images/documents/generic.tsx +26 -0
- package/src/images/documents/geodata.tsx +29 -0
- package/src/images/documents/ical.tsx +30 -0
- package/src/images/documents/ico.tsx +30 -0
- package/src/images/documents/image.tsx +25 -0
- package/src/images/documents/index.ts +22 -0
- package/src/images/documents/odf.tsx +28 -0
- package/src/images/documents/odg.tsx +28 -0
- package/src/images/documents/odp.tsx +33 -0
- package/src/images/documents/ods.tsx +37 -0
- package/src/images/documents/odt.tsx +28 -0
- package/src/images/documents/pdf.tsx +30 -0
- package/src/images/documents/ppt.tsx +28 -0
- package/src/images/documents/rtf.tsx +30 -0
- package/src/images/documents/text.tsx +30 -0
- package/src/images/documents/video.tsx +34 -0
- package/src/images/documents/word.tsx +30 -0
- package/src/images/documents/xml.tsx +30 -0
- package/src/images/documents/zip.tsx +30 -0
- package/src/images/icons/index.ts +17 -0
- package/vite.config.ts +1 -1
- package/src/icons/index.ts +0 -17
- /package/src/common/{conditional-wrapper.tsx → ConditionalWrapper.tsx} +0 -0
- /package/src/common/{hint-text.tsx → HintText.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
- /package/src/{icons/ArrowUpward.tsx → images/icons/arrow_upward.tsx} +0 -0
- /package/src/{icons/CalendarToday.tsx → images/icons/calendar_today.tsx} +0 -0
- /package/src/{icons/Cancel.tsx → images/icons/cancel.tsx} +0 -0
- /package/src/{icons/CheckCircle.tsx → images/icons/check_circle.tsx} +0 -0
- /package/src/{icons/ChevronLeft.tsx → images/icons/chevron_left.tsx} +0 -0
- /package/src/{icons/ChevronRight.tsx → images/icons/chevron_right.tsx} +0 -0
- /package/src/{icons/Close.tsx → images/icons/close.tsx} +0 -0
- /package/src/{icons/Description.tsx → images/icons/description.tsx} +0 -0
- /package/src/{icons/DoubleChevronLeft.tsx → images/icons/double_chevron_left.tsx} +0 -0
- /package/src/{icons/DoubleChevronRight.tsx → images/icons/double_chevron_right.tsx} +0 -0
- /package/src/{icons/Error.tsx → images/icons/error.tsx} +0 -0
- /package/src/{icons/ExpandLess.tsx → images/icons/expand_less.tsx} +0 -0
- /package/src/{icons/ExpandMore.tsx → images/icons/expand_more.tsx} +0 -0
- /package/src/{icons/List.tsx → images/icons/list.tsx} +0 -0
- /package/src/{icons/Menu.tsx → images/icons/menu.tsx} +0 -0
- /package/src/{icons/PriorityHigh.tsx → images/icons/priority_high.tsx} +0 -0
- /package/src/{icons/Search.tsx → images/icons/search.tsx} +0 -0
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { test, expect, vi } from 'vitest';
|
|
2
2
|
import { render, screen, fireEvent } from '@testing-library/react';
|
|
3
|
-
import Select from './
|
|
3
|
+
import Select from './Select';
|
|
4
4
|
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
5
|
+
const SELECT_ID = 'select-component';
|
|
6
|
+
const LABEL_TEXT = 'choose a component';
|
|
7
|
+
const OPTIONS = [
|
|
8
8
|
{
|
|
9
9
|
text: 'Accordion',
|
|
10
10
|
value: 'accordion'
|
|
@@ -22,9 +22,9 @@ const options = [
|
|
|
22
22
|
test('select renders correctly', () => {
|
|
23
23
|
render(
|
|
24
24
|
<Select
|
|
25
|
-
id={
|
|
26
|
-
label={
|
|
27
|
-
options={
|
|
25
|
+
id={SELECT_ID}
|
|
26
|
+
label={LABEL_TEXT}
|
|
27
|
+
options={OPTIONS}
|
|
28
28
|
/>
|
|
29
29
|
);
|
|
30
30
|
|
|
@@ -34,14 +34,14 @@ test('select renders correctly', () => {
|
|
|
34
34
|
const selectArrow = select.nextElementSibling;
|
|
35
35
|
|
|
36
36
|
expect(select).toHaveClass('ds_select');
|
|
37
|
-
expect(select.id).toEqual(
|
|
38
|
-
expect(select).toHaveAttribute('name',
|
|
37
|
+
expect(select.id).toEqual(SELECT_ID);
|
|
38
|
+
expect(select).toHaveAttribute('name', SELECT_ID);
|
|
39
39
|
|
|
40
40
|
expect(selectWrapper).toHaveClass('ds_select-wrapper');
|
|
41
41
|
expect(selectWrapper?.tagName).toEqual('DIV');
|
|
42
42
|
|
|
43
43
|
expect(label).toHaveClass('ds_label');
|
|
44
|
-
expect(label).toHaveAttribute('for',
|
|
44
|
+
expect(label).toHaveAttribute('for', SELECT_ID);
|
|
45
45
|
|
|
46
46
|
expect(selectArrow).toHaveClass('ds_select-arrow');
|
|
47
47
|
expect(selectArrow).toHaveAttribute('aria-hidden');
|
|
@@ -49,34 +49,34 @@ test('select renders correctly', () => {
|
|
|
49
49
|
});
|
|
50
50
|
|
|
51
51
|
test('select with width', () => {
|
|
52
|
-
const
|
|
52
|
+
const SELECTWIDTH = 'fixed-10';
|
|
53
53
|
|
|
54
54
|
render(
|
|
55
55
|
<Select
|
|
56
|
-
id={
|
|
57
|
-
label={
|
|
58
|
-
options={
|
|
59
|
-
width={
|
|
56
|
+
id={SELECT_ID}
|
|
57
|
+
label={LABEL_TEXT}
|
|
58
|
+
options={OPTIONS}
|
|
59
|
+
width={SELECTWIDTH}
|
|
60
60
|
/>
|
|
61
61
|
);
|
|
62
62
|
|
|
63
63
|
const selectWrapper = screen.getByRole('combobox').parentElement;
|
|
64
|
-
expect(selectWrapper).toHaveClass(`ds_input--${
|
|
64
|
+
expect(selectWrapper).toHaveClass(`ds_input--${SELECTWIDTH}`);
|
|
65
65
|
});
|
|
66
66
|
|
|
67
67
|
test('select with hint text', () => {
|
|
68
|
-
const
|
|
68
|
+
const HINT_TEXT = 'hint text';
|
|
69
69
|
|
|
70
70
|
render(
|
|
71
71
|
<Select
|
|
72
|
-
id={
|
|
73
|
-
label={
|
|
74
|
-
options={
|
|
75
|
-
hintText={
|
|
72
|
+
id={SELECT_ID}
|
|
73
|
+
label={LABEL_TEXT}
|
|
74
|
+
options={OPTIONS}
|
|
75
|
+
hintText={HINT_TEXT}
|
|
76
76
|
/>
|
|
77
77
|
);
|
|
78
78
|
|
|
79
|
-
const hintTextEl = screen.getByText(
|
|
79
|
+
const hintTextEl = screen.getByText(HINT_TEXT);
|
|
80
80
|
const select = screen.getByRole('combobox');
|
|
81
81
|
|
|
82
82
|
expect(hintTextEl).toBeInTheDocument();
|
|
@@ -84,29 +84,30 @@ test('select with hint text', () => {
|
|
|
84
84
|
});
|
|
85
85
|
|
|
86
86
|
test('select with custom name', () => {
|
|
87
|
-
const
|
|
87
|
+
const SELECT_NAME = 'foo';
|
|
88
88
|
|
|
89
89
|
render(
|
|
90
90
|
<Select
|
|
91
|
-
id={
|
|
92
|
-
label={
|
|
93
|
-
options={
|
|
94
|
-
name={
|
|
91
|
+
id={SELECT_ID}
|
|
92
|
+
label={LABEL_TEXT}
|
|
93
|
+
options={OPTIONS}
|
|
94
|
+
name={SELECT_NAME}
|
|
95
95
|
/>
|
|
96
96
|
);
|
|
97
97
|
|
|
98
98
|
const select = screen.getByRole('combobox');
|
|
99
|
-
expect(select).toHaveAttribute('name',
|
|
99
|
+
expect(select).toHaveAttribute('name', SELECT_NAME);
|
|
100
100
|
});
|
|
101
101
|
|
|
102
102
|
test('select with blur function', () => {
|
|
103
|
-
const
|
|
103
|
+
const ONBLUR_FUNCTION = vi.fn();
|
|
104
|
+
|
|
104
105
|
render(
|
|
105
106
|
<Select
|
|
106
|
-
id={
|
|
107
|
-
label={
|
|
108
|
-
options={
|
|
109
|
-
onBlur={
|
|
107
|
+
id={SELECT_ID}
|
|
108
|
+
label={LABEL_TEXT}
|
|
109
|
+
options={OPTIONS}
|
|
110
|
+
onBlur={ONBLUR_FUNCTION}
|
|
110
111
|
/>
|
|
111
112
|
);
|
|
112
113
|
|
|
@@ -114,17 +115,18 @@ test('select with blur function', () => {
|
|
|
114
115
|
|
|
115
116
|
fireEvent.blur(select);
|
|
116
117
|
|
|
117
|
-
expect(
|
|
118
|
+
expect(ONBLUR_FUNCTION).toHaveBeenCalled();
|
|
118
119
|
});
|
|
119
120
|
|
|
120
121
|
test('select with change function', () => {
|
|
121
|
-
const
|
|
122
|
+
const ONCHANGE_FUNCTION = vi.fn();
|
|
123
|
+
|
|
122
124
|
render(
|
|
123
125
|
<Select
|
|
124
|
-
id={
|
|
125
|
-
label={
|
|
126
|
-
options={
|
|
127
|
-
onChange={
|
|
126
|
+
id={SELECT_ID}
|
|
127
|
+
label={LABEL_TEXT}
|
|
128
|
+
options={OPTIONS}
|
|
129
|
+
onChange={ONCHANGE_FUNCTION}
|
|
128
130
|
/>
|
|
129
131
|
);
|
|
130
132
|
|
|
@@ -132,59 +134,60 @@ test('select with change function', () => {
|
|
|
132
134
|
|
|
133
135
|
fireEvent.change(select, {target: {value: 'button'}});
|
|
134
136
|
|
|
135
|
-
expect(
|
|
137
|
+
expect(ONCHANGE_FUNCTION).toHaveBeenCalled();
|
|
136
138
|
});
|
|
137
139
|
|
|
138
140
|
test('select with placeholder option', () => {
|
|
139
|
-
const
|
|
141
|
+
const PLACEHOLDER_TEXT = 'foo';
|
|
140
142
|
|
|
141
143
|
render(
|
|
142
144
|
<Select
|
|
143
|
-
id={
|
|
144
|
-
label={
|
|
145
|
-
options={
|
|
146
|
-
placeholder={
|
|
145
|
+
id={SELECT_ID}
|
|
146
|
+
label={LABEL_TEXT}
|
|
147
|
+
options={OPTIONS}
|
|
148
|
+
placeholder={PLACEHOLDER_TEXT}
|
|
147
149
|
/>
|
|
148
150
|
);
|
|
149
151
|
|
|
150
152
|
const select = screen.getByRole('combobox');
|
|
151
153
|
const firstOption = select.childNodes[0];
|
|
152
|
-
expect(firstOption.textContent).toEqual(
|
|
154
|
+
expect(firstOption.textContent).toEqual(PLACEHOLDER_TEXT);
|
|
153
155
|
expect(firstOption).toHaveAttribute('value', '');
|
|
154
156
|
});
|
|
155
157
|
|
|
156
158
|
test('select with initial value', () => {
|
|
157
|
-
const
|
|
159
|
+
const INITIAL_VALUE = 'button';
|
|
158
160
|
|
|
159
161
|
render(
|
|
160
162
|
<Select
|
|
161
|
-
id={
|
|
162
|
-
label={
|
|
163
|
-
options={
|
|
164
|
-
defaultValue={
|
|
163
|
+
id={SELECT_ID}
|
|
164
|
+
label={LABEL_TEXT}
|
|
165
|
+
options={OPTIONS}
|
|
166
|
+
defaultValue={INITIAL_VALUE}
|
|
165
167
|
/>
|
|
166
168
|
);
|
|
167
169
|
|
|
168
170
|
const select = screen.getByRole('combobox');
|
|
169
171
|
const selectedOption = [].slice.call(select.childNodes).filter(childNode => childNode.selected)[0];
|
|
170
|
-
expect(selectedOption).toHaveAttribute('value',
|
|
172
|
+
expect(selectedOption).toHaveAttribute('value', INITIAL_VALUE);
|
|
171
173
|
});
|
|
172
174
|
|
|
173
175
|
test('select with error message', () => {
|
|
174
|
-
const
|
|
176
|
+
const ERROR_MESSAGE_TEXT = 'This is a required field';
|
|
177
|
+
|
|
175
178
|
render(
|
|
176
179
|
<Select
|
|
177
|
-
id={
|
|
178
|
-
label={
|
|
179
|
-
options={
|
|
180
|
+
id={SELECT_ID}
|
|
181
|
+
label={LABEL_TEXT}
|
|
182
|
+
options={OPTIONS}
|
|
180
183
|
error
|
|
181
|
-
errorMessage={
|
|
184
|
+
errorMessage={ERROR_MESSAGE_TEXT}
|
|
182
185
|
/>
|
|
183
186
|
);
|
|
184
187
|
|
|
185
188
|
const select = screen.getByRole('combobox');
|
|
186
189
|
const selectWrapper = select.parentElement;
|
|
187
|
-
const errorMessageElement = screen.getByText(
|
|
190
|
+
const errorMessageElement = screen.getByText(ERROR_MESSAGE_TEXT);
|
|
188
191
|
|
|
189
192
|
expect(selectWrapper).toHaveClass('ds_input--error')
|
|
190
193
|
expect(select).toHaveAttribute('aria-describedby', errorMessageElement.id);
|
|
@@ -196,9 +199,9 @@ test('select with error message', () => {
|
|
|
196
199
|
test('passing additional props', () => {
|
|
197
200
|
render(
|
|
198
201
|
<Select
|
|
199
|
-
id={
|
|
200
|
-
label={
|
|
201
|
-
options={
|
|
202
|
+
id={SELECT_ID}
|
|
203
|
+
label={LABEL_TEXT}
|
|
204
|
+
options={OPTIONS}
|
|
202
205
|
data-test="foo"
|
|
203
206
|
/>
|
|
204
207
|
);
|
|
@@ -211,9 +214,9 @@ test('passing additional props', () => {
|
|
|
211
214
|
test('passing additional CSS classes', () => {
|
|
212
215
|
render(
|
|
213
216
|
<Select
|
|
214
|
-
id={
|
|
215
|
-
label={
|
|
216
|
-
options={
|
|
217
|
+
id={SELECT_ID}
|
|
218
|
+
label={LABEL_TEXT}
|
|
219
|
+
options={OPTIONS}
|
|
217
220
|
className="foo"
|
|
218
221
|
/>
|
|
219
222
|
);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import ErrorMessage from '../
|
|
2
|
-
import HintText from '../../common/
|
|
1
|
+
import ErrorMessage from '../ErrorMessage/ErrorMessage';
|
|
2
|
+
import HintText from '../../common/HintText';
|
|
3
3
|
|
|
4
4
|
const Option: React.FC<SGDS.Component.Select.Option> = function ({
|
|
5
5
|
text,
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { test, expect } from 'vitest';
|
|
2
2
|
import { render, screen } from '@testing-library/react';
|
|
3
|
-
import SequentialNavigation from './
|
|
3
|
+
import SequentialNavigation from './SequentialNavigation';
|
|
4
4
|
|
|
5
|
-
const
|
|
6
|
-
const
|
|
5
|
+
const NEXT_LINK_OBJECT = { title: 'Apply for or renew a Blue Badge?', href: '#prev' }
|
|
6
|
+
const PREVIOUS_LINK_OBJECT = { title: 'Apply for or renew a Blue Badge?', href: '#prev' }
|
|
7
7
|
|
|
8
8
|
test('sequential navigation renders correctly', () => {
|
|
9
9
|
render(
|
|
10
10
|
<SequentialNavigation
|
|
11
|
-
next={
|
|
12
|
-
previous={
|
|
11
|
+
next={NEXT_LINK_OBJECT}
|
|
12
|
+
previous={PREVIOUS_LINK_OBJECT}
|
|
13
13
|
/>
|
|
14
14
|
);
|
|
15
15
|
|
|
@@ -23,42 +23,42 @@ test('sequential navigation renders correctly', () => {
|
|
|
23
23
|
expect(sequentialNavigation).toHaveAttribute('aria-label', 'Article navigation');
|
|
24
24
|
|
|
25
25
|
expect(prevLink).toHaveClass('ds_sequential-nav__button', 'ds_sequential-nav__button--left');
|
|
26
|
-
expect(prevLink).toHaveAttribute('href',
|
|
27
|
-
expect(prevLink.textContent).toEqual(
|
|
26
|
+
expect(prevLink).toHaveAttribute('href', PREVIOUS_LINK_OBJECT.href);
|
|
27
|
+
expect(prevLink.textContent).toEqual(PREVIOUS_LINK_OBJECT.title);
|
|
28
28
|
expect(prevLinkWrapper).toHaveClass('ds_sequential-nav__item', 'ds_sequential-nav__item--prev');
|
|
29
29
|
expect(prevLinkWrapper?.tagName).toEqual('DIV');
|
|
30
30
|
expect(prevLink.childNodes[0]).toHaveAttribute('data-label', 'Previous')
|
|
31
31
|
|
|
32
32
|
expect(nextLink).toHaveClass('ds_sequential-nav__button', 'ds_sequential-nav__button--right');
|
|
33
|
-
expect(nextLink).toHaveAttribute('href',
|
|
34
|
-
expect(nextLink.textContent).toEqual(
|
|
33
|
+
expect(nextLink).toHaveAttribute('href', NEXT_LINK_OBJECT.href);
|
|
34
|
+
expect(nextLink.textContent).toEqual(NEXT_LINK_OBJECT.title);
|
|
35
35
|
expect(nextLinkWrapper).toHaveClass('ds_sequential-nav__item', 'ds_sequential-nav__item--next');
|
|
36
36
|
expect(nextLinkWrapper?.tagName).toEqual('DIV');
|
|
37
37
|
expect(nextLink.childNodes[0]).toHaveAttribute('data-label', 'Next')
|
|
38
38
|
});
|
|
39
39
|
|
|
40
40
|
test('with custom aria label', () => {
|
|
41
|
-
const
|
|
41
|
+
const ARIA_LABEL = 'My label';
|
|
42
42
|
|
|
43
43
|
render(
|
|
44
44
|
<SequentialNavigation
|
|
45
|
-
ariaLabel={
|
|
46
|
-
next={
|
|
47
|
-
previous={
|
|
45
|
+
ariaLabel={ARIA_LABEL}
|
|
46
|
+
next={NEXT_LINK_OBJECT}
|
|
47
|
+
previous={PREVIOUS_LINK_OBJECT}
|
|
48
48
|
/>
|
|
49
49
|
);
|
|
50
50
|
|
|
51
51
|
const sequentialNavigation = screen.getByRole('navigation');
|
|
52
52
|
|
|
53
|
-
expect(sequentialNavigation).toHaveAttribute('aria-label',
|
|
53
|
+
expect(sequentialNavigation).toHaveAttribute('aria-label', ARIA_LABEL);
|
|
54
54
|
});
|
|
55
55
|
|
|
56
56
|
test('passing additional props', () => {
|
|
57
57
|
render(
|
|
58
58
|
<SequentialNavigation
|
|
59
59
|
data-test="foo"
|
|
60
|
-
next={
|
|
61
|
-
previous={
|
|
60
|
+
next={NEXT_LINK_OBJECT}
|
|
61
|
+
previous={PREVIOUS_LINK_OBJECT}
|
|
62
62
|
/>
|
|
63
63
|
);
|
|
64
64
|
|
|
@@ -70,8 +70,8 @@ test('passing additional CSS classes', () => {
|
|
|
70
70
|
render(
|
|
71
71
|
<SequentialNavigation
|
|
72
72
|
className="foo"
|
|
73
|
-
next={
|
|
74
|
-
previous={
|
|
73
|
+
next={NEXT_LINK_OBJECT}
|
|
74
|
+
previous={PREVIOUS_LINK_OBJECT}
|
|
75
75
|
/>
|
|
76
76
|
);
|
|
77
77
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { test, expect } from 'vitest';
|
|
2
2
|
import { render, screen, within } from '@testing-library/react';
|
|
3
|
-
import SideNavigation, { List, Link } from './
|
|
3
|
+
import SideNavigation, { List, Link } from './SideNavigation';
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const ITEMS = [
|
|
6
6
|
{
|
|
7
7
|
title: 'Apples',
|
|
8
8
|
href: '#apples',
|
|
@@ -43,7 +43,7 @@ const items = [
|
|
|
43
43
|
|
|
44
44
|
test('side navigation renders correctly', () => {
|
|
45
45
|
render(
|
|
46
|
-
<SideNavigation items={
|
|
46
|
+
<SideNavigation items={ITEMS} />
|
|
47
47
|
);
|
|
48
48
|
|
|
49
49
|
const sideNavigation = screen.getByRole('navigation');
|
|
@@ -124,7 +124,7 @@ test('side nav link with children', () => {
|
|
|
124
124
|
});
|
|
125
125
|
|
|
126
126
|
test('side nav list renders correctly', () => {
|
|
127
|
-
const
|
|
127
|
+
const ITEMS = [
|
|
128
128
|
{
|
|
129
129
|
title: 'Bramley',
|
|
130
130
|
href: '#bramley'
|
|
@@ -136,7 +136,7 @@ test('side nav list renders correctly', () => {
|
|
|
136
136
|
];
|
|
137
137
|
|
|
138
138
|
render(
|
|
139
|
-
<List items={
|
|
139
|
+
<List items={ITEMS}/>
|
|
140
140
|
);
|
|
141
141
|
|
|
142
142
|
const list = screen.getByRole('list');
|
|
@@ -146,7 +146,7 @@ test('side nav list renders correctly', () => {
|
|
|
146
146
|
expect(list).toHaveClass('ds_side-navigation__list');
|
|
147
147
|
expect(list.tagName).toEqual('UL');
|
|
148
148
|
|
|
149
|
-
expect(list.children.length).toEqual(
|
|
149
|
+
expect(list.children.length).toEqual(ITEMS.length);
|
|
150
150
|
|
|
151
151
|
// check properties of first link
|
|
152
152
|
expect(item).toHaveClass('ds_side-navigation__item');
|
|
@@ -157,7 +157,7 @@ test('side nav list renders correctly', () => {
|
|
|
157
157
|
|
|
158
158
|
test('passing additional props', () => {
|
|
159
159
|
render(
|
|
160
|
-
<SideNavigation data-test="foo" items={
|
|
160
|
+
<SideNavigation data-test="foo" items={ITEMS} />
|
|
161
161
|
);
|
|
162
162
|
|
|
163
163
|
const sideNavigation = screen.getByRole('navigation');
|
|
@@ -166,7 +166,7 @@ test('passing additional props', () => {
|
|
|
166
166
|
|
|
167
167
|
test('passing additional CSS classes', () => {
|
|
168
168
|
render(
|
|
169
|
-
<SideNavigation className="foo" items={
|
|
169
|
+
<SideNavigation className="foo" items={ITEMS} />
|
|
170
170
|
);
|
|
171
171
|
|
|
172
172
|
const sideNavigation = screen.getByRole('navigation');
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { test, expect } from 'vitest';
|
|
2
2
|
import { render, screen, within } from '@testing-library/react';
|
|
3
|
-
import SiteHeader from './
|
|
4
|
-
import SiteNavigation from '../
|
|
5
|
-
import SiteSearch from '../
|
|
6
|
-
import PhaseBanner from '../
|
|
3
|
+
import SiteHeader from './SiteHeader';
|
|
4
|
+
import SiteNavigation from '../SiteNavigation/SiteNavigation';
|
|
5
|
+
import SiteSearch from '../SiteSearch/SiteSearch';
|
|
6
|
+
import PhaseBanner from '../PhaseBanner/PhaseBanner';
|
|
7
7
|
|
|
8
8
|
test('site header renders correctly (maximal, testing markup structure)', () => {
|
|
9
9
|
render(
|
|
@@ -67,14 +67,14 @@ test('site header renders correctly (maximal, testing markup structure)', () =>
|
|
|
67
67
|
});
|
|
68
68
|
|
|
69
69
|
test('site header branding: logo only, default URL', () => {
|
|
70
|
-
const
|
|
70
|
+
const LOGO = {
|
|
71
71
|
alt: 'The Scottish Government',
|
|
72
72
|
src: './scottish-government.svg'
|
|
73
73
|
};
|
|
74
74
|
|
|
75
75
|
render(
|
|
76
76
|
<SiteHeader
|
|
77
|
-
logo={
|
|
77
|
+
logo={LOGO}
|
|
78
78
|
/>
|
|
79
79
|
);
|
|
80
80
|
|
|
@@ -87,24 +87,24 @@ test('site header branding: logo only, default URL', () => {
|
|
|
87
87
|
expect(siteHeaderLogoLink).toHaveAttribute('href', '/');
|
|
88
88
|
|
|
89
89
|
expect(siteHeaderLogoImg).toHaveClass('ds_site-branding__logo-image');
|
|
90
|
-
expect(siteHeaderLogoImg).toHaveAttribute('src',
|
|
91
|
-
expect(siteHeaderLogoImg).toHaveAttribute('alt',
|
|
90
|
+
expect(siteHeaderLogoImg).toHaveAttribute('src', LOGO.src);
|
|
91
|
+
expect(siteHeaderLogoImg).toHaveAttribute('alt', LOGO.alt);
|
|
92
92
|
|
|
93
93
|
expect(siteHeaderLogoImg.parentElement).toEqual(siteHeaderLogoLink);
|
|
94
94
|
expect(siteHeaderLogoLink.parentElement).toEqual(siteHeaderBranding);
|
|
95
95
|
});
|
|
96
96
|
|
|
97
97
|
test('site header branding: logo and site title', () => {
|
|
98
|
-
const
|
|
98
|
+
const LOGO = {
|
|
99
99
|
alt: 'The Scottish Government',
|
|
100
100
|
src: './scottish-government.svg'
|
|
101
101
|
};
|
|
102
|
-
const
|
|
102
|
+
const SITE_TITLE_CONTENT = 'Design System React';
|
|
103
103
|
|
|
104
104
|
render(
|
|
105
105
|
<SiteHeader
|
|
106
|
-
logo={
|
|
107
|
-
siteTitle={
|
|
106
|
+
logo={LOGO}
|
|
107
|
+
siteTitle={SITE_TITLE_CONTENT}
|
|
108
108
|
/>
|
|
109
109
|
);
|
|
110
110
|
|
|
@@ -114,13 +114,13 @@ test('site header branding: logo and site title', () => {
|
|
|
114
114
|
const siteTitle = siteHeader.querySelector('.ds_site-branding__title');
|
|
115
115
|
|
|
116
116
|
expect(siteTitle?.tagName).toEqual('DIV');
|
|
117
|
-
expect(siteTitle?.textContent).toEqual(
|
|
117
|
+
expect(siteTitle?.textContent).toEqual(SITE_TITLE_CONTENT);
|
|
118
118
|
expect(siteTitle?.parentElement).toEqual(siteHeaderBranding);
|
|
119
119
|
expect(siteTitle?.previousElementSibling).toEqual(siteHeaderLogoLink);
|
|
120
120
|
});
|
|
121
121
|
|
|
122
122
|
test('site header branding: custom link URL', () => {
|
|
123
|
-
const
|
|
123
|
+
const LOGO = {
|
|
124
124
|
alt: 'The Scottish Government',
|
|
125
125
|
href: '/home.aspx',
|
|
126
126
|
src: './scottish-government.svg'
|
|
@@ -128,18 +128,18 @@ test('site header branding: custom link URL', () => {
|
|
|
128
128
|
|
|
129
129
|
render(
|
|
130
130
|
<SiteHeader
|
|
131
|
-
logo={
|
|
131
|
+
logo={LOGO}
|
|
132
132
|
/>
|
|
133
133
|
);
|
|
134
134
|
|
|
135
135
|
const siteHeader = screen.getByRole('banner');
|
|
136
136
|
const siteHeaderLogoLink = within(siteHeader).getByRole('link');
|
|
137
137
|
|
|
138
|
-
expect(siteHeaderLogoLink).toHaveAttribute('href',
|
|
138
|
+
expect(siteHeaderLogoLink).toHaveAttribute('href', LOGO.href);
|
|
139
139
|
});
|
|
140
140
|
|
|
141
141
|
test('site header with site search', () => {
|
|
142
|
-
const
|
|
142
|
+
const SEARCH_PROPS = {
|
|
143
143
|
action: 'apple',
|
|
144
144
|
autocompleteEndpoint: 'banana',
|
|
145
145
|
autocompleteSuggestionMappingFunction: 'cucumber',
|
|
@@ -152,8 +152,8 @@ test('site header with site search', () => {
|
|
|
152
152
|
|
|
153
153
|
render(
|
|
154
154
|
<>
|
|
155
|
-
<SiteHeader siteSearch={
|
|
156
|
-
<SiteSearch data-testid="sitesearch" {...
|
|
155
|
+
<SiteHeader siteSearch={SEARCH_PROPS} />
|
|
156
|
+
<SiteSearch data-testid="sitesearch" {...SEARCH_PROPS} />
|
|
157
157
|
</>
|
|
158
158
|
);
|
|
159
159
|
|
|
@@ -165,7 +165,7 @@ test('site header with site search', () => {
|
|
|
165
165
|
});
|
|
166
166
|
|
|
167
167
|
test('site header with site navigation', () => {
|
|
168
|
-
const
|
|
168
|
+
const NAVIGATION_ITEMS = [
|
|
169
169
|
{ title: 'About', href: '#about' },
|
|
170
170
|
{ title: 'Get started', href: '#get-started' },
|
|
171
171
|
{ title: 'Styles', href: '#styles' },
|
|
@@ -176,8 +176,8 @@ test('site header with site navigation', () => {
|
|
|
176
176
|
|
|
177
177
|
render(
|
|
178
178
|
<>
|
|
179
|
-
<SiteHeader navigationItems={
|
|
180
|
-
<SiteNavigation data-testid="sitenavigation" items={
|
|
179
|
+
<SiteHeader navigationItems={NAVIGATION_ITEMS} />
|
|
180
|
+
<SiteNavigation data-testid="sitenavigation" items={NAVIGATION_ITEMS} />
|
|
181
181
|
</>
|
|
182
182
|
);
|
|
183
183
|
|
|
@@ -212,15 +212,15 @@ test('site header with site navigation', () => {
|
|
|
212
212
|
});
|
|
213
213
|
|
|
214
214
|
test('site header with phase banner', () => {
|
|
215
|
-
const
|
|
215
|
+
const PHASE_BANNER_PROPS = {
|
|
216
216
|
content: 'My content',
|
|
217
217
|
phaseName: 'Beta'
|
|
218
218
|
};
|
|
219
219
|
|
|
220
220
|
render(
|
|
221
221
|
<>
|
|
222
|
-
<SiteHeader phaseBanner={
|
|
223
|
-
<PhaseBanner data-testid="phasebanner" {...
|
|
222
|
+
<SiteHeader phaseBanner={PHASE_BANNER_PROPS} />
|
|
223
|
+
<PhaseBanner data-testid="phasebanner" {...PHASE_BANNER_PROPS} />
|
|
224
224
|
</>
|
|
225
225
|
);
|
|
226
226
|
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
import { useEffect, useRef } from 'react';
|
|
4
4
|
|
|
5
|
-
import Icon from '../../common/
|
|
6
|
-
import PhaseBanner from '../
|
|
7
|
-
import SiteNavigation from "../
|
|
8
|
-
import SiteSearch from "../
|
|
5
|
+
import Icon from '../../common/Icon';
|
|
6
|
+
import PhaseBanner from '../PhaseBanner/PhaseBanner';
|
|
7
|
+
import SiteNavigation from "../SiteNavigation/SiteNavigation";
|
|
8
|
+
import SiteSearch from "../SiteSearch/SiteSearch";
|
|
9
9
|
|
|
10
10
|
// @ts-ignore
|
|
11
11
|
import DSMobileMenu from '@scottish-government/design-system/src/components/site-navigation/site-navigation';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { test, expect } from 'vitest';
|
|
2
2
|
import { render, screen, within } from '@testing-library/react';
|
|
3
|
-
import SiteNavigation from './
|
|
3
|
+
import SiteNavigation from './SiteNavigation';
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const ITEMS = [
|
|
6
6
|
{title: 'About', href: '#about'},
|
|
7
7
|
{title: 'Get started', href: '#get-started'},
|
|
8
8
|
{title: 'Styles', href: '#styles'},
|
|
@@ -13,7 +13,7 @@ const items = [
|
|
|
13
13
|
|
|
14
14
|
test('renders correctly', () => {
|
|
15
15
|
render(
|
|
16
|
-
<SiteNavigation items={
|
|
16
|
+
<SiteNavigation items={ITEMS}/>
|
|
17
17
|
);
|
|
18
18
|
|
|
19
19
|
const nav = screen.getByRole('navigation');
|
|
@@ -29,7 +29,7 @@ test('renders correctly', () => {
|
|
|
29
29
|
expect(list).toHaveClass('ds_site-navigation__list');
|
|
30
30
|
|
|
31
31
|
// check items
|
|
32
|
-
expect(listItems.length).toEqual(
|
|
32
|
+
expect(listItems.length).toEqual(ITEMS.length);
|
|
33
33
|
|
|
34
34
|
listItems.forEach((item, index) => {
|
|
35
35
|
expect(item).toHaveClass('ds_site-navigation__item');
|
|
@@ -38,8 +38,8 @@ test('renders correctly', () => {
|
|
|
38
38
|
|
|
39
39
|
expect(link).toHaveClass('ds_site-navigation__link');
|
|
40
40
|
expect(link).not.toHaveClass('ds_current');
|
|
41
|
-
expect(link.textContent).toEqual(
|
|
42
|
-
expect(link).toHaveAttribute('href',
|
|
41
|
+
expect(link.textContent).toEqual(ITEMS[index].title);
|
|
42
|
+
expect(link).toHaveAttribute('href', ITEMS[index].href)
|
|
43
43
|
});
|
|
44
44
|
});
|
|
45
45
|
|
|
@@ -55,7 +55,7 @@ test('highlights current item', () => {
|
|
|
55
55
|
|
|
56
56
|
test('passing additional props', () => {
|
|
57
57
|
render(
|
|
58
|
-
<SiteNavigation data-test="foo" items={
|
|
58
|
+
<SiteNavigation data-test="foo" items={ITEMS}/>
|
|
59
59
|
);
|
|
60
60
|
|
|
61
61
|
const nav = screen.getByRole('navigation');
|
|
@@ -64,7 +64,7 @@ test('passing additional props', () => {
|
|
|
64
64
|
|
|
65
65
|
test('passing additional CSS classes', () => {
|
|
66
66
|
render(
|
|
67
|
-
<SiteNavigation className="foo" items={
|
|
67
|
+
<SiteNavigation className="foo" items={ITEMS}/>
|
|
68
68
|
);
|
|
69
69
|
|
|
70
70
|
const nav = screen.getByRole('navigation');
|