@scottish-government/designsystem-react 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/@types/components/Accordion.d.ts +2 -2
- package/@types/components/ConfirmationMessage.d.ts +1 -1
- package/@types/components/NotificationPanel.d.ts +1 -1
- package/@types/components/SummaryCard.d.ts +1 -1
- package/@types/components/Tabs.d.ts +1 -1
- package/@types/sgds.d.ts +1 -1
- package/CHANGELOG.md +81 -0
- package/README.md +4 -0
- package/dist/common/AbstractNotificationBanner.jsx +63 -0
- package/dist/common/ConditionalWrapper.jsx +8 -0
- package/dist/common/FileIcon.jsx +51 -0
- package/dist/common/HintText.jsx +9 -0
- package/dist/common/Icon.jsx +57 -0
- package/dist/common/ScreenReaderText.jsx +9 -0
- package/dist/common/WrapperTag.jsx +11 -0
- package/dist/components/Accordion/Accordion.jsx +102 -0
- package/dist/components/AspectBox/AspectBox.jsx +79 -0
- package/dist/components/BackToTop/BackToTop.jsx +27 -0
- package/dist/components/Breadcrumbs/Breadcrumbs.jsx +28 -0
- package/dist/components/Button/Button.jsx +30 -0
- package/dist/components/Checkbox/Checkbox.jsx +62 -0
- package/dist/components/ConfirmationMessage/ConfirmationMessage.jsx +24 -0
- package/dist/components/ContentsNav/ContentsNav.jsx +33 -0
- package/dist/components/CookieBanner/CookieBanner.jsx +21 -0
- package/dist/components/DatePicker/DatePicker.jsx +54 -0
- package/dist/components/Details/Details.jsx +17 -0
- package/dist/components/ErrorMessage/ErrorMessage.jsx +12 -0
- package/dist/components/ErrorSummary/ErrorSummary.jsx +27 -0
- package/dist/components/FileDownload/FileDownload.jsx +50 -0
- package/dist/components/HideThisPage/HideThisPage.jsx +71 -0
- package/dist/components/InsetText/InsetText.jsx +14 -0
- package/dist/components/NotificationBanner/NotificationBanner.jsx +26 -0
- package/dist/components/NotificationPanel/NotificationPanel.jsx +21 -0
- package/dist/components/PageHeader/PageHeader.jsx +15 -0
- package/dist/components/PageMetadata/PageMetadata.jsx +26 -0
- package/dist/components/Pagination/Pagination.jsx +97 -0
- package/dist/components/PhaseBanner/PhaseBanner.jsx +23 -0
- package/dist/components/Question/Question.jsx +22 -0
- package/dist/components/RadioButton/RadioButton.jsx +43 -0
- package/dist/components/Select/Select.jsx +52 -0
- package/dist/components/SequentialNavigation/SequentialNavigation.jsx +31 -0
- package/dist/components/SideNavigation/SideNavigation.jsx +52 -0
- package/dist/components/SiteHeader/SiteHeader.jsx +68 -0
- package/dist/components/SiteNavigation/SiteNavigation.jsx +22 -0
- package/dist/components/SiteSearch/SiteSearch.jsx +55 -0
- package/dist/components/SkipLinks/SkipLinks.jsx +21 -0
- package/dist/components/SummaryCard/SummaryCard.jsx +67 -0
- package/dist/components/SummaryList/SummaryList.jsx +75 -0
- package/dist/components/Table/Table.jsx +24 -0
- package/dist/components/Tabs/Tabs.jsx +99 -0
- package/dist/components/Tag/Tag.jsx +13 -0
- package/dist/components/TaskList/TaskList.jsx +95 -0
- package/dist/components/TextInput/TextInput.jsx +58 -0
- package/dist/components/Textarea/Textarea.jsx +54 -0
- package/dist/components/WarningText/WarningText.jsx +16 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/common/{abstract-notification-banner.test.tsx → AbstractNotificationBanner.test.tsx} +11 -11
- package/src/common/{abstract-notification-banner.tsx → AbstractNotificationBanner.tsx} +2 -2
- package/src/common/{conditional-wrapper.test.tsx → ConditionalWrapper.test.tsx} +1 -1
- package/src/common/{file-icon.test.tsx → FileIcon.test.tsx} +10 -10
- package/src/common/{hint-text.test.tsx → HintText.test.tsx} +12 -12
- package/src/common/{icon.test.tsx → Icon.test.tsx} +16 -16
- package/src/common/{screen-reader-text.test.tsx → ScreenReaderText.test.tsx} +5 -5
- package/src/common/{wrapper-tag.test.tsx → WrapperTag.test.tsx} +5 -5
- package/src/components/{accordion/accordion.test.tsx → Accordion/Accordion.test.tsx} +35 -35
- package/src/components/{accordion/accordion.tsx → Accordion/Accordion.tsx} +5 -5
- package/src/components/{aspect-box/aspect-box.test.tsx → AspectBox/AspectBox.test.tsx} +2 -2
- package/src/components/{back-to-top/back-to-top.test.tsx → BackToTop/BackToTop.test.tsx} +1 -1
- package/src/components/{back-to-top/back-to-top.tsx → BackToTop/BackToTop.tsx} +1 -1
- package/src/components/{breadcrumbs/breadcrumbs.test.tsx → Breadcrumbs/Breadcrumbs.test.tsx} +7 -7
- package/src/components/{button/button.test.tsx → Button/Button.test.tsx} +1 -1
- package/src/components/{button/button.tsx → Button/Button.tsx} +3 -3
- package/src/components/{checkbox/checkbox.test.tsx → Checkbox/Checkbox.test.tsx} +16 -16
- package/src/components/{checkbox/checkbox.tsx → Checkbox/Checkbox.tsx} +1 -1
- package/src/components/{confirmation-message/confirmation-message.test.tsx → ConfirmationMessage/ConfirmationMessage.test.tsx} +12 -14
- package/src/components/{confirmation-message/confirmation-message.tsx → ConfirmationMessage/ConfirmationMessage.tsx} +4 -4
- package/src/components/{contents-nav/contents-nav.test.tsx → ContentsNav/ContentsNav.test.tsx} +21 -28
- package/src/components/{contents-nav/contents-nav.tsx → ContentsNav/ContentsNav.tsx} +1 -1
- package/src/components/{cookie-banner/cookie-banner.test.tsx → CookieBanner/CookieBanner.test.tsx} +3 -3
- package/src/components/{cookie-banner/cookie-banner.tsx → CookieBanner/CookieBanner.tsx} +1 -1
- package/src/components/{date-picker/date-picker.test.tsx → DatePicker/DatePicker.test.tsx} +76 -66
- package/src/components/{date-picker/date-picker.tsx → DatePicker/DatePicker.tsx} +2 -2
- package/src/components/{details/details.test.tsx → Details/Details.test.tsx} +10 -10
- package/src/components/{error-message/error-message.test.tsx → ErrorMessage/ErrorMessage.test.tsx} +10 -10
- package/src/components/{error-summary/error-summary.test.tsx → ErrorSummary/ErrorSummary.test.tsx} +13 -14
- package/src/components/{error-summary/error-summary.tsx → ErrorSummary/ErrorSummary.tsx} +1 -1
- package/src/components/{file-download/file-download.test.tsx → FileDownload/FileDownload.test.tsx} +21 -21
- package/src/components/{file-download/file-download.tsx → FileDownload/FileDownload.tsx} +1 -1
- package/src/components/{hide-this-page/hide-this-page.test.tsx → HideThisPage/HideThisPage.test.tsx} +4 -4
- package/src/components/{hide-this-page/hide-this-page.tsx → HideThisPage/HideThisPage.tsx} +3 -3
- package/src/components/{inset-text/inset-text.test.tsx → InsetText/InsetText.test.tsx} +1 -1
- package/src/components/{notification-banner/notification-banner.test.tsx → NotificationBanner/NotificationBanner.test.tsx} +4 -4
- package/src/components/{notification-banner/notification-banner.tsx → NotificationBanner/NotificationBanner.tsx} +1 -1
- package/src/components/{notification-panel/notification-panel.test.tsx → NotificationPanel/NotificationPanel.test.tsx} +24 -23
- package/src/components/{notification-panel/notification-panel.tsx → NotificationPanel/NotificationPanel.tsx} +3 -3
- package/src/components/{page-header/page-header.test.tsx → PageHeader/PageHeader.test.tsx} +9 -9
- package/src/components/{page-metadata/page-metadata.test.tsx → PageMetadata/PageMetadata.test.tsx} +9 -9
- package/src/components/{pagination/pagination.test.tsx → Pagination/Pagination.test.tsx} +56 -56
- package/src/components/{pagination/pagination.tsx → Pagination/Pagination.tsx} +1 -1
- package/src/components/{phase-banner/phase-banner.test.tsx → PhaseBanner/PhaseBanner.test.tsx} +9 -9
- package/src/components/{phase-banner/phase-banner.tsx → PhaseBanner/PhaseBanner.tsx} +1 -1
- package/src/components/{question/question.test.tsx → Question/Question.test.tsx} +10 -10
- package/src/components/{question/question.tsx → Question/Question.tsx} +3 -3
- package/src/components/{radio-button/radio-button.test.tsx → RadioButton/RadioButton.test.tsx} +23 -23
- package/src/components/{radio-button/radio-button.tsx → RadioButton/RadioButton.tsx} +1 -1
- package/src/components/{select/select.test.tsx → Select/Select.test.tsx} +67 -64
- package/src/components/{select/select.tsx → Select/Select.tsx} +2 -2
- package/src/components/{sequential-navigation/sequential-navigation.test.tsx → SequentialNavigation/SequentialNavigation.test.tsx} +18 -18
- package/src/components/{side-navigation/side-navigation.test.tsx → SideNavigation/SideNavigation.test.tsx} +8 -8
- package/src/components/{site-header/site-header.test.tsx → SiteHeader/SiteHeader.test.tsx} +25 -25
- package/src/components/{site-header/site-header.tsx → SiteHeader/SiteHeader.tsx} +4 -4
- package/src/components/{site-navigation/site-navigation.test.tsx → SiteNavigation/SiteNavigation.test.tsx} +8 -8
- package/src/components/{site-search/site-search.test.tsx → SiteSearch/SiteSearch.test.tsx} +16 -16
- package/src/components/{site-search/site-search.tsx → SiteSearch/SiteSearch.tsx} +1 -1
- package/src/components/{skip-links/skip-links.test.tsx → SkipLinks/SkipLinks.test.tsx} +15 -15
- package/src/components/{summary-card/summary-card.test.tsx → SummaryCard/SummaryCard.test.tsx} +28 -28
- package/src/components/{summary-card/summary-card.tsx → SummaryCard/SummaryCard.tsx} +4 -4
- package/src/components/{summary-list/summary-list.test.tsx → SummaryList/SummaryList.test.tsx} +55 -56
- package/src/components/{summary-list/summary-list.tsx → SummaryList/SummaryList.tsx} +2 -2
- package/src/components/{table/table.test.tsx → Table/Table.test.tsx} +4 -4
- package/src/components/{tabs/tabs.test.tsx → Tabs/Tabs.test.tsx} +22 -42
- package/src/components/{tabs/tabs.tsx → Tabs/Tabs.tsx} +3 -3
- package/src/components/{tag/tag.test.tsx → Tag/Tag.test.tsx} +10 -10
- package/src/components/{task-list/task-list.test.tsx → TaskList/TaskList.test.tsx} +109 -108
- package/src/components/{task-list/task-list.tsx → TaskList/TaskList.tsx} +4 -4
- package/src/components/{text-input/text-input.test.tsx → TextInput/TextInput.test.tsx} +92 -87
- package/src/components/{text-input/text-input.tsx → TextInput/TextInput.tsx} +4 -4
- package/src/components/{textarea/textarea.test.tsx → Textarea/Textarea.test.tsx} +71 -67
- package/src/components/{textarea/textarea.tsx → Textarea/Textarea.tsx} +3 -3
- package/src/components/{warning-text/warning-text.test.tsx → WarningText/WarningText.test.tsx} +1 -1
- /package/src/common/{conditional-wrapper.tsx → ConditionalWrapper.tsx} +0 -0
- /package/src/common/{file-icon.tsx → FileIcon.tsx} +0 -0
- /package/src/common/{hint-text.tsx → HintText.tsx} +0 -0
- /package/src/common/{icon.tsx → Icon.tsx} +0 -0
- /package/src/common/{screen-reader-text.tsx → ScreenReaderText.tsx} +0 -0
- /package/src/common/{wrapper-tag.tsx → WrapperTag.tsx} +0 -0
- /package/src/components/{aspect-box/aspect-box.tsx → AspectBox/AspectBox.tsx} +0 -0
- /package/src/components/{breadcrumbs/breadcrumbs.tsx → Breadcrumbs/Breadcrumbs.tsx} +0 -0
- /package/src/components/{details/details.tsx → Details/Details.tsx} +0 -0
- /package/src/components/{error-message/error-message.tsx → ErrorMessage/ErrorMessage.tsx} +0 -0
- /package/src/components/{inset-text/inset-text.tsx → InsetText/InsetText.tsx} +0 -0
- /package/src/components/{page-header/page-header.tsx → PageHeader/PageHeader.tsx} +0 -0
- /package/src/components/{page-metadata/page-metadata.tsx → PageMetadata/PageMetadata.tsx} +0 -0
- /package/src/components/{sequential-navigation/sequential-navigation.tsx → SequentialNavigation/SequentialNavigation.tsx} +0 -0
- /package/src/components/{side-navigation/side-navigation.tsx → SideNavigation/SideNavigation.tsx} +0 -0
- /package/src/components/{site-navigation/site-navigation.tsx → SiteNavigation/SiteNavigation.tsx} +0 -0
- /package/src/components/{skip-links/skip-links.tsx → SkipLinks/SkipLinks.tsx} +0 -0
- /package/src/components/{table/table.tsx → Table/Table.tsx} +0 -0
- /package/src/components/{tag/tag.tsx → Tag/Tag.tsx} +0 -0
- /package/src/components/{warning-text/warning-text.tsx → WarningText/WarningText.tsx} +0 -0
|
@@ -1,39 +1,39 @@
|
|
|
1
1
|
import { test, expect, vi } from 'vitest';
|
|
2
2
|
import { render, screen, within, fireEvent } from '@testing-library/react';
|
|
3
|
-
import Pagination, { Page, Ellipsis } from './
|
|
3
|
+
import Pagination, { Page, Ellipsis } from './Pagination';
|
|
4
4
|
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
5
|
+
const PAGE_ARIA_LABEL = 'Page 1';
|
|
6
|
+
const PAGE_HREF = '#foo';
|
|
7
|
+
const PAGE_TEXT = '1';
|
|
8
|
+
const CURRENT_PAGE = 10;
|
|
9
|
+
const TOTAL_PAGES = 21;
|
|
10
10
|
|
|
11
11
|
test('pagination page renders correctly', () => {
|
|
12
12
|
render(
|
|
13
13
|
<Page
|
|
14
|
-
ariaLabel={
|
|
15
|
-
href={
|
|
16
|
-
text={
|
|
14
|
+
ariaLabel={PAGE_ARIA_LABEL}
|
|
15
|
+
href={PAGE_HREF}
|
|
16
|
+
text={PAGE_TEXT}
|
|
17
17
|
/>
|
|
18
18
|
);
|
|
19
19
|
|
|
20
20
|
const item = screen.getByRole('listitem');
|
|
21
21
|
const link = within(item).getByRole('link');
|
|
22
|
-
const span = within(link).getByText(
|
|
22
|
+
const span = within(link).getByText(PAGE_TEXT);
|
|
23
23
|
|
|
24
24
|
expect(item).toHaveClass('ds_pagination__item');
|
|
25
25
|
expect(link).toHaveClass('ds_pagination__link');
|
|
26
|
-
expect(link).toHaveAttribute('aria-label',
|
|
27
|
-
expect(link).toHaveAttribute('href',
|
|
26
|
+
expect(link).toHaveAttribute('aria-label', PAGE_ARIA_LABEL);
|
|
27
|
+
expect(link).toHaveAttribute('href', PAGE_HREF);
|
|
28
28
|
expect(span).toHaveClass('ds_pagination__link-label');
|
|
29
29
|
});
|
|
30
30
|
|
|
31
31
|
test('current pagination page', () => {
|
|
32
32
|
render(
|
|
33
33
|
<Page
|
|
34
|
-
ariaLabel={
|
|
35
|
-
href={
|
|
36
|
-
text={
|
|
34
|
+
ariaLabel={PAGE_ARIA_LABEL}
|
|
35
|
+
href={PAGE_HREF}
|
|
36
|
+
text={PAGE_TEXT}
|
|
37
37
|
current
|
|
38
38
|
/>
|
|
39
39
|
);
|
|
@@ -46,14 +46,14 @@ test('current pagination page', () => {
|
|
|
46
46
|
});
|
|
47
47
|
|
|
48
48
|
test('pagination page with click event', () => {
|
|
49
|
-
const
|
|
49
|
+
const ONCLICK_FUNCTION = vi.fn();
|
|
50
50
|
|
|
51
51
|
render(
|
|
52
52
|
<Page
|
|
53
|
-
ariaLabel={
|
|
54
|
-
href={
|
|
55
|
-
text={
|
|
56
|
-
onClick={
|
|
53
|
+
ariaLabel={PAGE_ARIA_LABEL}
|
|
54
|
+
href={PAGE_HREF}
|
|
55
|
+
text={PAGE_TEXT}
|
|
56
|
+
onClick={ONCLICK_FUNCTION}
|
|
57
57
|
/>
|
|
58
58
|
);
|
|
59
59
|
|
|
@@ -62,7 +62,7 @@ test('pagination page with click event', () => {
|
|
|
62
62
|
|
|
63
63
|
fireEvent.click(link);
|
|
64
64
|
|
|
65
|
-
expect(
|
|
65
|
+
expect(ONCLICK_FUNCTION).toHaveBeenCalled();
|
|
66
66
|
});
|
|
67
67
|
|
|
68
68
|
test('Ellipsis item renders correctly', () => {
|
|
@@ -79,11 +79,11 @@ test('Ellipsis item renders correctly', () => {
|
|
|
79
79
|
});
|
|
80
80
|
|
|
81
81
|
test('pagination renders correctly', () => {
|
|
82
|
-
const
|
|
83
|
-
const
|
|
82
|
+
const CURRENT_PAGE = 10;
|
|
83
|
+
const TOTAL_PAGES = 21;
|
|
84
84
|
|
|
85
85
|
render(
|
|
86
|
-
<Pagination page={
|
|
86
|
+
<Pagination page={CURRENT_PAGE} totalPages={TOTAL_PAGES} />
|
|
87
87
|
);
|
|
88
88
|
|
|
89
89
|
const paginationNav = screen.getByRole('navigation');
|
|
@@ -100,7 +100,7 @@ test('pagination renders correctly', () => {
|
|
|
100
100
|
const firstPageLabel = within(paginationList).getByText('1');
|
|
101
101
|
const firstPageLink = firstPageLabel.parentElement;
|
|
102
102
|
const firstPageItem = firstPageLink?.parentElement;
|
|
103
|
-
const lastPageLabel = within(paginationList).getByText(
|
|
103
|
+
const lastPageLabel = within(paginationList).getByText(TOTAL_PAGES);
|
|
104
104
|
const lastPageLink = lastPageLabel.parentElement;
|
|
105
105
|
const lastPageItem = lastPageLink?.parentElement;
|
|
106
106
|
|
|
@@ -125,7 +125,7 @@ test('pagination renders correctly', () => {
|
|
|
125
125
|
expect(prevItem?.parentElement).toEqual(paginationList);
|
|
126
126
|
expect(prevLink).toHaveClass('ds_pagination__link', 'ds_pagination__link--text', 'ds_pagination__link--icon')
|
|
127
127
|
expect(prevLink).toHaveAttribute('aria-label', 'Previous page');
|
|
128
|
-
expect(prevLink).toHaveAttribute('href', `/search?page=${
|
|
128
|
+
expect(prevLink).toHaveAttribute('href', `/search?page=${CURRENT_PAGE - 1}`);
|
|
129
129
|
expect(prevLink?.tagName).toEqual('A');
|
|
130
130
|
expect(prevIcon).toHaveClass('ds_icon');
|
|
131
131
|
expect(prevIcon).toHaveAttribute('aria-hidden', 'true')
|
|
@@ -138,7 +138,7 @@ test('pagination renders correctly', () => {
|
|
|
138
138
|
expect(nextItem?.parentElement).toEqual(paginationList);
|
|
139
139
|
expect(nextLink).toHaveClass('ds_pagination__link', 'ds_pagination__link--text', 'ds_pagination__link--icon')
|
|
140
140
|
expect(nextLink).toHaveAttribute('aria-label', 'Next page');
|
|
141
|
-
expect(nextLink).toHaveAttribute('href', `/search?page=${
|
|
141
|
+
expect(nextLink).toHaveAttribute('href', `/search?page=${CURRENT_PAGE + 1}`);
|
|
142
142
|
expect(nextLink?.tagName).toEqual('A');
|
|
143
143
|
expect(nextIcon).toHaveClass('ds_icon');
|
|
144
144
|
expect(nextIcon).toHaveAttribute('aria-hidden', 'true')
|
|
@@ -160,8 +160,8 @@ test('pagination renders correctly', () => {
|
|
|
160
160
|
expect(lastPageItem?.tagName).toEqual('LI');
|
|
161
161
|
expect(lastPageItem?.parentElement).toEqual(paginationList);
|
|
162
162
|
expect(lastPageLink).toHaveClass('ds_pagination__link')
|
|
163
|
-
expect(lastPageLink).toHaveAttribute('aria-label', `Page ${
|
|
164
|
-
expect(lastPageLink).toHaveAttribute('href', `/search?page=${
|
|
163
|
+
expect(lastPageLink).toHaveAttribute('aria-label', `Page ${TOTAL_PAGES}`);
|
|
164
|
+
expect(lastPageLink).toHaveAttribute('href', `/search?page=${TOTAL_PAGES}`);
|
|
165
165
|
expect(lastPageLink?.tagName).toEqual('A');
|
|
166
166
|
expect(lastPageLabel).toHaveClass('ds_pagination__link-label');
|
|
167
167
|
expect(lastPageLabel?.tagName).toEqual('SPAN');
|
|
@@ -184,7 +184,7 @@ test('pagination renders correctly', () => {
|
|
|
184
184
|
|
|
185
185
|
expect(currentPageItem).toHaveClass('ds_pagination__item');
|
|
186
186
|
expect(currentPageLink).toHaveClass('ds_pagination__link', 'ds_current');
|
|
187
|
-
expect(currentPageLink?.textContent).toEqual(
|
|
187
|
+
expect(currentPageLink?.textContent).toEqual(CURRENT_PAGE.toString());
|
|
188
188
|
|
|
189
189
|
// expect one link either side of the current (default padding)
|
|
190
190
|
expect(currentPageItem?.previousElementSibling?.querySelector('a')).toHaveAttribute('aria-label', 'Page 9');
|
|
@@ -198,13 +198,13 @@ test('pagination renders correctly', () => {
|
|
|
198
198
|
});
|
|
199
199
|
|
|
200
200
|
test('pagination with 2 padding', () => {
|
|
201
|
-
const
|
|
201
|
+
const PADDING = 2;
|
|
202
202
|
|
|
203
203
|
render(
|
|
204
204
|
<Pagination
|
|
205
|
-
page={
|
|
206
|
-
totalPages={
|
|
207
|
-
padding={
|
|
205
|
+
page={CURRENT_PAGE}
|
|
206
|
+
totalPages={TOTAL_PAGES}
|
|
207
|
+
padding={PADDING}
|
|
208
208
|
/>
|
|
209
209
|
);
|
|
210
210
|
|
|
@@ -217,29 +217,29 @@ test('pagination with 2 padding', () => {
|
|
|
217
217
|
});
|
|
218
218
|
|
|
219
219
|
test('pagination with custom aria label', () => {
|
|
220
|
-
const
|
|
220
|
+
const ARIA_LABEL = 'My label';
|
|
221
221
|
|
|
222
222
|
render(
|
|
223
223
|
<Pagination
|
|
224
|
-
page={
|
|
225
|
-
totalPages={
|
|
226
|
-
ariaLabel={
|
|
224
|
+
page={CURRENT_PAGE}
|
|
225
|
+
totalPages={TOTAL_PAGES}
|
|
226
|
+
ariaLabel={ARIA_LABEL}
|
|
227
227
|
/>
|
|
228
228
|
);
|
|
229
229
|
|
|
230
230
|
const paginationNav = screen.getByRole('navigation');
|
|
231
231
|
|
|
232
|
-
expect(paginationNav).toHaveAttribute('aria-label',
|
|
232
|
+
expect(paginationNav).toHaveAttribute('aria-label', ARIA_LABEL);
|
|
233
233
|
});
|
|
234
234
|
|
|
235
235
|
test('pagination passes onclick event to child links', () => {
|
|
236
|
-
const
|
|
236
|
+
const ONCLICK_FUNCTION = vi.fn();
|
|
237
237
|
|
|
238
238
|
render(
|
|
239
239
|
<Pagination
|
|
240
|
-
page={
|
|
241
|
-
totalPages={
|
|
242
|
-
onClick={
|
|
240
|
+
page={CURRENT_PAGE}
|
|
241
|
+
totalPages={TOTAL_PAGES}
|
|
242
|
+
onClick={ONCLICK_FUNCTION}
|
|
243
243
|
/>
|
|
244
244
|
);
|
|
245
245
|
|
|
@@ -249,14 +249,14 @@ test('pagination passes onclick event to child links', () => {
|
|
|
249
249
|
|
|
250
250
|
fireEvent.click(link);
|
|
251
251
|
|
|
252
|
-
expect(
|
|
252
|
+
expect(ONCLICK_FUNCTION).toHaveBeenCalled();
|
|
253
253
|
});
|
|
254
254
|
|
|
255
255
|
test('pagination modifies an input pattern for its link format', () => {
|
|
256
256
|
render(
|
|
257
257
|
<Pagination
|
|
258
|
-
page={
|
|
259
|
-
totalPages={
|
|
258
|
+
page={CURRENT_PAGE}
|
|
259
|
+
totalPages={TOTAL_PAGES}
|
|
260
260
|
pattern='My/Link/Format?Page=$1#foo'
|
|
261
261
|
/>
|
|
262
262
|
);
|
|
@@ -271,7 +271,7 @@ test('pagination at an early link in the list', () => {
|
|
|
271
271
|
render(
|
|
272
272
|
<Pagination
|
|
273
273
|
page="1"
|
|
274
|
-
totalPages={
|
|
274
|
+
totalPages={TOTAL_PAGES}
|
|
275
275
|
/>
|
|
276
276
|
);
|
|
277
277
|
|
|
@@ -289,7 +289,7 @@ test('pagination at an early link in the list, increased padding', () => {
|
|
|
289
289
|
<Pagination
|
|
290
290
|
padding={2}
|
|
291
291
|
page="1"
|
|
292
|
-
totalPages={
|
|
292
|
+
totalPages={TOTAL_PAGES}
|
|
293
293
|
/>
|
|
294
294
|
);
|
|
295
295
|
|
|
@@ -305,8 +305,8 @@ test('pagination at an early link in the list, increased padding', () => {
|
|
|
305
305
|
test('pagination at late link in the list', () => {
|
|
306
306
|
render(
|
|
307
307
|
<Pagination
|
|
308
|
-
page={
|
|
309
|
-
totalPages={
|
|
308
|
+
page={TOTAL_PAGES}
|
|
309
|
+
totalPages={TOTAL_PAGES}
|
|
310
310
|
/>
|
|
311
311
|
);
|
|
312
312
|
|
|
@@ -323,8 +323,8 @@ test('pagination at late link in the list, increased padding', () => {
|
|
|
323
323
|
render(
|
|
324
324
|
<Pagination
|
|
325
325
|
padding={2}
|
|
326
|
-
page={
|
|
327
|
-
totalPages={
|
|
326
|
+
page={TOTAL_PAGES}
|
|
327
|
+
totalPages={TOTAL_PAGES}
|
|
328
328
|
/>
|
|
329
329
|
);
|
|
330
330
|
|
|
@@ -340,8 +340,8 @@ test('pagination at late link in the list, increased padding', () => {
|
|
|
340
340
|
test('passing additional props', () => {
|
|
341
341
|
render(
|
|
342
342
|
<Pagination
|
|
343
|
-
page={
|
|
344
|
-
totalPages={
|
|
343
|
+
page={CURRENT_PAGE}
|
|
344
|
+
totalPages={TOTAL_PAGES}
|
|
345
345
|
data-test="foo"
|
|
346
346
|
/>
|
|
347
347
|
);
|
|
@@ -353,8 +353,8 @@ test('passing additional props', () => {
|
|
|
353
353
|
test('passing additional CSS classes', () => {
|
|
354
354
|
render(
|
|
355
355
|
<Pagination
|
|
356
|
-
page={
|
|
357
|
-
totalPages={
|
|
356
|
+
page={CURRENT_PAGE}
|
|
357
|
+
totalPages={TOTAL_PAGES}
|
|
358
358
|
className="foo"
|
|
359
359
|
/>
|
|
360
360
|
)
|
package/src/components/{phase-banner/phase-banner.test.tsx → PhaseBanner/PhaseBanner.test.tsx}
RENAMED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { test, expect } from 'vitest';
|
|
2
2
|
import { render } from '@testing-library/react';
|
|
3
|
-
import PhaseBanner from './
|
|
3
|
+
import PhaseBanner from './PhaseBanner';
|
|
4
4
|
|
|
5
|
-
const
|
|
6
|
-
const
|
|
5
|
+
const BANNER_TEXT = 'This is a new service. Your feedback will help us to improve it.';
|
|
6
|
+
const DEFAULT_TEXT = 'This is a new service';
|
|
7
7
|
|
|
8
8
|
test('phase banner renders correctly', () => {
|
|
9
9
|
render(
|
|
10
10
|
<PhaseBanner>
|
|
11
|
-
{
|
|
11
|
+
{BANNER_TEXT}
|
|
12
12
|
</PhaseBanner>
|
|
13
13
|
);
|
|
14
14
|
|
|
@@ -23,7 +23,7 @@ test('phase banner renders correctly', () => {
|
|
|
23
23
|
expect(phaseBannerWrapper?.tagName).toEqual('DIV');
|
|
24
24
|
expect(phaseBannerContent?.tagName).toEqual('P');
|
|
25
25
|
expect(phaseBannerText?.tagName).toEqual('SPAN');
|
|
26
|
-
expect(phaseBannerText?.textContent).toEqual(
|
|
26
|
+
expect(phaseBannerText?.textContent).toEqual(BANNER_TEXT);
|
|
27
27
|
});
|
|
28
28
|
|
|
29
29
|
test('phase banner with default text', () => {
|
|
@@ -36,14 +36,14 @@ test('phase banner with default text', () => {
|
|
|
36
36
|
const phaseBannerContent = phaseBanner?.querySelector('.ds_phase-banner__content');
|
|
37
37
|
const phaseBannerText = phaseBannerContent?.querySelector('.ds_phase-banner__text');
|
|
38
38
|
|
|
39
|
-
expect(phaseBannerText?.textContent).toEqual(
|
|
39
|
+
expect(phaseBannerText?.textContent).toEqual(DEFAULT_TEXT);
|
|
40
40
|
});
|
|
41
41
|
|
|
42
42
|
test('phase banner with phase tag', () => {
|
|
43
|
-
const
|
|
43
|
+
const PHASE_TEXT = 'Beta';
|
|
44
44
|
|
|
45
45
|
render(
|
|
46
|
-
<PhaseBanner phaseName={
|
|
46
|
+
<PhaseBanner phaseName={PHASE_TEXT}></PhaseBanner>
|
|
47
47
|
);
|
|
48
48
|
|
|
49
49
|
const phaseBanner = document.querySelector('.ds_phase-banner');
|
|
@@ -52,7 +52,7 @@ test('phase banner with phase tag', () => {
|
|
|
52
52
|
expect(phaseBannerTag).toBeInTheDocument();
|
|
53
53
|
expect(phaseBannerTag?.tagName).toEqual('SPAN');
|
|
54
54
|
expect(phaseBannerTag).toHaveClass('ds_tag', 'ds_phase-banner__tag');
|
|
55
|
-
expect(phaseBannerTag?.textContent).toEqual(
|
|
55
|
+
expect(phaseBannerTag?.textContent).toEqual(PHASE_TEXT);
|
|
56
56
|
});
|
|
57
57
|
|
|
58
58
|
test('passing additional props', () => {
|
|
@@ -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', () => {
|