@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.
Files changed (151) hide show
  1. package/@types/components/Accordion.d.ts +2 -2
  2. package/@types/components/ConfirmationMessage.d.ts +1 -1
  3. package/@types/components/NotificationPanel.d.ts +1 -1
  4. package/@types/components/SummaryCard.d.ts +1 -1
  5. package/@types/components/Tabs.d.ts +1 -1
  6. package/@types/sgds.d.ts +1 -1
  7. package/CHANGELOG.md +81 -0
  8. package/README.md +4 -0
  9. package/dist/common/AbstractNotificationBanner.jsx +63 -0
  10. package/dist/common/ConditionalWrapper.jsx +8 -0
  11. package/dist/common/FileIcon.jsx +51 -0
  12. package/dist/common/HintText.jsx +9 -0
  13. package/dist/common/Icon.jsx +57 -0
  14. package/dist/common/ScreenReaderText.jsx +9 -0
  15. package/dist/common/WrapperTag.jsx +11 -0
  16. package/dist/components/Accordion/Accordion.jsx +102 -0
  17. package/dist/components/AspectBox/AspectBox.jsx +79 -0
  18. package/dist/components/BackToTop/BackToTop.jsx +27 -0
  19. package/dist/components/Breadcrumbs/Breadcrumbs.jsx +28 -0
  20. package/dist/components/Button/Button.jsx +30 -0
  21. package/dist/components/Checkbox/Checkbox.jsx +62 -0
  22. package/dist/components/ConfirmationMessage/ConfirmationMessage.jsx +24 -0
  23. package/dist/components/ContentsNav/ContentsNav.jsx +33 -0
  24. package/dist/components/CookieBanner/CookieBanner.jsx +21 -0
  25. package/dist/components/DatePicker/DatePicker.jsx +54 -0
  26. package/dist/components/Details/Details.jsx +17 -0
  27. package/dist/components/ErrorMessage/ErrorMessage.jsx +12 -0
  28. package/dist/components/ErrorSummary/ErrorSummary.jsx +27 -0
  29. package/dist/components/FileDownload/FileDownload.jsx +50 -0
  30. package/dist/components/HideThisPage/HideThisPage.jsx +71 -0
  31. package/dist/components/InsetText/InsetText.jsx +14 -0
  32. package/dist/components/NotificationBanner/NotificationBanner.jsx +26 -0
  33. package/dist/components/NotificationPanel/NotificationPanel.jsx +21 -0
  34. package/dist/components/PageHeader/PageHeader.jsx +15 -0
  35. package/dist/components/PageMetadata/PageMetadata.jsx +26 -0
  36. package/dist/components/Pagination/Pagination.jsx +97 -0
  37. package/dist/components/PhaseBanner/PhaseBanner.jsx +23 -0
  38. package/dist/components/Question/Question.jsx +22 -0
  39. package/dist/components/RadioButton/RadioButton.jsx +43 -0
  40. package/dist/components/Select/Select.jsx +52 -0
  41. package/dist/components/SequentialNavigation/SequentialNavigation.jsx +31 -0
  42. package/dist/components/SideNavigation/SideNavigation.jsx +52 -0
  43. package/dist/components/SiteHeader/SiteHeader.jsx +68 -0
  44. package/dist/components/SiteNavigation/SiteNavigation.jsx +22 -0
  45. package/dist/components/SiteSearch/SiteSearch.jsx +55 -0
  46. package/dist/components/SkipLinks/SkipLinks.jsx +21 -0
  47. package/dist/components/SummaryCard/SummaryCard.jsx +67 -0
  48. package/dist/components/SummaryList/SummaryList.jsx +75 -0
  49. package/dist/components/Table/Table.jsx +24 -0
  50. package/dist/components/Tabs/Tabs.jsx +99 -0
  51. package/dist/components/Tag/Tag.jsx +13 -0
  52. package/dist/components/TaskList/TaskList.jsx +95 -0
  53. package/dist/components/TextInput/TextInput.jsx +58 -0
  54. package/dist/components/Textarea/Textarea.jsx +54 -0
  55. package/dist/components/WarningText/WarningText.jsx +16 -0
  56. package/dist/tsconfig.tsbuildinfo +1 -1
  57. package/package.json +1 -1
  58. package/src/common/{abstract-notification-banner.test.tsx → AbstractNotificationBanner.test.tsx} +11 -11
  59. package/src/common/{abstract-notification-banner.tsx → AbstractNotificationBanner.tsx} +2 -2
  60. package/src/common/{conditional-wrapper.test.tsx → ConditionalWrapper.test.tsx} +1 -1
  61. package/src/common/{file-icon.test.tsx → FileIcon.test.tsx} +10 -10
  62. package/src/common/{hint-text.test.tsx → HintText.test.tsx} +12 -12
  63. package/src/common/{icon.test.tsx → Icon.test.tsx} +16 -16
  64. package/src/common/{screen-reader-text.test.tsx → ScreenReaderText.test.tsx} +5 -5
  65. package/src/common/{wrapper-tag.test.tsx → WrapperTag.test.tsx} +5 -5
  66. package/src/components/{accordion/accordion.test.tsx → Accordion/Accordion.test.tsx} +35 -35
  67. package/src/components/{accordion/accordion.tsx → Accordion/Accordion.tsx} +5 -5
  68. package/src/components/{aspect-box/aspect-box.test.tsx → AspectBox/AspectBox.test.tsx} +2 -2
  69. package/src/components/{back-to-top/back-to-top.test.tsx → BackToTop/BackToTop.test.tsx} +1 -1
  70. package/src/components/{back-to-top/back-to-top.tsx → BackToTop/BackToTop.tsx} +1 -1
  71. package/src/components/{breadcrumbs/breadcrumbs.test.tsx → Breadcrumbs/Breadcrumbs.test.tsx} +7 -7
  72. package/src/components/{button/button.test.tsx → Button/Button.test.tsx} +1 -1
  73. package/src/components/{button/button.tsx → Button/Button.tsx} +3 -3
  74. package/src/components/{checkbox/checkbox.test.tsx → Checkbox/Checkbox.test.tsx} +16 -16
  75. package/src/components/{checkbox/checkbox.tsx → Checkbox/Checkbox.tsx} +1 -1
  76. package/src/components/{confirmation-message/confirmation-message.test.tsx → ConfirmationMessage/ConfirmationMessage.test.tsx} +12 -14
  77. package/src/components/{confirmation-message/confirmation-message.tsx → ConfirmationMessage/ConfirmationMessage.tsx} +4 -4
  78. package/src/components/{contents-nav/contents-nav.test.tsx → ContentsNav/ContentsNav.test.tsx} +21 -28
  79. package/src/components/{contents-nav/contents-nav.tsx → ContentsNav/ContentsNav.tsx} +1 -1
  80. package/src/components/{cookie-banner/cookie-banner.test.tsx → CookieBanner/CookieBanner.test.tsx} +3 -3
  81. package/src/components/{cookie-banner/cookie-banner.tsx → CookieBanner/CookieBanner.tsx} +1 -1
  82. package/src/components/{date-picker/date-picker.test.tsx → DatePicker/DatePicker.test.tsx} +76 -66
  83. package/src/components/{date-picker/date-picker.tsx → DatePicker/DatePicker.tsx} +2 -2
  84. package/src/components/{details/details.test.tsx → Details/Details.test.tsx} +10 -10
  85. package/src/components/{error-message/error-message.test.tsx → ErrorMessage/ErrorMessage.test.tsx} +10 -10
  86. package/src/components/{error-summary/error-summary.test.tsx → ErrorSummary/ErrorSummary.test.tsx} +13 -14
  87. package/src/components/{error-summary/error-summary.tsx → ErrorSummary/ErrorSummary.tsx} +1 -1
  88. package/src/components/{file-download/file-download.test.tsx → FileDownload/FileDownload.test.tsx} +21 -21
  89. package/src/components/{file-download/file-download.tsx → FileDownload/FileDownload.tsx} +1 -1
  90. package/src/components/{hide-this-page/hide-this-page.test.tsx → HideThisPage/HideThisPage.test.tsx} +4 -4
  91. package/src/components/{hide-this-page/hide-this-page.tsx → HideThisPage/HideThisPage.tsx} +3 -3
  92. package/src/components/{inset-text/inset-text.test.tsx → InsetText/InsetText.test.tsx} +1 -1
  93. package/src/components/{notification-banner/notification-banner.test.tsx → NotificationBanner/NotificationBanner.test.tsx} +4 -4
  94. package/src/components/{notification-banner/notification-banner.tsx → NotificationBanner/NotificationBanner.tsx} +1 -1
  95. package/src/components/{notification-panel/notification-panel.test.tsx → NotificationPanel/NotificationPanel.test.tsx} +24 -23
  96. package/src/components/{notification-panel/notification-panel.tsx → NotificationPanel/NotificationPanel.tsx} +3 -3
  97. package/src/components/{page-header/page-header.test.tsx → PageHeader/PageHeader.test.tsx} +9 -9
  98. package/src/components/{page-metadata/page-metadata.test.tsx → PageMetadata/PageMetadata.test.tsx} +9 -9
  99. package/src/components/{pagination/pagination.test.tsx → Pagination/Pagination.test.tsx} +56 -56
  100. package/src/components/{pagination/pagination.tsx → Pagination/Pagination.tsx} +1 -1
  101. package/src/components/{phase-banner/phase-banner.test.tsx → PhaseBanner/PhaseBanner.test.tsx} +9 -9
  102. package/src/components/{phase-banner/phase-banner.tsx → PhaseBanner/PhaseBanner.tsx} +1 -1
  103. package/src/components/{question/question.test.tsx → Question/Question.test.tsx} +10 -10
  104. package/src/components/{question/question.tsx → Question/Question.tsx} +3 -3
  105. package/src/components/{radio-button/radio-button.test.tsx → RadioButton/RadioButton.test.tsx} +23 -23
  106. package/src/components/{radio-button/radio-button.tsx → RadioButton/RadioButton.tsx} +1 -1
  107. package/src/components/{select/select.test.tsx → Select/Select.test.tsx} +67 -64
  108. package/src/components/{select/select.tsx → Select/Select.tsx} +2 -2
  109. package/src/components/{sequential-navigation/sequential-navigation.test.tsx → SequentialNavigation/SequentialNavigation.test.tsx} +18 -18
  110. package/src/components/{side-navigation/side-navigation.test.tsx → SideNavigation/SideNavigation.test.tsx} +8 -8
  111. package/src/components/{site-header/site-header.test.tsx → SiteHeader/SiteHeader.test.tsx} +25 -25
  112. package/src/components/{site-header/site-header.tsx → SiteHeader/SiteHeader.tsx} +4 -4
  113. package/src/components/{site-navigation/site-navigation.test.tsx → SiteNavigation/SiteNavigation.test.tsx} +8 -8
  114. package/src/components/{site-search/site-search.test.tsx → SiteSearch/SiteSearch.test.tsx} +16 -16
  115. package/src/components/{site-search/site-search.tsx → SiteSearch/SiteSearch.tsx} +1 -1
  116. package/src/components/{skip-links/skip-links.test.tsx → SkipLinks/SkipLinks.test.tsx} +15 -15
  117. package/src/components/{summary-card/summary-card.test.tsx → SummaryCard/SummaryCard.test.tsx} +28 -28
  118. package/src/components/{summary-card/summary-card.tsx → SummaryCard/SummaryCard.tsx} +4 -4
  119. package/src/components/{summary-list/summary-list.test.tsx → SummaryList/SummaryList.test.tsx} +55 -56
  120. package/src/components/{summary-list/summary-list.tsx → SummaryList/SummaryList.tsx} +2 -2
  121. package/src/components/{table/table.test.tsx → Table/Table.test.tsx} +4 -4
  122. package/src/components/{tabs/tabs.test.tsx → Tabs/Tabs.test.tsx} +22 -42
  123. package/src/components/{tabs/tabs.tsx → Tabs/Tabs.tsx} +3 -3
  124. package/src/components/{tag/tag.test.tsx → Tag/Tag.test.tsx} +10 -10
  125. package/src/components/{task-list/task-list.test.tsx → TaskList/TaskList.test.tsx} +109 -108
  126. package/src/components/{task-list/task-list.tsx → TaskList/TaskList.tsx} +4 -4
  127. package/src/components/{text-input/text-input.test.tsx → TextInput/TextInput.test.tsx} +92 -87
  128. package/src/components/{text-input/text-input.tsx → TextInput/TextInput.tsx} +4 -4
  129. package/src/components/{textarea/textarea.test.tsx → Textarea/Textarea.test.tsx} +71 -67
  130. package/src/components/{textarea/textarea.tsx → Textarea/Textarea.tsx} +3 -3
  131. package/src/components/{warning-text/warning-text.test.tsx → WarningText/WarningText.test.tsx} +1 -1
  132. /package/src/common/{conditional-wrapper.tsx → ConditionalWrapper.tsx} +0 -0
  133. /package/src/common/{file-icon.tsx → FileIcon.tsx} +0 -0
  134. /package/src/common/{hint-text.tsx → HintText.tsx} +0 -0
  135. /package/src/common/{icon.tsx → Icon.tsx} +0 -0
  136. /package/src/common/{screen-reader-text.tsx → ScreenReaderText.tsx} +0 -0
  137. /package/src/common/{wrapper-tag.tsx → WrapperTag.tsx} +0 -0
  138. /package/src/components/{aspect-box/aspect-box.tsx → AspectBox/AspectBox.tsx} +0 -0
  139. /package/src/components/{breadcrumbs/breadcrumbs.tsx → Breadcrumbs/Breadcrumbs.tsx} +0 -0
  140. /package/src/components/{details/details.tsx → Details/Details.tsx} +0 -0
  141. /package/src/components/{error-message/error-message.tsx → ErrorMessage/ErrorMessage.tsx} +0 -0
  142. /package/src/components/{inset-text/inset-text.tsx → InsetText/InsetText.tsx} +0 -0
  143. /package/src/components/{page-header/page-header.tsx → PageHeader/PageHeader.tsx} +0 -0
  144. /package/src/components/{page-metadata/page-metadata.tsx → PageMetadata/PageMetadata.tsx} +0 -0
  145. /package/src/components/{sequential-navigation/sequential-navigation.tsx → SequentialNavigation/SequentialNavigation.tsx} +0 -0
  146. /package/src/components/{side-navigation/side-navigation.tsx → SideNavigation/SideNavigation.tsx} +0 -0
  147. /package/src/components/{site-navigation/site-navigation.tsx → SiteNavigation/SiteNavigation.tsx} +0 -0
  148. /package/src/components/{skip-links/skip-links.tsx → SkipLinks/SkipLinks.tsx} +0 -0
  149. /package/src/components/{table/table.tsx → Table/Table.tsx} +0 -0
  150. /package/src/components/{tag/tag.tsx → Tag/Tag.tsx} +0 -0
  151. /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 './pagination';
3
+ import Pagination, { Page, Ellipsis } from './Pagination';
4
4
 
5
- const pageAriaLabel = 'Page 1';
6
- const pageHref = '#foo';
7
- const pageText = '1';
8
- const currentPage = 10;
9
- const totalPages = 21;
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={pageAriaLabel}
15
- href={pageHref}
16
- text={pageText}
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(pageText);
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', pageAriaLabel);
27
- expect(link).toHaveAttribute('href', pageHref);
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={pageAriaLabel}
35
- href={pageHref}
36
- text={pageText}
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 onClickFn = vi.fn();
49
+ const ONCLICK_FUNCTION = vi.fn();
50
50
 
51
51
  render(
52
52
  <Page
53
- ariaLabel={pageAriaLabel}
54
- href={pageHref}
55
- text={pageText}
56
- onClick={onClickFn}
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(onClickFn).toHaveBeenCalled();
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 currentPage = 10;
83
- const totalPages = 21;
82
+ const CURRENT_PAGE = 10;
83
+ const TOTAL_PAGES = 21;
84
84
 
85
85
  render(
86
- <Pagination page={currentPage} totalPages={totalPages} />
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(totalPages);
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=${currentPage - 1}`);
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=${currentPage + 1}`);
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 ${totalPages}`);
164
- expect(lastPageLink).toHaveAttribute('href', `/search?page=${totalPages}`);
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(currentPage.toString());
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 padding = 2;
201
+ const PADDING = 2;
202
202
 
203
203
  render(
204
204
  <Pagination
205
- page={currentPage}
206
- totalPages={totalPages}
207
- padding={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 ariaLabel = 'My label';
220
+ const ARIA_LABEL = 'My label';
221
221
 
222
222
  render(
223
223
  <Pagination
224
- page={currentPage}
225
- totalPages={totalPages}
226
- ariaLabel={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', ariaLabel);
232
+ expect(paginationNav).toHaveAttribute('aria-label', ARIA_LABEL);
233
233
  });
234
234
 
235
235
  test('pagination passes onclick event to child links', () => {
236
- const onClickFn = vi.fn();
236
+ const ONCLICK_FUNCTION = vi.fn();
237
237
 
238
238
  render(
239
239
  <Pagination
240
- page={currentPage}
241
- totalPages={totalPages}
242
- onClick={onClickFn}
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(onClickFn).toHaveBeenCalled();
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={currentPage}
259
- totalPages={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={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={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={totalPages}
309
- totalPages={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={totalPages}
327
- totalPages={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={currentPage}
344
- totalPages={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={currentPage}
357
- totalPages={totalPages}
356
+ page={CURRENT_PAGE}
357
+ totalPages={TOTAL_PAGES}
358
358
  className="foo"
359
359
  />
360
360
  )
@@ -1,4 +1,4 @@
1
- import Icon from "../../common/icon";
1
+ import Icon from "../../common/Icon";
2
2
 
3
3
  export const Page: React.FC<SGDS.Component.Pagination.Page> = ({
4
4
  ariaLabel,
@@ -1,14 +1,14 @@
1
1
  import { test, expect } from 'vitest';
2
2
  import { render } from '@testing-library/react';
3
- import PhaseBanner from './phase-banner';
3
+ import PhaseBanner from './PhaseBanner';
4
4
 
5
- const text = 'This is a new service. Your feedback will help us to improve it.';
6
- const defaultText = 'This is a new service';
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
- {text}
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(text);
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(defaultText);
39
+ expect(phaseBannerText?.textContent).toEqual(DEFAULT_TEXT);
40
40
  });
41
41
 
42
42
  test('phase banner with phase tag', () => {
43
- const phase = 'Beta';
43
+ const PHASE_TEXT = 'Beta';
44
44
 
45
45
  render(
46
- <PhaseBanner phaseName={phase}></PhaseBanner>
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(phase);
55
+ expect(phaseBannerTag?.textContent).toEqual(PHASE_TEXT);
56
56
  });
57
57
 
58
58
  test('passing additional props', () => {
@@ -1,4 +1,4 @@
1
- import Tag from "../tag/tag";
1
+ import Tag from "../Tag/Tag";
2
2
 
3
3
  const PhaseBanner: React.FC<SGDS.Component.PhaseBanner> = ({
4
4
  children,
@@ -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 './question';
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 legendText = 'My legend';
17
+ const LEGEND_TEXT = 'My legend';
18
18
 
19
19
  render(
20
- <Question tagName="fieldset" legend={legendText}>
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(legendText);
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 hintText = 'My hint text';
31
+ const HINT_TEXT = 'My hint text';
32
32
 
33
33
  render(
34
- <Question hintText={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(hintText);
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 errorMessage = 'My error message';
46
+ const ERROR_MESSAGE_TEXT = 'My error message';
47
47
 
48
48
  render(
49
- <Question error errorMessage={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(errorMessage);
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 '../error-message/error-message';
2
- import HintText from '../../common/hint-text';
3
- import WrapperTag from '../../common/wrapper-tag';
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,
@@ -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 './radio-button';
3
+ import RadioGroup, { Radio } from './RadioButton';
4
4
 
5
5
  test('radio group renders correct children', () => {
6
- const items = [
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 groupName = "foo"
25
+ const GROUP_NAME = "foo"
26
26
 
27
27
  render(
28
- <RadioGroup name={groupName} items={items} />
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(items.length);
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 items = [
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 groupName = "yesno"
48
+ const GROUP_NAME = "yesno"
49
49
 
50
50
  render(
51
- <RadioGroup inline name={groupName} items={items} />
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 onBlurFn = vi.fn();
62
- const onChangeFn = vi.fn();
63
- const groupName = "foo"
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={groupName} small items={[
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: {onBlurFn},
74
- onChange: {onChangeFn},
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', groupName);
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(onBlurFn).toHaveBeenCalled();
92
+ // expect(ONBLUR_FUNCTION).toHaveBeenCalled();
93
93
 
94
94
  // fireEvent.click(radio);
95
- // expect(onChangeFn).toHaveBeenCalled();
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 onBlurFn = vi.fn();
129
+ const ONBLUR_FUNCTION = vi.fn();
130
130
 
131
131
  render(
132
- <Radio onBlur={onBlurFn} name="benefitType" label="Pension Credit" id="pensioncredit" />
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(onBlurFn).toHaveBeenCalled();
139
+ expect(ONBLUR_FUNCTION).toHaveBeenCalled();
140
140
  });
141
141
 
142
142
  test('radio with change fn', () => {
143
- const onChangeFn = vi.fn();
143
+ const ONCHANGE_FUNCTION = vi.fn();
144
144
 
145
145
  render(
146
- <Radio onChange={onChangeFn} name="benefitType" label="Pension Credit" id="pensioncredit" />
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(onChangeFn).toHaveBeenCalled();
153
+ expect(ONCHANGE_FUNCTION).toHaveBeenCalled();
154
154
  });
155
155
 
156
156
  test('radio with hint text', () => {
@@ -1,4 +1,4 @@
1
- import HintText from '../../common/hint-text';
1
+ import HintText from '../../common/HintText';
2
2
 
3
3
  export const Radio: React.FC<SGDS.Component.RadioButton> = ({
4
4
  checked,