@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,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 './select';
3
+ import Select from './Select';
4
4
 
5
- const id = 'select-component';
6
- const labelText = 'choose a component';
7
- const options = [
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={id}
26
- label={labelText}
27
- options={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(id);
38
- expect(select).toHaveAttribute('name', id);
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', id);
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 width = 'fixed-10';
52
+ const SELECTWIDTH = 'fixed-10';
53
53
 
54
54
  render(
55
55
  <Select
56
- id={id}
57
- label={labelText}
58
- options={options}
59
- width={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--${width}`);
64
+ expect(selectWrapper).toHaveClass(`ds_input--${SELECTWIDTH}`);
65
65
  });
66
66
 
67
67
  test('select with hint text', () => {
68
- const hintText = 'hint text';
68
+ const HINT_TEXT = 'hint text';
69
69
 
70
70
  render(
71
71
  <Select
72
- id={id}
73
- label={labelText}
74
- options={options}
75
- hintText={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(hintText);
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 name = 'foo';
87
+ const SELECT_NAME = 'foo';
88
88
 
89
89
  render(
90
90
  <Select
91
- id={id}
92
- label={labelText}
93
- options={options}
94
- name={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', name);
99
+ expect(select).toHaveAttribute('name', SELECT_NAME);
100
100
  });
101
101
 
102
102
  test('select with blur function', () => {
103
- const onBlurFn = vi.fn();
103
+ const ONBLUR_FUNCTION = vi.fn();
104
+
104
105
  render(
105
106
  <Select
106
- id={id}
107
- label={labelText}
108
- options={options}
109
- onBlur={onBlurFn}
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(onBlurFn).toHaveBeenCalled();
118
+ expect(ONBLUR_FUNCTION).toHaveBeenCalled();
118
119
  });
119
120
 
120
121
  test('select with change function', () => {
121
- const onChangeFn = vi.fn();
122
+ const ONCHANGE_FUNCTION = vi.fn();
123
+
122
124
  render(
123
125
  <Select
124
- id={id}
125
- label={labelText}
126
- options={options}
127
- onChange={onChangeFn}
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(onChangeFn).toHaveBeenCalled();
137
+ expect(ONCHANGE_FUNCTION).toHaveBeenCalled();
136
138
  });
137
139
 
138
140
  test('select with placeholder option', () => {
139
- const placeholder = 'foo';
141
+ const PLACEHOLDER_TEXT = 'foo';
140
142
 
141
143
  render(
142
144
  <Select
143
- id={id}
144
- label={labelText}
145
- options={options}
146
- placeholder={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(placeholder);
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 initialValue = 'button';
159
+ const INITIAL_VALUE = 'button';
158
160
 
159
161
  render(
160
162
  <Select
161
- id={id}
162
- label={labelText}
163
- options={options}
164
- defaultValue={initialValue}
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', initialValue);
172
+ expect(selectedOption).toHaveAttribute('value', INITIAL_VALUE);
171
173
  });
172
174
 
173
175
  test('select with error message', () => {
174
- const errorMessage = 'This is a required field';
176
+ const ERROR_MESSAGE_TEXT = 'This is a required field';
177
+
175
178
  render(
176
179
  <Select
177
- id={id}
178
- label={labelText}
179
- options={options}
180
+ id={SELECT_ID}
181
+ label={LABEL_TEXT}
182
+ options={OPTIONS}
180
183
  error
181
- errorMessage={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(errorMessage);
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={id}
200
- label={labelText}
201
- options={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={id}
215
- label={labelText}
216
- options={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 '../error-message/error-message';
2
- import HintText from '../../common/hint-text';
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 './sequential-navigation';
3
+ import SequentialNavigation from './SequentialNavigation';
4
4
 
5
- const nextLinkObj = { title: 'Apply for or renew a Blue Badge?', href: '#prev' }
6
- const prevLinkObj = { title: 'Apply for or renew a Blue Badge?', href: '#prev' }
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={nextLinkObj}
12
- previous={prevLinkObj}
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', prevLinkObj.href);
27
- expect(prevLink.textContent).toEqual(prevLinkObj.title);
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', nextLinkObj.href);
34
- expect(nextLink.textContent).toEqual(nextLinkObj.title);
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 ariaLabel = 'My label';
41
+ const ARIA_LABEL = 'My label';
42
42
 
43
43
  render(
44
44
  <SequentialNavigation
45
- ariaLabel={ariaLabel}
46
- next={nextLinkObj}
47
- previous={prevLinkObj}
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', ariaLabel);
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={nextLinkObj}
61
- previous={prevLinkObj}
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={nextLinkObj}
74
- previous={prevLinkObj}
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 './side-navigation';
3
+ import SideNavigation, { List, Link } from './SideNavigation';
4
4
 
5
- const items = [
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={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 items = [
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={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(items.length);
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={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={items} />
169
+ <SideNavigation className="foo" items={ITEMS} />
170
170
  );
171
171
 
172
172
  const sideNavigation = screen.getByRole('navigation');
@@ -1,9 +1,9 @@
1
1
  import { test, expect } from 'vitest';
2
2
  import { render, screen, within } from '@testing-library/react';
3
- import SiteHeader from './site-header';
4
- import SiteNavigation from '../site-navigation/site-navigation';
5
- import SiteSearch from '../site-search/site-search';
6
- import PhaseBanner from '../phase-banner/phase-banner';
3
+ import SiteHeader from './SiteHeader';
4
+ import SiteNavigation from '../SiteNavigation/SiteNavigation';
5
+ import SiteSearch from '../SiteSearch/SiteSearch';
6
+ import PhaseBanner from '../PhaseBanner/PhaseBanner';
7
7
 
8
8
  test('site header renders correctly (maximal, testing markup structure)', () => {
9
9
  render(
@@ -67,14 +67,14 @@ test('site header renders correctly (maximal, testing markup structure)', () =>
67
67
  });
68
68
 
69
69
  test('site header branding: logo only, default URL', () => {
70
- const logo = {
70
+ const LOGO = {
71
71
  alt: 'The Scottish Government',
72
72
  src: './scottish-government.svg'
73
73
  };
74
74
 
75
75
  render(
76
76
  <SiteHeader
77
- logo={logo}
77
+ logo={LOGO}
78
78
  />
79
79
  );
80
80
 
@@ -87,24 +87,24 @@ test('site header branding: logo only, default URL', () => {
87
87
  expect(siteHeaderLogoLink).toHaveAttribute('href', '/');
88
88
 
89
89
  expect(siteHeaderLogoImg).toHaveClass('ds_site-branding__logo-image');
90
- expect(siteHeaderLogoImg).toHaveAttribute('src', logo.src);
91
- expect(siteHeaderLogoImg).toHaveAttribute('alt', logo.alt);
90
+ expect(siteHeaderLogoImg).toHaveAttribute('src', LOGO.src);
91
+ expect(siteHeaderLogoImg).toHaveAttribute('alt', LOGO.alt);
92
92
 
93
93
  expect(siteHeaderLogoImg.parentElement).toEqual(siteHeaderLogoLink);
94
94
  expect(siteHeaderLogoLink.parentElement).toEqual(siteHeaderBranding);
95
95
  });
96
96
 
97
97
  test('site header branding: logo and site title', () => {
98
- const logo = {
98
+ const LOGO = {
99
99
  alt: 'The Scottish Government',
100
100
  src: './scottish-government.svg'
101
101
  };
102
- const siteTitleContent = 'Design System React';
102
+ const SITE_TITLE_CONTENT = 'Design System React';
103
103
 
104
104
  render(
105
105
  <SiteHeader
106
- logo={logo}
107
- siteTitle={siteTitleContent}
106
+ logo={LOGO}
107
+ siteTitle={SITE_TITLE_CONTENT}
108
108
  />
109
109
  );
110
110
 
@@ -114,13 +114,13 @@ test('site header branding: logo and site title', () => {
114
114
  const siteTitle = siteHeader.querySelector('.ds_site-branding__title');
115
115
 
116
116
  expect(siteTitle?.tagName).toEqual('DIV');
117
- expect(siteTitle?.textContent).toEqual(siteTitleContent);
117
+ expect(siteTitle?.textContent).toEqual(SITE_TITLE_CONTENT);
118
118
  expect(siteTitle?.parentElement).toEqual(siteHeaderBranding);
119
119
  expect(siteTitle?.previousElementSibling).toEqual(siteHeaderLogoLink);
120
120
  });
121
121
 
122
122
  test('site header branding: custom link URL', () => {
123
- const logo = {
123
+ const LOGO = {
124
124
  alt: 'The Scottish Government',
125
125
  href: '/home.aspx',
126
126
  src: './scottish-government.svg'
@@ -128,18 +128,18 @@ test('site header branding: custom link URL', () => {
128
128
 
129
129
  render(
130
130
  <SiteHeader
131
- logo={logo}
131
+ logo={LOGO}
132
132
  />
133
133
  );
134
134
 
135
135
  const siteHeader = screen.getByRole('banner');
136
136
  const siteHeaderLogoLink = within(siteHeader).getByRole('link');
137
137
 
138
- expect(siteHeaderLogoLink).toHaveAttribute('href', logo.href);
138
+ expect(siteHeaderLogoLink).toHaveAttribute('href', LOGO.href);
139
139
  });
140
140
 
141
141
  test('site header with site search', () => {
142
- const searchProps = {
142
+ const SEARCH_PROPS = {
143
143
  action: 'apple',
144
144
  autocompleteEndpoint: 'banana',
145
145
  autocompleteSuggestionMappingFunction: 'cucumber',
@@ -152,8 +152,8 @@ test('site header with site search', () => {
152
152
 
153
153
  render(
154
154
  <>
155
- <SiteHeader siteSearch={searchProps} />
156
- <SiteSearch data-testid="sitesearch" {...searchProps} />
155
+ <SiteHeader siteSearch={SEARCH_PROPS} />
156
+ <SiteSearch data-testid="sitesearch" {...SEARCH_PROPS} />
157
157
  </>
158
158
  );
159
159
 
@@ -165,7 +165,7 @@ test('site header with site search', () => {
165
165
  });
166
166
 
167
167
  test('site header with site navigation', () => {
168
- const navigationItems = [
168
+ const NAVIGATION_ITEMS = [
169
169
  { title: 'About', href: '#about' },
170
170
  { title: 'Get started', href: '#get-started' },
171
171
  { title: 'Styles', href: '#styles' },
@@ -176,8 +176,8 @@ test('site header with site navigation', () => {
176
176
 
177
177
  render(
178
178
  <>
179
- <SiteHeader navigationItems={navigationItems} />
180
- <SiteNavigation data-testid="sitenavigation" items={navigationItems} />
179
+ <SiteHeader navigationItems={NAVIGATION_ITEMS} />
180
+ <SiteNavigation data-testid="sitenavigation" items={NAVIGATION_ITEMS} />
181
181
  </>
182
182
  );
183
183
 
@@ -212,15 +212,15 @@ test('site header with site navigation', () => {
212
212
  });
213
213
 
214
214
  test('site header with phase banner', () => {
215
- const phaseBannerProps = {
215
+ const PHASE_BANNER_PROPS = {
216
216
  content: 'My content',
217
217
  phaseName: 'Beta'
218
218
  };
219
219
 
220
220
  render(
221
221
  <>
222
- <SiteHeader phaseBanner={phaseBannerProps} />
223
- <PhaseBanner data-testid="phasebanner" {...phaseBannerProps} />
222
+ <SiteHeader phaseBanner={PHASE_BANNER_PROPS} />
223
+ <PhaseBanner data-testid="phasebanner" {...PHASE_BANNER_PROPS} />
224
224
  </>
225
225
  );
226
226
 
@@ -2,10 +2,10 @@
2
2
 
3
3
  import { useEffect, useRef } from 'react';
4
4
 
5
- import Icon from '../../common/icon';
6
- import PhaseBanner from '../phase-banner/phase-banner';
7
- import SiteNavigation from "../site-navigation/site-navigation";
8
- import SiteSearch from "../site-search/site-search";
5
+ import Icon from '../../common/Icon';
6
+ import PhaseBanner from '../PhaseBanner/PhaseBanner';
7
+ import SiteNavigation from "../SiteNavigation/SiteNavigation";
8
+ import SiteSearch from "../SiteSearch/SiteSearch";
9
9
 
10
10
  // @ts-ignore
11
11
  import DSMobileMenu from '@scottish-government/design-system/src/components/site-navigation/site-navigation';
@@ -1,8 +1,8 @@
1
1
  import { test, expect } from 'vitest';
2
2
  import { render, screen, within } from '@testing-library/react';
3
- import SiteNavigation from './site-navigation';
3
+ import SiteNavigation from './SiteNavigation';
4
4
 
5
- const items = [
5
+ const ITEMS = [
6
6
  {title: 'About', href: '#about'},
7
7
  {title: 'Get started', href: '#get-started'},
8
8
  {title: 'Styles', href: '#styles'},
@@ -13,7 +13,7 @@ const items = [
13
13
 
14
14
  test('renders correctly', () => {
15
15
  render(
16
- <SiteNavigation items={items}/>
16
+ <SiteNavigation items={ITEMS}/>
17
17
  );
18
18
 
19
19
  const nav = screen.getByRole('navigation');
@@ -29,7 +29,7 @@ test('renders correctly', () => {
29
29
  expect(list).toHaveClass('ds_site-navigation__list');
30
30
 
31
31
  // check items
32
- expect(listItems.length).toEqual(items.length);
32
+ expect(listItems.length).toEqual(ITEMS.length);
33
33
 
34
34
  listItems.forEach((item, index) => {
35
35
  expect(item).toHaveClass('ds_site-navigation__item');
@@ -38,8 +38,8 @@ test('renders correctly', () => {
38
38
 
39
39
  expect(link).toHaveClass('ds_site-navigation__link');
40
40
  expect(link).not.toHaveClass('ds_current');
41
- expect(link.textContent).toEqual(items[index].title);
42
- expect(link).toHaveAttribute('href', items[index].href)
41
+ expect(link.textContent).toEqual(ITEMS[index].title);
42
+ expect(link).toHaveAttribute('href', ITEMS[index].href)
43
43
  });
44
44
  });
45
45
 
@@ -55,7 +55,7 @@ test('highlights current item', () => {
55
55
 
56
56
  test('passing additional props', () => {
57
57
  render(
58
- <SiteNavigation data-test="foo" items={items}/>
58
+ <SiteNavigation data-test="foo" items={ITEMS}/>
59
59
  );
60
60
 
61
61
  const nav = screen.getByRole('navigation');
@@ -64,7 +64,7 @@ test('passing additional props', () => {
64
64
 
65
65
  test('passing additional CSS classes', () => {
66
66
  render(
67
- <SiteNavigation className="foo" items={items}/>
67
+ <SiteNavigation className="foo" items={ITEMS}/>
68
68
  );
69
69
 
70
70
  const nav = screen.getByRole('navigation');