@scottish-government/designsystem-react 0.6.0 → 0.7.1
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/{abstract-notification-banner.jsx → AbstractNotificationBanner.jsx} +5 -5
- package/dist/components/{accordion/accordion.jsx → Accordion/Accordion.jsx} +6 -6
- package/dist/components/{back-to-top/back-to-top.jsx → BackToTop/BackToTop.jsx} +2 -2
- package/dist/components/{button/button.jsx → Button/Button.jsx} +7 -7
- package/dist/components/{checkbox/checkbox.jsx → Checkbox/Checkbox.jsx} +2 -2
- package/dist/components/{confirmation-message/confirmation-message.jsx → ConfirmationMessage/ConfirmationMessage.jsx} +6 -6
- package/dist/components/{contents-nav/contents-nav.jsx → ContentsNav/ContentsNav.jsx} +3 -3
- package/dist/components/{cookie-banner/cookie-banner.jsx → CookieBanner/CookieBanner.jsx} +4 -4
- package/dist/components/{date-picker/date-picker.jsx → DatePicker/DatePicker.jsx} +7 -7
- package/dist/components/{error-summary/error-summary.jsx → ErrorSummary/ErrorSummary.jsx} +2 -2
- package/dist/components/{file-download/file-download.jsx → FileDownload/FileDownload.jsx} +2 -2
- package/dist/components/{hide-this-page/hide-this-page.jsx → HideThisPage/HideThisPage.jsx} +3 -3
- package/dist/components/{notification-banner/notification-banner.jsx → NotificationBanner/NotificationBanner.jsx} +4 -4
- package/dist/components/{notification-panel/notification-panel.jsx → NotificationPanel/NotificationPanel.jsx} +4 -4
- package/dist/components/{pagination/pagination.jsx → Pagination/Pagination.jsx} +3 -3
- package/dist/components/{phase-banner/phase-banner.jsx → PhaseBanner/PhaseBanner.jsx} +2 -2
- package/dist/components/{question/question.jsx → Question/Question.jsx} +7 -7
- package/dist/components/{radio-button/radio-button.jsx → RadioButton/RadioButton.jsx} +2 -2
- package/dist/components/{select/select.jsx → Select/Select.jsx} +4 -4
- package/dist/components/{site-header/site-header.jsx → SiteHeader/SiteHeader.jsx} +13 -13
- package/dist/components/{site-search/site-search.jsx → SiteSearch/SiteSearch.jsx} +2 -2
- package/dist/components/{summary-card/summary-card.jsx → SummaryCard/SummaryCard.jsx} +6 -6
- package/dist/components/{summary-list/summary-list.jsx → SummaryList/SummaryList.jsx} +8 -8
- package/dist/components/{tabs/tabs.jsx → Tabs/Tabs.jsx} +4 -4
- package/dist/components/{task-list/task-list.jsx → TaskList/TaskList.jsx} +9 -9
- package/dist/components/{text-input/text-input.jsx → TextInput/TextInput.jsx} +11 -11
- package/dist/components/{textarea/textarea.jsx → Textarea/Textarea.jsx} +7 -7
- 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/dist/icons/ArrowUpward.jsx +0 -41
- package/dist/icons/CalendarToday.jsx +0 -41
- package/dist/icons/Cancel.jsx +0 -40
- package/dist/icons/CheckCircle.jsx +0 -41
- package/dist/icons/ChevronLeft.jsx +0 -41
- package/dist/icons/ChevronRight.jsx +0 -41
- package/dist/icons/Close.jsx +0 -41
- package/dist/icons/Description.jsx +0 -41
- package/dist/icons/DoubleChevronLeft.jsx +0 -40
- package/dist/icons/DoubleChevronRight.jsx +0 -40
- package/dist/icons/Error.jsx +0 -41
- package/dist/icons/ExpandLess.jsx +0 -41
- package/dist/icons/ExpandMore.jsx +0 -41
- package/dist/icons/List.jsx +0 -44
- package/dist/icons/Menu.jsx +0 -41
- package/dist/icons/PriorityHigh.jsx +0 -42
- package/dist/icons/Search.jsx +0 -41
- package/dist/icons/index.js +0 -40
- /package/dist/common/{conditional-wrapper.jsx → ConditionalWrapper.jsx} +0 -0
- /package/dist/common/{file-icon.jsx → FileIcon.jsx} +0 -0
- /package/dist/common/{hint-text.jsx → HintText.jsx} +0 -0
- /package/dist/common/{icon.jsx → Icon.jsx} +0 -0
- /package/dist/common/{screen-reader-text.jsx → ScreenReaderText.jsx} +0 -0
- /package/dist/common/{wrapper-tag.jsx → WrapperTag.jsx} +0 -0
- /package/dist/components/{aspect-box/aspect-box.jsx → AspectBox/AspectBox.jsx} +0 -0
- /package/dist/components/{breadcrumbs/breadcrumbs.jsx → Breadcrumbs/Breadcrumbs.jsx} +0 -0
- /package/dist/components/{details/details.jsx → Details/Details.jsx} +0 -0
- /package/dist/components/{error-message/error-message.jsx → ErrorMessage/ErrorMessage.jsx} +0 -0
- /package/dist/components/{inset-text/inset-text.jsx → InsetText/InsetText.jsx} +0 -0
- /package/dist/components/{page-header/page-header.jsx → PageHeader/PageHeader.jsx} +0 -0
- /package/dist/components/{page-metadata/page-metadata.jsx → PageMetadata/PageMetadata.jsx} +0 -0
- /package/dist/components/{sequential-navigation/sequential-navigation.jsx → SequentialNavigation/SequentialNavigation.jsx} +0 -0
- /package/dist/components/{side-navigation/side-navigation.jsx → SideNavigation/SideNavigation.jsx} +0 -0
- /package/dist/components/{site-navigation/site-navigation.jsx → SiteNavigation/SiteNavigation.jsx} +0 -0
- /package/dist/components/{skip-links/skip-links.jsx → SkipLinks/SkipLinks.jsx} +0 -0
- /package/dist/components/{table/table.jsx → Table/Table.jsx} +0 -0
- /package/dist/components/{tag/tag.jsx → Tag/Tag.jsx} +0 -0
- /package/dist/components/{warning-text/warning-text.jsx → WarningText/WarningText.jsx} +0 -0
- /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
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
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { test, expect } from 'vitest';
|
|
2
2
|
import { render, screen, within } from '@testing-library/react';
|
|
3
|
-
import Tabs from './
|
|
3
|
+
import Tabs from './Tabs';
|
|
4
4
|
import slugify from '../../utils/slugify';
|
|
5
5
|
|
|
6
6
|
test('tab container renders correctly', () => {
|
|
@@ -29,7 +29,7 @@ test('tab container renders correctly', () => {
|
|
|
29
29
|
expect(tabContainer.tagName).toEqual('DIV');
|
|
30
30
|
|
|
31
31
|
expect(tabHeading).toHaveClass('ds_tabs__title');
|
|
32
|
-
// default
|
|
32
|
+
// default heading level
|
|
33
33
|
expect(tabHeading.tagName).toEqual('H2');
|
|
34
34
|
expect(tabHeading.parentElement).toEqual(tabContainer);
|
|
35
35
|
// default ID-heading
|
|
@@ -83,10 +83,10 @@ test('non-bordered tabs', () => {
|
|
|
83
83
|
});
|
|
84
84
|
|
|
85
85
|
test('custom title', () => {
|
|
86
|
-
const
|
|
86
|
+
const TABS_TITLE = 'My title';
|
|
87
87
|
|
|
88
88
|
render(
|
|
89
|
-
<Tabs data-testid="tabcontainer" title={
|
|
89
|
+
<Tabs data-testid="tabcontainer" title={TABS_TITLE}>
|
|
90
90
|
<Tabs.Item tabLabel="Tab 1" data-testid="tabpanel1">
|
|
91
91
|
<div data-testid="tabpanel1content">Content one</div>
|
|
92
92
|
</Tabs.Item>
|
|
@@ -101,14 +101,14 @@ test('custom title', () => {
|
|
|
101
101
|
const tabHeading = within(tabContainer).getByRole('heading');
|
|
102
102
|
|
|
103
103
|
expect(tabList).toHaveAttribute('aria-labelledby', tabHeading.id);
|
|
104
|
-
expect(tabHeading.textContent).toEqual(
|
|
104
|
+
expect(tabHeading.textContent).toEqual(TABS_TITLE)
|
|
105
105
|
});
|
|
106
106
|
|
|
107
|
-
test('custom
|
|
108
|
-
const
|
|
107
|
+
test('custom heading level', () => {
|
|
108
|
+
const HEADING_LEVEL = 'h3';
|
|
109
109
|
|
|
110
110
|
render(
|
|
111
|
-
<Tabs data-testid="tabcontainer"
|
|
111
|
+
<Tabs data-testid="tabcontainer" headingLevel={HEADING_LEVEL}>
|
|
112
112
|
<Tabs.Item tabLabel="Tab 1" data-testid="tabpanel1">
|
|
113
113
|
<div data-testid="tabpanel1content">Content one</div>
|
|
114
114
|
</Tabs.Item>
|
|
@@ -121,34 +121,14 @@ test('custom base ID', () => {
|
|
|
121
121
|
const tabContainer = screen.getByTestId('tabcontainer');
|
|
122
122
|
const tabHeading = within(tabContainer).getByRole('heading');
|
|
123
123
|
|
|
124
|
-
expect(tabHeading).
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
test('custom header level', () => {
|
|
128
|
-
const headerLevel = 'h3';
|
|
129
|
-
|
|
130
|
-
render(
|
|
131
|
-
<Tabs data-testid="tabcontainer" headerLevel={headerLevel}>
|
|
132
|
-
<Tabs.Item tabLabel="Tab 1" data-testid="tabpanel1">
|
|
133
|
-
<div data-testid="tabpanel1content">Content one</div>
|
|
134
|
-
</Tabs.Item>
|
|
135
|
-
<Tabs.Item tabLabel="Tab 2" data-testid="tabpanel2">
|
|
136
|
-
Content two
|
|
137
|
-
</Tabs.Item>
|
|
138
|
-
</Tabs>
|
|
139
|
-
);
|
|
140
|
-
|
|
141
|
-
const tabContainer = screen.getByTestId('tabcontainer');
|
|
142
|
-
const tabHeading = within(tabContainer).getByRole('heading');
|
|
143
|
-
|
|
144
|
-
expect(tabHeading.tagName).toEqual(headerLevel.toUpperCase());
|
|
124
|
+
expect(tabHeading.tagName).toEqual(HEADING_LEVEL.toUpperCase());
|
|
145
125
|
});
|
|
146
126
|
|
|
147
127
|
test('custom baseID', () => {
|
|
148
|
-
const
|
|
128
|
+
const BASE_ID = 'myId';
|
|
149
129
|
|
|
150
130
|
render(
|
|
151
|
-
<Tabs data-testid="tabcontainer" baseId={
|
|
131
|
+
<Tabs data-testid="tabcontainer" baseId={BASE_ID}>
|
|
152
132
|
<Tabs.Item tabLabel="Tab 1" data-testid="tabpanel1">
|
|
153
133
|
<div data-testid="tabpanel1content">Content one</div>
|
|
154
134
|
</Tabs.Item>
|
|
@@ -164,23 +144,23 @@ test('custom baseID', () => {
|
|
|
164
144
|
const tabPanelTwo = screen.getByTestId('tabpanel2');
|
|
165
145
|
|
|
166
146
|
// default title slugified to part of the ID
|
|
167
|
-
expect(tabHeading).toHaveAttribute('id', `${
|
|
147
|
+
expect(tabHeading).toHaveAttribute('id', `${BASE_ID}-heading`);
|
|
168
148
|
// generated IDs using the slug of the tab title
|
|
169
|
-
expect(tabPanelOne).toHaveAttribute('id', `${
|
|
170
|
-
expect(tabPanelTwo).toHaveAttribute('id', `${
|
|
149
|
+
expect(tabPanelOne).toHaveAttribute('id', `${BASE_ID}-tab-1`);
|
|
150
|
+
expect(tabPanelTwo).toHaveAttribute('id', `${BASE_ID}-tab-2`);
|
|
171
151
|
});
|
|
172
152
|
|
|
173
153
|
test('tab with and without specific ID attribute', () => {
|
|
174
|
-
const
|
|
175
|
-
const
|
|
176
|
-
const
|
|
154
|
+
const BASE_ID = 'foo'
|
|
155
|
+
const TAB_LABEL = 'Tab 1';
|
|
156
|
+
const TAB_ID = 'bar';
|
|
177
157
|
|
|
178
158
|
render(
|
|
179
|
-
<Tabs baseId={
|
|
180
|
-
<Tabs.Item tabLabel={
|
|
159
|
+
<Tabs baseId={BASE_ID}>
|
|
160
|
+
<Tabs.Item tabLabel={TAB_LABEL} data-testid="tabpanel1">
|
|
181
161
|
<div data-testid="tabpanel1content">Content one</div>
|
|
182
162
|
</Tabs.Item>
|
|
183
|
-
<Tabs.Item tabLabel="Tab 2" id={
|
|
163
|
+
<Tabs.Item tabLabel="Tab 2" id={TAB_ID} data-testid="tabpanel2">
|
|
184
164
|
<div data-testid="tabpanel1content">Content one</div>
|
|
185
165
|
</Tabs.Item>
|
|
186
166
|
</Tabs>
|
|
@@ -189,8 +169,8 @@ test('tab with and without specific ID attribute', () => {
|
|
|
189
169
|
const tabPanelOne = screen.getByTestId('tabpanel1');
|
|
190
170
|
const tabPanelTwo = screen.getByTestId('tabpanel2');
|
|
191
171
|
|
|
192
|
-
expect(tabPanelOne).toHaveAttribute('id', `${
|
|
193
|
-
expect(tabPanelTwo).toHaveAttribute('id',
|
|
172
|
+
expect(tabPanelOne).toHaveAttribute('id', `${BASE_ID}-${slugify(TAB_LABEL)}`);
|
|
173
|
+
expect(tabPanelTwo).toHaveAttribute('id', TAB_ID);
|
|
194
174
|
});
|
|
195
175
|
|
|
196
176
|
test('with manual activation', () => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { isValidElement, Children, useEffect, useRef } from 'react';
|
|
2
|
-
import WrapperTag from '../../common/
|
|
2
|
+
import WrapperTag from '../../common/WrapperTag';
|
|
3
3
|
// @ts-ignore
|
|
4
4
|
import DSTabs from '@scottish-government/design-system/src/components/tabs/tabs';
|
|
5
5
|
import slugify from '../../utils/slugify';
|
|
@@ -44,7 +44,7 @@ const Tabs: React.FC<SGDS.Component.Tabs>
|
|
|
44
44
|
bordered = true,
|
|
45
45
|
children,
|
|
46
46
|
className,
|
|
47
|
-
|
|
47
|
+
headingLevel = 'h2',
|
|
48
48
|
manual = false,
|
|
49
49
|
title = 'Contents',
|
|
50
50
|
...props
|
|
@@ -89,7 +89,7 @@ const Tabs: React.FC<SGDS.Component.Tabs>
|
|
|
89
89
|
<WrapperTag
|
|
90
90
|
id={headingId}
|
|
91
91
|
className="ds_tabs__title"
|
|
92
|
-
tagName={
|
|
92
|
+
tagName={headingLevel}
|
|
93
93
|
>
|
|
94
94
|
{title}
|
|
95
95
|
</WrapperTag>
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { test, expect } from 'vitest';
|
|
2
2
|
import { render, screen } from '@testing-library/react';
|
|
3
|
-
import Tag from './
|
|
3
|
+
import Tag from './Tag';
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const TAG_TEXT = 'Beta';
|
|
6
6
|
|
|
7
7
|
test('tag renders correctly', () => {
|
|
8
8
|
render(
|
|
9
|
-
<Tag title={
|
|
9
|
+
<Tag title={TAG_TEXT}/>
|
|
10
10
|
);
|
|
11
11
|
|
|
12
|
-
const tag = screen.getByText(
|
|
12
|
+
const tag = screen.getByText(TAG_TEXT);
|
|
13
13
|
|
|
14
14
|
expect(tag).toHaveClass('ds_tag');
|
|
15
15
|
expect(tag.nodeName).toEqual('SPAN');
|
|
@@ -17,29 +17,29 @@ test('tag renders correctly', () => {
|
|
|
17
17
|
|
|
18
18
|
test('tag with custom colour', () => {
|
|
19
19
|
render(
|
|
20
|
-
<Tag colour="red" title={
|
|
20
|
+
<Tag colour="red" title={TAG_TEXT}/>
|
|
21
21
|
);
|
|
22
22
|
|
|
23
|
-
const tag = screen.getByText(
|
|
23
|
+
const tag = screen.getByText(TAG_TEXT);
|
|
24
24
|
|
|
25
25
|
expect(tag).toHaveClass('ds_tag--red');
|
|
26
26
|
});
|
|
27
27
|
|
|
28
28
|
test('passing additional props', () => {
|
|
29
29
|
render(
|
|
30
|
-
<Tag data-test="foo" title={
|
|
30
|
+
<Tag data-test="foo" title={TAG_TEXT}/>
|
|
31
31
|
);
|
|
32
32
|
|
|
33
|
-
const tag = screen.getByText(
|
|
33
|
+
const tag = screen.getByText(TAG_TEXT);
|
|
34
34
|
expect(tag?.dataset.test).toEqual('foo');
|
|
35
35
|
});
|
|
36
36
|
|
|
37
37
|
test('tag with additional CSS class', () => {
|
|
38
38
|
render(
|
|
39
|
-
<Tag className="foo" title={
|
|
39
|
+
<Tag className="foo" title={TAG_TEXT}/>
|
|
40
40
|
);
|
|
41
41
|
|
|
42
|
-
const tag = screen.getByText(
|
|
42
|
+
const tag = screen.getByText(TAG_TEXT);
|
|
43
43
|
|
|
44
44
|
expect(tag).toHaveClass('foo', 'ds_tag');
|
|
45
45
|
});
|