@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,31 +1,31 @@
1
1
  import { test, expect, vi } from 'vitest';
2
2
  import { render, screen, within, fireEvent } from '@testing-library/react';
3
- import TextInput from './text-input';
3
+ import TextInput from './TextInput';
4
4
 
5
- const id = 'text-input';
6
- const labelText = 'First name';
5
+ const INPUT_ID = 'text-input';
6
+ const LABEL_TEXT = 'First name';
7
7
 
8
8
  test('text input renders correctly', () => {
9
9
  render(
10
10
  <TextInput
11
- id={id}
12
- label={labelText}
11
+ id={INPUT_ID}
12
+ label={LABEL_TEXT}
13
13
  />
14
14
  );
15
15
 
16
16
  const textInput = screen.getByRole('textbox');
17
- const label = screen.getByText(labelText);
17
+ const label = screen.getByText(LABEL_TEXT);
18
18
 
19
19
  expect(textInput).toHaveClass('ds_input');
20
- expect(textInput).toHaveAttribute('id', id);
21
- expect(textInput).toHaveAttribute('name', id);
20
+ expect(textInput).toHaveAttribute('id', INPUT_ID);
21
+ expect(textInput).toHaveAttribute('name', INPUT_ID);
22
22
  expect(textInput).toHaveAttribute('type', 'text');
23
23
  expect(textInput.tagName).toEqual('INPUT');
24
24
 
25
25
  expect(label).toHaveClass('ds_label');
26
- expect(label).toHaveAttribute('for', id);
26
+ expect(label).toHaveAttribute('for', INPUT_ID);
27
27
  expect(label.tagName).toEqual('LABEL');
28
- expect(label.textContent).toEqual(labelText);
28
+ expect(label.textContent).toEqual(LABEL_TEXT);
29
29
 
30
30
  expect(textInput.previousSibling).toEqual(label);
31
31
  });
@@ -33,8 +33,8 @@ test('text input renders correctly', () => {
33
33
  test('text input with custom class(es)', () => {
34
34
  render(
35
35
  <TextInput
36
- id={id}
37
- label={labelText}
36
+ id={INPUT_ID}
37
+ label={LABEL_TEXT}
38
38
  className="foo bar"
39
39
  />
40
40
  );
@@ -45,62 +45,62 @@ test('text input with custom class(es)', () => {
45
45
  });
46
46
 
47
47
  test('text input with character count', () => {
48
- const maxLength = 100;
48
+ const MAX_LENGTH = 100;
49
49
 
50
50
  render(
51
51
  <TextInput
52
- id={id}
53
- label={labelText}
54
- maxlength={maxLength}
52
+ id={INPUT_ID}
53
+ label={LABEL_TEXT}
54
+ maxlength={MAX_LENGTH}
55
55
  />
56
56
  );
57
57
 
58
58
  const textInput = screen.getByRole('textbox');
59
59
  const textInputWrapper = textInput.parentElement;
60
60
 
61
- expect(textInputWrapper).toHaveAttribute('data-maxlength', maxLength.toString());
61
+ expect(textInputWrapper).toHaveAttribute('data-maxlength', MAX_LENGTH.toString());
62
62
  expect(textInputWrapper).toHaveAttribute('data-module', 'ds-character-count');
63
63
  });
64
64
 
65
65
  test('text input with character count and threshold', () => {
66
- const maxLength = 100;
67
- const countThreshold = 80;
66
+ const MAX_LENGTH = 100;
67
+ const COUNT_THRESHOLD = 80;
68
68
 
69
69
  render(
70
70
  <TextInput
71
- id={id}
72
- label={labelText}
73
- maxlength={maxLength}
74
- countThreshold={countThreshold}
71
+ id={INPUT_ID}
72
+ label={LABEL_TEXT}
73
+ maxlength={MAX_LENGTH}
74
+ countThreshold={COUNT_THRESHOLD}
75
75
  />
76
76
  );
77
77
 
78
78
  const textInput = screen.getByRole('textbox');
79
79
  const textInputWrapper = textInput.parentElement;
80
80
 
81
- expect(textInputWrapper).toHaveAttribute('data-threshold', countThreshold.toString());
81
+ expect(textInputWrapper).toHaveAttribute('data-threshold', COUNT_THRESHOLD.toString());
82
82
  });
83
83
 
84
84
  test('text input with width', () => {
85
- const width = 'fixed-10';
85
+ const INPUT_WIDTH = 'fixed-10';
86
86
 
87
87
  render(
88
88
  <TextInput
89
- id={id}
90
- label={labelText}
91
- width={width}
89
+ id={INPUT_ID}
90
+ label={LABEL_TEXT}
91
+ width={INPUT_WIDTH}
92
92
  />
93
93
  );
94
94
 
95
95
  const textInput = screen.getByRole('textbox');
96
- expect(textInput).toHaveClass(`ds_input--${width}`);
96
+ expect(textInput).toHaveClass(`ds_input--${INPUT_WIDTH}`);
97
97
  });
98
98
 
99
99
  test('text input with currency', () => {
100
100
  render(
101
101
  <TextInput
102
- id={id}
103
- label={labelText}
102
+ id={INPUT_ID}
103
+ label={LABEL_TEXT}
104
104
  currency
105
105
  />
106
106
  );
@@ -114,32 +114,33 @@ test('text input with currency', () => {
114
114
  });
115
115
 
116
116
  test('text input with custom currency symbol', () => {
117
- const symbol = '@';
117
+ const CURRENCY_SYMBOL = '@';
118
118
 
119
119
  render(
120
120
  <TextInput
121
- id={id}
122
- label={labelText}
121
+ id={INPUT_ID}
122
+ label={LABEL_TEXT}
123
123
  currency
124
- currencySymbol={symbol}
124
+ currencySymbol={CURRENCY_SYMBOL}
125
125
  />
126
126
  );
127
127
 
128
128
  const textInput = screen.getByRole('textbox');
129
129
  const textInputWrapper = textInput.parentElement;
130
130
 
131
- expect(textInputWrapper).toHaveAttribute('data-symbol', symbol);
131
+ expect(textInputWrapper).toHaveAttribute('data-symbol', CURRENCY_SYMBOL);
132
132
  });
133
133
 
134
134
  test('text input with button', () => {
135
- const buttonText = 'Search';
136
- const buttonIcon = 'Search';
135
+ const BUTTON_TEXT = 'Search';
136
+ const BUTTON_ICON = 'Search';
137
+
137
138
  render(
138
139
  <TextInput
139
- id={id}
140
- label={labelText}
141
- buttonIcon={buttonIcon}
142
- buttonText={buttonText}
140
+ id={INPUT_ID}
141
+ label={LABEL_TEXT}
142
+ buttonIcon={BUTTON_ICON}
143
+ buttonText={BUTTON_TEXT}
143
144
  hasButton
144
145
  />
145
146
  );
@@ -147,7 +148,7 @@ test('text input with button', () => {
147
148
  const textInput = screen.getByRole('textbox');
148
149
  const textInputWrapper = textInput.parentElement;
149
150
  const button = screen.getByRole('button');
150
- const buttonTextElement = within(button).getByText(buttonText);
151
+ const buttonTextElement = within(button).getByText(BUTTON_TEXT);
151
152
  const buttonIconElement = within(button).getByRole('img', { hidden: true });
152
153
 
153
154
  expect(textInputWrapper).toHaveClass('ds_input__wrapper', 'ds_input__wrapper--has-icon ');
@@ -163,16 +164,17 @@ test('text input with button', () => {
163
164
  });
164
165
 
165
166
  test('text input with hint text', () => {
166
- const hintText = 'hint text';
167
+ const HINT_TEXT = 'hint text';
168
+
167
169
  render(
168
170
  <TextInput
169
- id={id}
170
- label={labelText}
171
- hintText={hintText}
171
+ id={INPUT_ID}
172
+ label={LABEL_TEXT}
173
+ hintText={HINT_TEXT}
172
174
  />
173
175
  );
174
176
 
175
- const hintTextEl = screen.getByText(hintText);
177
+ const hintTextEl = screen.getByText(HINT_TEXT);
176
178
  const textInput = screen.getByRole('textbox');
177
179
 
178
180
  expect(hintTextEl).toBeInTheDocument();
@@ -180,27 +182,28 @@ test('text input with hint text', () => {
180
182
  });
181
183
 
182
184
  test('text input with custom name', () => {
183
- const name = 'foo';
185
+ const INPUT_NAME = 'foo';
184
186
 
185
187
  render(
186
188
  <TextInput
187
- id={id}
188
- label={labelText}
189
- name={name}
189
+ id={INPUT_ID}
190
+ label={LABEL_TEXT}
191
+ name={INPUT_NAME}
190
192
  />
191
193
  );
192
194
 
193
195
  const textInput = screen.getByRole('textbox');
194
- expect(textInput).toHaveAttribute('name', name);
196
+ expect(textInput).toHaveAttribute('name', INPUT_NAME);
195
197
  });
196
198
 
197
199
  test('text input with blur function', () => {
198
- const onBlurFn = vi.fn();
200
+ const ONBLUR_FUNCTION = vi.fn();
201
+
199
202
  render(
200
203
  <TextInput
201
- id={id}
202
- label={labelText}
203
- onBlur={onBlurFn}
204
+ id={INPUT_ID}
205
+ label={LABEL_TEXT}
206
+ onBlur={ONBLUR_FUNCTION}
204
207
  />
205
208
  );
206
209
 
@@ -208,16 +211,17 @@ test('text input with blur function', () => {
208
211
 
209
212
  fireEvent.blur(textInput);
210
213
 
211
- expect(onBlurFn).toHaveBeenCalled();
214
+ expect(ONBLUR_FUNCTION).toHaveBeenCalled();
212
215
  });
213
216
 
214
217
  test('text input with change function', () => {
215
- const onChangeFn = vi.fn();
218
+ const ONCHANGE_FUNCTION = vi.fn();
219
+
216
220
  render(
217
221
  <TextInput
218
- id={id}
219
- label={labelText}
220
- onChange={onChangeFn}
222
+ id={INPUT_ID}
223
+ label={LABEL_TEXT}
224
+ onChange={ONCHANGE_FUNCTION}
221
225
  />
222
226
  );
223
227
 
@@ -225,67 +229,68 @@ test('text input with change function', () => {
225
229
 
226
230
  fireEvent.change(textInput, {target: {value: 'foo'}});
227
231
 
228
- expect(onChangeFn).toHaveBeenCalled();
232
+ expect(ONCHANGE_FUNCTION).toHaveBeenCalled();
229
233
  });
230
234
 
231
235
  test('text input with placeholder text', () => {
232
- const placeholder = 'foo';
236
+ const PLACEHOLDER_TEXT = 'foo';
233
237
 
234
238
  render(
235
239
  <TextInput
236
- id={id}
237
- label={labelText}
238
- placeholder={placeholder}
240
+ id={INPUT_ID}
241
+ label={LABEL_TEXT}
242
+ placeholder={PLACEHOLDER_TEXT}
239
243
  />
240
244
  );
241
245
 
242
246
  const textInput = screen.getByRole('textbox');
243
- expect(textInput).toHaveAttribute('placeholder', placeholder);
247
+ expect(textInput).toHaveAttribute('placeholder', PLACEHOLDER_TEXT);
244
248
  });
245
249
 
246
250
  test('text input with different type', () => {
247
- const type = 'foo';
251
+ const INPUT_TYPE = 'foo';
248
252
 
249
253
  render(
250
254
  <TextInput
251
- id={id}
252
- label={labelText}
253
- type={type}
255
+ id={INPUT_ID}
256
+ label={LABEL_TEXT}
257
+ type={INPUT_TYPE}
254
258
  />
255
259
  );
256
260
 
257
261
  const textInput = screen.getByRole('textbox');
258
- expect(textInput).toHaveAttribute('type', type);
262
+ expect(textInput).toHaveAttribute('type', INPUT_TYPE);
259
263
  });
260
264
 
261
265
  test('text input with initial value', () => {
262
- const initialValue = 'initial value';
266
+ const INITIAL_VALUE = 'initial value';
263
267
 
264
268
  render(
265
269
  <TextInput
266
- id={id}
267
- label={labelText}
268
- value={initialValue}
270
+ id={INPUT_ID}
271
+ label={LABEL_TEXT}
272
+ value={INITIAL_VALUE}
269
273
  />
270
274
  );
271
275
 
272
276
  const textInput = screen.getByRole('textbox');
273
- expect(textInput).toHaveAttribute('value', initialValue);
277
+ expect(textInput).toHaveAttribute('value', INITIAL_VALUE);
274
278
  });
275
279
 
276
280
  test('text input with error message', () => {
277
- const errorMessage = 'This is a required field';
281
+ const ERROR_MESSAGE_TEXT = 'This is a required field';
282
+
278
283
  render(
279
284
  <TextInput
280
- id={id}
281
- label={labelText}
285
+ id={INPUT_ID}
286
+ label={LABEL_TEXT}
282
287
  error
283
- errorMessage={errorMessage}
288
+ errorMessage={ERROR_MESSAGE_TEXT}
284
289
  />
285
290
  );
286
291
 
287
292
  const textInput = screen.getByRole('textbox');
288
- const errorMessageElement = screen.getByText(errorMessage);
293
+ const errorMessageElement = screen.getByText(ERROR_MESSAGE_TEXT);
289
294
 
290
295
  expect(textInput).toHaveClass('ds_input--error')
291
296
  expect(textInput).toHaveAttribute('aria-describedby', errorMessageElement.id);
@@ -297,8 +302,8 @@ test('text input with error message', () => {
297
302
  test('passing additional props', () => {
298
303
  render(
299
304
  <TextInput
300
- id={id}
301
- label={labelText}
305
+ id={INPUT_ID}
306
+ label={LABEL_TEXT}
302
307
  data-test="foo"
303
308
  />
304
309
  );
@@ -310,8 +315,8 @@ test('passing additional props', () => {
310
315
  test('passing additional CSS classes', () => {
311
316
  render(
312
317
  <TextInput
313
- id={id}
314
- label={labelText}
318
+ id={INPUT_ID}
319
+ label={LABEL_TEXT}
315
320
  className="foo"
316
321
  />
317
322
  );
@@ -1,10 +1,10 @@
1
1
  import { useEffect, useRef } from 'react';
2
2
  // @ts-ignore
3
3
  import DSCharacterCount from '@scottish-government/design-system/src/forms/character-count/character-count';
4
- import Button from '../button/button';
5
- import ConditionalWrapper from '../../common/conditional-wrapper';
6
- import ErrorMessage from '../error-message/error-message';
7
- import HintText from '../../common/hint-text';
4
+ import Button from '../Button/Button';
5
+ import ConditionalWrapper from '../../common/ConditionalWrapper';
6
+ import ErrorMessage from '../ErrorMessage/ErrorMessage';
7
+ import HintText from '../../common/HintText';
8
8
 
9
9
  const TextInput: React.FC<SGDS.Component.TextInput> = ({
10
10
  buttonIcon,
@@ -1,82 +1,83 @@
1
1
  import { test, expect, vi } from 'vitest';
2
- import { render, screen, within, fireEvent } from '@testing-library/react';
3
- import Textarea from './textarea';
2
+ import { render, screen, fireEvent } from '@testing-library/react';
3
+ import Textarea from './Textarea';
4
4
 
5
- const id = 'textarea';
6
- const labelText = 'Description';
5
+ const TEXTAREA_ID = 'textarea';
6
+ const LABEL_TEXT = 'Description';
7
7
 
8
8
  test('text input renders correctly', () => {
9
9
  render(
10
10
  <Textarea
11
- id={id}
12
- label={labelText}
11
+ id={TEXTAREA_ID}
12
+ label={LABEL_TEXT}
13
13
  />
14
14
  );
15
15
 
16
16
  const textarea = screen.getByRole('textbox');
17
- const label = screen.getByText(labelText);
17
+ const label = screen.getByText(LABEL_TEXT);
18
18
 
19
19
  expect(textarea).toHaveClass('ds_input');
20
- expect(textarea).toHaveAttribute('id', id);
21
- expect(textarea).toHaveAttribute('name', id);
20
+ expect(textarea).toHaveAttribute('id', TEXTAREA_ID);
21
+ expect(textarea).toHaveAttribute('name', TEXTAREA_ID);
22
22
  expect(textarea).toHaveAttribute('rows', String(4));
23
23
 
24
24
  expect(label).toHaveClass('ds_label');
25
- expect(label).toHaveAttribute('for', id);
25
+ expect(label).toHaveAttribute('for', TEXTAREA_ID);
26
26
  expect(label.tagName).toEqual('LABEL');
27
- expect(label.textContent).toEqual(labelText);
27
+ expect(label.textContent).toEqual(LABEL_TEXT);
28
28
 
29
29
  expect(textarea.previousSibling).toEqual(label);
30
30
  });
31
31
 
32
32
  test('textarea with character count', () => {
33
- const maxLength = 250;
33
+ const MAX_LENGTH = 250;
34
34
 
35
35
  render(
36
36
  <Textarea
37
- id={id}
38
- label={labelText}
39
- maxlength={maxLength}
37
+ id={TEXTAREA_ID}
38
+ label={LABEL_TEXT}
39
+ maxlength={MAX_LENGTH}
40
40
  />
41
41
  );
42
42
 
43
43
  const textarea = screen.getByRole('textbox');
44
44
  const textareaWrapper = textarea.parentElement;
45
45
 
46
- expect(textareaWrapper).toHaveAttribute('data-maxlength', maxLength.toString());
46
+ expect(textareaWrapper).toHaveAttribute('data-maxlength', MAX_LENGTH.toString());
47
47
  expect(textareaWrapper).toHaveAttribute('data-module', 'ds-character-count');
48
48
  });
49
49
 
50
50
  test('text input with character count and threshold', () => {
51
- const maxLength = 250;
52
- const countThreshold = 80;
51
+ const MAX_LENGTH = 250;
52
+ const COUNT_THRESHOLD = 80;
53
53
 
54
54
  render(
55
55
  <Textarea
56
- id={id}
57
- label={labelText}
58
- maxlength={maxLength}
59
- countThreshold={countThreshold}
56
+ id={TEXTAREA_ID}
57
+ label={LABEL_TEXT}
58
+ maxlength={MAX_LENGTH}
59
+ countThreshold={COUNT_THRESHOLD}
60
60
  />
61
61
  );
62
62
 
63
63
  const textarea = screen.getByRole('textbox');
64
64
  const textareaWrapper = textarea.parentElement;
65
65
 
66
- expect(textareaWrapper).toHaveAttribute('data-threshold', countThreshold.toString());
66
+ expect(textareaWrapper).toHaveAttribute('data-threshold', COUNT_THRESHOLD.toString());
67
67
  });
68
68
 
69
69
  test('textarea with hint text', () => {
70
- const hintText = 'hint text';
70
+ const HINT_TEXT = 'hint text';
71
+
71
72
  render(
72
73
  <Textarea
73
- id={id}
74
- label={labelText}
75
- hintText={hintText}
74
+ id={TEXTAREA_ID}
75
+ label={LABEL_TEXT}
76
+ hintText={HINT_TEXT}
76
77
  />
77
78
  );
78
79
 
79
- const hintTextEl = screen.getByText(hintText);
80
+ const hintTextEl = screen.getByText(HINT_TEXT);
80
81
  const textarea = screen.getByRole('textbox');
81
82
 
82
83
  expect(hintTextEl).toBeInTheDocument();
@@ -84,27 +85,28 @@ test('textarea with hint text', () => {
84
85
  });
85
86
 
86
87
  test('textarea with custom name', () => {
87
- const name = 'foo';
88
+ const TEXTAREA_NAME = 'foo';
88
89
 
89
90
  render(
90
91
  <Textarea
91
- id={id}
92
- label={labelText}
93
- name={name}
92
+ id={TEXTAREA_ID}
93
+ label={LABEL_TEXT}
94
+ name={TEXTAREA_NAME}
94
95
  />
95
96
  );
96
97
 
97
98
  const textarea = screen.getByRole('textbox');
98
- expect(textarea).toHaveAttribute('name', name);
99
+ expect(textarea).toHaveAttribute('name', TEXTAREA_NAME);
99
100
  });
100
101
 
101
102
  test('textarea with blur function', () => {
102
- const onBlurFn = vi.fn();
103
+ const ONBLUR_FUNCTION = vi.fn();
104
+
103
105
  render(
104
106
  <Textarea
105
- id={id}
106
- label={labelText}
107
- onBlur={onBlurFn}
107
+ id={TEXTAREA_ID}
108
+ label={LABEL_TEXT}
109
+ onBlur={ONBLUR_FUNCTION}
108
110
  />
109
111
  );
110
112
 
@@ -112,16 +114,17 @@ test('textarea with blur function', () => {
112
114
 
113
115
  fireEvent.blur(textarea);
114
116
 
115
- expect(onBlurFn).toHaveBeenCalled();
117
+ expect(ONBLUR_FUNCTION).toHaveBeenCalled();
116
118
  });
117
119
 
118
120
  test('textarea with change function', () => {
119
- const onChangeFn = vi.fn();
121
+ const ONCHANGE_FUNCTION = vi.fn();
122
+
120
123
  render(
121
124
  <Textarea
122
- id={id}
123
- label={labelText}
124
- onChange={onChangeFn}
125
+ id={TEXTAREA_ID}
126
+ label={LABEL_TEXT}
127
+ onChange={ONCHANGE_FUNCTION}
125
128
  />
126
129
  );
127
130
 
@@ -129,68 +132,69 @@ test('textarea with change function', () => {
129
132
 
130
133
  fireEvent.change(textarea, {target: {value: 'foo'}});
131
134
 
132
- expect(onChangeFn).toHaveBeenCalled();
135
+ expect(ONCHANGE_FUNCTION).toHaveBeenCalled();
133
136
  });
134
137
 
135
138
  test('textarea with placeholder text', () => {
136
- const placeholder = 'foo';
139
+ const PLACEHOLDER_TEXT = 'foo';
137
140
 
138
141
  render(
139
142
  <Textarea
140
- id={id}
141
- label={labelText}
142
- placeholder={placeholder}
143
+ id={TEXTAREA_ID}
144
+ label={LABEL_TEXT}
145
+ placeholder={PLACEHOLDER_TEXT}
143
146
  />
144
147
  );
145
148
 
146
149
  const textarea = screen.getByRole('textbox');
147
- expect(textarea).toHaveAttribute('placeholder', placeholder);
150
+ expect(textarea).toHaveAttribute('placeholder', PLACEHOLDER_TEXT);
148
151
  });
149
152
 
150
153
  test('textarea with custom rows', () => {
151
- const rows = 2;
154
+ const ROWS = 2;
152
155
 
153
156
  render(
154
157
  <Textarea
155
- id={id}
156
- label={labelText}
157
- rows={rows}
158
+ id={TEXTAREA_ID}
159
+ label={LABEL_TEXT}
160
+ rows={ROWS}
158
161
  />
159
162
  );
160
163
 
161
164
  const textarea = screen.getByRole('textbox');
162
165
 
163
- expect(textarea).toHaveAttribute('rows', String(rows));
166
+ expect(textarea).toHaveAttribute('rows', String(ROWS));
164
167
  });
165
168
 
166
169
  test('textarea with initial value', () => {
167
- const content = 'Mygov.scot gives people and businesses information about and access to public services in Scotland. We work closely with public sector organisations to make public services easy to find and understand.';
170
+ const TEXTAREA_CONTENT = 'Mygov.scot gives people and businesses information about and access to public services in Scotland. We work closely with public sector organisations to make public services easy to find and understand.';
168
171
 
169
172
  render(
170
173
  <Textarea
171
- defaultValue={content}
172
- id={id}
173
- label={labelText}
174
+ defaultValue={TEXTAREA_CONTENT}
175
+ id={TEXTAREA_ID}
176
+ label={LABEL_TEXT}
174
177
  />
175
178
  );
176
179
 
177
180
  const textarea = screen.getByRole('textbox');
178
- expect(textarea.textContent).toEqual(content);
181
+ expect(textarea.textContent).toEqual(TEXTAREA_CONTENT);
179
182
  });
180
183
 
181
184
  test('textarea with error message', () => {
182
- const errorMessage = 'This is a required field';
185
+ const ERROR_MESSAGE_TEXT = 'This is a required field';
186
+
183
187
  render(
184
188
  <Textarea
185
- id={id}
186
- label={labelText}
189
+ id={TEXTAREA_ID}
190
+ label={LABEL_TEXT}
187
191
  error
188
- errorMessage={errorMessage}
192
+ errorMessage={ERROR_MESSAGE_TEXT}
189
193
  />
190
194
  );
191
195
 
192
196
  const textarea = screen.getByRole('textbox');
193
- const errorMessageElement = screen.getByText(errorMessage);
197
+ const errorMessageElement = screen.getByText(ERROR_MESSAGE_TEXT);
194
198
 
195
199
  expect(textarea).toHaveClass('ds_input--error')
196
200
  expect(textarea).toHaveAttribute('aria-describedby', errorMessageElement.id);
@@ -202,8 +206,8 @@ test('textarea with error message', () => {
202
206
  test('passing additional props', () => {
203
207
  render(
204
208
  <Textarea
205
- id={id}
206
- label={labelText}
209
+ id={TEXTAREA_ID}
210
+ label={LABEL_TEXT}
207
211
  data-test="foo"
208
212
  />
209
213
  );
@@ -215,8 +219,8 @@ test('passing additional props', () => {
215
219
  test('passing additional CSS classes', () => {
216
220
  render(
217
221
  <Textarea
218
- id={id}
219
- label={labelText}
222
+ id={TEXTAREA_ID}
223
+ label={LABEL_TEXT}
220
224
  className="foo"
221
225
  />
222
226
  );