@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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { test, expect } from 'vitest';
|
|
2
2
|
import { render, screen, within } from '@testing-library/react';
|
|
3
|
-
import Question from './
|
|
3
|
+
import Question from './Question';
|
|
4
4
|
|
|
5
5
|
test('question renders correctly (basic q, just a wrapper, invalid example)', () => {
|
|
6
6
|
render(
|
|
@@ -14,39 +14,39 @@ test('question renders correctly (basic q, just a wrapper, invalid example)', ()
|
|
|
14
14
|
});
|
|
15
15
|
|
|
16
16
|
test('fieldset question with legend', () => {
|
|
17
|
-
const
|
|
17
|
+
const LEGEND_TEXT = 'My legend';
|
|
18
18
|
|
|
19
19
|
render(
|
|
20
|
-
<Question tagName="fieldset" legend={
|
|
20
|
+
<Question tagName="fieldset" legend={LEGEND_TEXT}>
|
|
21
21
|
</Question>
|
|
22
22
|
);
|
|
23
23
|
|
|
24
24
|
const questionElement = screen.getByRole('group');
|
|
25
|
-
const legendElement = within(questionElement).getByText(
|
|
25
|
+
const legendElement = within(questionElement).getByText(LEGEND_TEXT);
|
|
26
26
|
expect(questionElement?.tagName).toEqual('FIELDSET');
|
|
27
27
|
expect(legendElement.tagName).toEqual('LEGEND');
|
|
28
28
|
});
|
|
29
29
|
|
|
30
30
|
test('question with hint text', () => {
|
|
31
|
-
const
|
|
31
|
+
const HINT_TEXT = 'My hint text';
|
|
32
32
|
|
|
33
33
|
render(
|
|
34
|
-
<Question hintText={
|
|
34
|
+
<Question hintText={HINT_TEXT}>
|
|
35
35
|
</Question>
|
|
36
36
|
);
|
|
37
37
|
|
|
38
38
|
const hintTextElement = screen.getByRole('paragraph');
|
|
39
39
|
const firstQuestionChild = document.querySelector('.ds_question')?.childNodes[0]
|
|
40
40
|
expect(hintTextElement).toHaveClass('ds_hint-text');
|
|
41
|
-
expect(hintTextElement.textContent).toEqual(
|
|
41
|
+
expect(hintTextElement.textContent).toEqual(HINT_TEXT);
|
|
42
42
|
expect(hintTextElement).toBe(firstQuestionChild);
|
|
43
43
|
});
|
|
44
44
|
|
|
45
45
|
test('question with error', () => {
|
|
46
|
-
const
|
|
46
|
+
const ERROR_MESSAGE_TEXT = 'My error message';
|
|
47
47
|
|
|
48
48
|
render(
|
|
49
|
-
<Question error errorMessage={
|
|
49
|
+
<Question error errorMessage={ERROR_MESSAGE_TEXT}>
|
|
50
50
|
</Question>
|
|
51
51
|
);
|
|
52
52
|
|
|
@@ -55,7 +55,7 @@ test('question with error', () => {
|
|
|
55
55
|
|
|
56
56
|
expect(questionElement).toHaveClass('ds_question--error');
|
|
57
57
|
expect(errorMessageElement).toBeInTheDocument();
|
|
58
|
-
expect(errorMessageElement?.textContent).toEqual(
|
|
58
|
+
expect(errorMessageElement?.textContent).toEqual(ERROR_MESSAGE_TEXT);
|
|
59
59
|
});
|
|
60
60
|
|
|
61
61
|
test('passing additional props', () => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import ErrorMessage from '../
|
|
2
|
-
import HintText from '../../common/
|
|
3
|
-
import WrapperTag from '../../common/
|
|
1
|
+
import ErrorMessage from '../ErrorMessage/ErrorMessage';
|
|
2
|
+
import HintText from '../../common/HintText';
|
|
3
|
+
import WrapperTag from '../../common/WrapperTag';
|
|
4
4
|
|
|
5
5
|
const Question: React.FC<SGDS.Component.Question> = function ({
|
|
6
6
|
children,
|
package/src/components/{radio-button/radio-button.test.tsx → RadioButton/RadioButton.test.tsx}
RENAMED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { test, expect, vi } from 'vitest';
|
|
2
2
|
import { render, screen, fireEvent } from '@testing-library/react';
|
|
3
|
-
import RadioGroup, { Radio } from './
|
|
3
|
+
import RadioGroup, { Radio } from './RadioButton';
|
|
4
4
|
|
|
5
5
|
test('radio group renders correct children', () => {
|
|
6
|
-
const
|
|
6
|
+
const ITEMS = [
|
|
7
7
|
{
|
|
8
8
|
id: 'universal-credit',
|
|
9
9
|
label: 'Universal Credit',
|
|
@@ -22,20 +22,20 @@ test('radio group renders correct children', () => {
|
|
|
22
22
|
label: 'I do not receive any of these benefits',
|
|
23
23
|
}
|
|
24
24
|
];
|
|
25
|
-
const
|
|
25
|
+
const GROUP_NAME = "foo"
|
|
26
26
|
|
|
27
27
|
render(
|
|
28
|
-
<RadioGroup name={
|
|
28
|
+
<RadioGroup name={GROUP_NAME} items={ITEMS} />
|
|
29
29
|
);
|
|
30
30
|
|
|
31
31
|
const radios = screen.getAllByRole('radio');
|
|
32
32
|
const groupContainer = radios[0].parentElement?.parentElement;
|
|
33
|
-
expect(radios.length).toEqual(
|
|
33
|
+
expect(radios.length).toEqual(ITEMS.length);
|
|
34
34
|
expect(groupContainer).toHaveClass('ds_radios', 'ds_field-group');
|
|
35
35
|
});
|
|
36
36
|
|
|
37
37
|
test('inline radio group', () => {
|
|
38
|
-
const
|
|
38
|
+
const ITEMS = [
|
|
39
39
|
{
|
|
40
40
|
id: 'radio-yes',
|
|
41
41
|
label: 'Yes'
|
|
@@ -45,10 +45,10 @@ test('inline radio group', () => {
|
|
|
45
45
|
label: 'No'
|
|
46
46
|
}
|
|
47
47
|
];
|
|
48
|
-
const
|
|
48
|
+
const GROUP_NAME = "yesno"
|
|
49
49
|
|
|
50
50
|
render(
|
|
51
|
-
<RadioGroup inline name={
|
|
51
|
+
<RadioGroup inline name={GROUP_NAME} items={ITEMS} />
|
|
52
52
|
);
|
|
53
53
|
|
|
54
54
|
|
|
@@ -58,20 +58,20 @@ test('inline radio group', () => {
|
|
|
58
58
|
});
|
|
59
59
|
|
|
60
60
|
test('radio group passes all expected item params', () => {
|
|
61
|
-
const
|
|
62
|
-
const
|
|
63
|
-
const
|
|
61
|
+
const ONBLUR_FUNCTION = vi.fn();
|
|
62
|
+
const ONCHANGE_FUNCTION = vi.fn();
|
|
63
|
+
const GROUP_NAME = "foo"
|
|
64
64
|
|
|
65
65
|
render(
|
|
66
|
-
<RadioGroup name={
|
|
66
|
+
<RadioGroup name={GROUP_NAME} small items={[
|
|
67
67
|
{
|
|
68
68
|
checked: true,
|
|
69
69
|
exclusive: true,
|
|
70
70
|
hintText: 'hint text',
|
|
71
71
|
id: 'myid',
|
|
72
72
|
label: 'label text',
|
|
73
|
-
onBlur: {
|
|
74
|
-
onChange: {
|
|
73
|
+
onBlur: {ONBLUR_FUNCTION},
|
|
74
|
+
onChange: {ONCHANGE_FUNCTION},
|
|
75
75
|
small: true
|
|
76
76
|
}
|
|
77
77
|
]}/>
|
|
@@ -82,17 +82,17 @@ test('radio group passes all expected item params', () => {
|
|
|
82
82
|
const hintText = screen.getByText('hint text');
|
|
83
83
|
|
|
84
84
|
expect(radio).toHaveAttribute('checked');
|
|
85
|
-
expect(radio).toHaveAttribute('name',
|
|
85
|
+
expect(radio).toHaveAttribute('name', GROUP_NAME);
|
|
86
86
|
expect(radio.id).toEqual('myid');
|
|
87
87
|
expect(radioContainer).toHaveClass('ds_radio--small');
|
|
88
88
|
expect(hintText).toBeInTheDocument();
|
|
89
89
|
expect(radio).toHaveAttribute('aria-describedby', hintText.id);
|
|
90
90
|
|
|
91
91
|
// fireEvent.blur(radio);
|
|
92
|
-
// expect(
|
|
92
|
+
// expect(ONBLUR_FUNCTION).toHaveBeenCalled();
|
|
93
93
|
|
|
94
94
|
// fireEvent.click(radio);
|
|
95
|
-
// expect(
|
|
95
|
+
// expect(ONCHANGE_FUNCTION).toHaveBeenCalled();
|
|
96
96
|
});
|
|
97
97
|
|
|
98
98
|
test('individual radio renders correctly', () => {
|
|
@@ -126,31 +126,31 @@ test('checked radio', () => {
|
|
|
126
126
|
});
|
|
127
127
|
|
|
128
128
|
test('radio with blur fn', () => {
|
|
129
|
-
const
|
|
129
|
+
const ONBLUR_FUNCTION = vi.fn();
|
|
130
130
|
|
|
131
131
|
render(
|
|
132
|
-
<Radio onBlur={
|
|
132
|
+
<Radio onBlur={ONBLUR_FUNCTION} name="benefitType" label="Pension Credit" id="pensioncredit" />
|
|
133
133
|
);
|
|
134
134
|
|
|
135
135
|
const radio = screen.getByRole('radio');
|
|
136
136
|
|
|
137
137
|
fireEvent.blur(radio);
|
|
138
138
|
|
|
139
|
-
expect(
|
|
139
|
+
expect(ONBLUR_FUNCTION).toHaveBeenCalled();
|
|
140
140
|
});
|
|
141
141
|
|
|
142
142
|
test('radio with change fn', () => {
|
|
143
|
-
const
|
|
143
|
+
const ONCHANGE_FUNCTION = vi.fn();
|
|
144
144
|
|
|
145
145
|
render(
|
|
146
|
-
<Radio onChange={
|
|
146
|
+
<Radio onChange={ONCHANGE_FUNCTION} name="benefitType" label="Pension Credit" id="pensioncredit" />
|
|
147
147
|
);
|
|
148
148
|
|
|
149
149
|
const radio = screen.getByRole('radio');
|
|
150
150
|
|
|
151
151
|
fireEvent.click(radio);
|
|
152
152
|
|
|
153
|
-
expect(
|
|
153
|
+
expect(ONCHANGE_FUNCTION).toHaveBeenCalled();
|
|
154
154
|
});
|
|
155
155
|
|
|
156
156
|
test('radio with hint text', () => {
|
|
@@ -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');
|