@skyux/forms 15.0.0-alpha.1 → 15.0.0-alpha.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/fesm2022/skyux-forms-testing.mjs +115 -31
- package/fesm2022/skyux-forms-testing.mjs.map +1 -1
- package/fesm2022/skyux-forms.mjs +256 -276
- package/fesm2022/skyux-forms.mjs.map +1 -1
- package/package.json +13 -19
- package/types/skyux-forms-testing.d.ts +26 -0
- package/types/skyux-forms.d.ts +41 -52
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { HarnessPredicate, ComponentHarness } from '@angular/cdk/testing';
|
|
2
|
-
import { SkyComponentHarness, SkyQueryableComponentHarness, SkyInputHarness, provideSkyFileReaderTesting } from '@skyux/core/testing';
|
|
2
|
+
import { SkyComponentHarness, SkyQueryableComponentHarness, SkyAppTestUtility, SkyInputHarness, provideSkyFileReaderTesting } from '@skyux/core/testing';
|
|
3
3
|
import { SkyHelpInlineHarness } from '@skyux/help-inline/testing';
|
|
4
4
|
import { SkyStatusIndicatorHarness } from '@skyux/indicators/testing';
|
|
5
5
|
import { SkyPopoverHarness } from '@skyux/popovers/testing';
|
|
6
6
|
import { By } from '@angular/platform-browser';
|
|
7
|
-
import { SkyAppTestUtility } from '@skyux-sdk/testing';
|
|
8
7
|
import { SkyIconHarness } from '@skyux/icon/testing';
|
|
9
8
|
|
|
10
9
|
/**
|
|
11
10
|
* Harness for interacting with a character counter indicator component in tests.
|
|
11
|
+
*
|
|
12
|
+
* @deprecated Use `SkyInputBoxHarness` with an input box that sets the
|
|
13
|
+
* `characterLimit` input instead.
|
|
12
14
|
*/
|
|
13
15
|
class SkyCharacterCounterIndicatorHarness extends SkyComponentHarness {
|
|
14
16
|
/**
|
|
@@ -123,6 +125,75 @@ class SkyFormErrorsHarness extends SkyComponentHarness {
|
|
|
123
125
|
}
|
|
124
126
|
}
|
|
125
127
|
|
|
128
|
+
/**
|
|
129
|
+
* @internal
|
|
130
|
+
*/
|
|
131
|
+
async function getCharacterLimitRatio(labelEl) {
|
|
132
|
+
const text = (await labelEl.text()).trim();
|
|
133
|
+
const parts = text.split('/');
|
|
134
|
+
const countText = parts[0]?.trim();
|
|
135
|
+
const limitText = parts[1]?.trim();
|
|
136
|
+
const count = Number(countText);
|
|
137
|
+
const limit = Number(limitText);
|
|
138
|
+
// The label mirrors whatever `characterLimit` coerced to, which allows
|
|
139
|
+
// decimals and negatives, so don't restrict this to digits.
|
|
140
|
+
if (parts.length !== 2 ||
|
|
141
|
+
!countText ||
|
|
142
|
+
!limitText ||
|
|
143
|
+
isNaN(count) ||
|
|
144
|
+
isNaN(limit)) {
|
|
145
|
+
throw new Error(`Expected the character limit label to read "count/limit" but found "${text}".`);
|
|
146
|
+
}
|
|
147
|
+
return { count, limit };
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* @internal
|
|
151
|
+
*/
|
|
152
|
+
async function isOverCharacterLimit(labelEl) {
|
|
153
|
+
return await labelEl.hasClass('sky-error-label');
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Setting `characterLimit` on `sky-input-box` used to render a
|
|
158
|
+
* `sky-character-counter-indicator`, but now renders a
|
|
159
|
+
* `sky-input-box-character-limit`. Since `SkyInputBoxHarness.getCharacterCounter()`
|
|
160
|
+
* is public API, it must still return a `SkyCharacterCounterIndicatorHarness`,
|
|
161
|
+
* so this subclass preserves that type while reading the new markup. Delete it
|
|
162
|
+
* when the deprecated character counter component is removed.
|
|
163
|
+
*
|
|
164
|
+
* @internal
|
|
165
|
+
*/
|
|
166
|
+
class SkyInputBoxCharacterCounterIndicatorCompatHarness extends SkyCharacterCounterIndicatorHarness {
|
|
167
|
+
static { this.hostSelector = 'sky-input-box-character-limit'; }
|
|
168
|
+
#getLabel = this.locatorFor('.sky-input-box-character-limit-label');
|
|
169
|
+
async getCharacterCount() {
|
|
170
|
+
return (await getCharacterLimitRatio(await this.#getLabel())).count;
|
|
171
|
+
}
|
|
172
|
+
async getCharacterCountLimit() {
|
|
173
|
+
return (await getCharacterLimitRatio(await this.#getLabel())).limit;
|
|
174
|
+
}
|
|
175
|
+
async isOverLimit() {
|
|
176
|
+
return await isOverCharacterLimit(await this.#getLabel());
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* @internal
|
|
182
|
+
*/
|
|
183
|
+
class SkyInputBoxCharacterLimitHarness extends SkyComponentHarness {
|
|
184
|
+
static { this.hostSelector = 'sky-input-box-character-limit'; }
|
|
185
|
+
#getLabel = this.locatorFor('.sky-input-box-character-limit-label');
|
|
186
|
+
async getCharacterCount() {
|
|
187
|
+
return (await getCharacterLimitRatio(await this.#getLabel())).count;
|
|
188
|
+
}
|
|
189
|
+
async getCharacterLimit() {
|
|
190
|
+
return (await getCharacterLimitRatio(await this.#getLabel())).limit;
|
|
191
|
+
}
|
|
192
|
+
async isOverCharacterLimit() {
|
|
193
|
+
return await isOverCharacterLimit(await this.#getLabel());
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
126
197
|
/**
|
|
127
198
|
* Harness for interacting with an input box component in tests.
|
|
128
199
|
*/
|
|
@@ -131,6 +202,7 @@ class SkyInputBoxHarness extends SkyQueryableComponentHarness {
|
|
|
131
202
|
* @internal
|
|
132
203
|
*/
|
|
133
204
|
static { this.hostSelector = 'sky-input-box'; }
|
|
205
|
+
#getCharacterLimit = this.locatorForOptional(SkyInputBoxCharacterLimitHarness);
|
|
134
206
|
#getHintText = this.locatorForOptional('.sky-input-box-hint-text');
|
|
135
207
|
#getLabel = this.locatorForOptional('.sky-control-label');
|
|
136
208
|
#getWrapper = this.locatorFor('.sky-input-box');
|
|
@@ -153,16 +225,46 @@ class SkyInputBoxHarness extends SkyQueryableComponentHarness {
|
|
|
153
225
|
/**
|
|
154
226
|
* Gets the character counter indicator for the input box or throws an error if
|
|
155
227
|
* a character limit is not specified.
|
|
228
|
+
*
|
|
229
|
+
* @deprecated Use `getCharacterCount()`, `getCharacterLimit()`, and
|
|
230
|
+
* `isOverCharacterLimit()` instead. Those methods require the `characterLimit`
|
|
231
|
+
* input, so an input box that projects a `sky-character-counter-indicator` component
|
|
232
|
+
* must migrate to that input first.
|
|
156
233
|
*/
|
|
157
234
|
async getCharacterCounter() {
|
|
158
|
-
const characterCounter = await this.locatorForOptional(new HarnessPredicate(SkyCharacterCounterIndicatorHarness, {
|
|
235
|
+
const characterCounter = (await this.locatorForOptional(new HarnessPredicate(SkyCharacterCounterIndicatorHarness, {
|
|
159
236
|
ancestor: '.sky-input-box-label-wrapper',
|
|
160
|
-
}))()
|
|
237
|
+
}))()) ??
|
|
238
|
+
(await this.locatorForOptional(SkyInputBoxCharacterCounterIndicatorCompatHarness)());
|
|
161
239
|
if (!characterCounter) {
|
|
162
240
|
throw new Error('The input box does not have a character limit specified.');
|
|
163
241
|
}
|
|
164
242
|
return characterCounter;
|
|
165
243
|
}
|
|
244
|
+
/**
|
|
245
|
+
* Gets the current character count, or throws an error if the input box does
|
|
246
|
+
* not set the `characterLimit` input.
|
|
247
|
+
*/
|
|
248
|
+
async getCharacterCount() {
|
|
249
|
+
const harness = await this.#getCharacterLimitOrThrow();
|
|
250
|
+
return await harness.getCharacterCount();
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Gets the character limit, or throws an error if the input box does not set
|
|
254
|
+
* the `characterLimit` input.
|
|
255
|
+
*/
|
|
256
|
+
async getCharacterLimit() {
|
|
257
|
+
const harness = await this.#getCharacterLimitOrThrow();
|
|
258
|
+
return await harness.getCharacterLimit();
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Whether the character count has exceeded the character limit. Throws an
|
|
262
|
+
* error if the input box does not set the `characterLimit` input.
|
|
263
|
+
*/
|
|
264
|
+
async isOverCharacterLimit() {
|
|
265
|
+
const harness = await this.#getCharacterLimitOrThrow();
|
|
266
|
+
return await harness.isOverCharacterLimit();
|
|
267
|
+
}
|
|
166
268
|
/**
|
|
167
269
|
* Gets a list of status indicator harnesses for errors not automatically
|
|
168
270
|
* handled by input box.
|
|
@@ -298,6 +400,13 @@ class SkyInputBoxHarness extends SkyQueryableComponentHarness {
|
|
|
298
400
|
const host = await this.host();
|
|
299
401
|
return await host.hasClass('sky-form-field-stacked');
|
|
300
402
|
}
|
|
403
|
+
async #getCharacterLimitOrThrow() {
|
|
404
|
+
const characterLimit = await this.#getCharacterLimit();
|
|
405
|
+
if (!characterLimit) {
|
|
406
|
+
throw new Error('The input box does not have a character limit specified.');
|
|
407
|
+
}
|
|
408
|
+
return characterLimit;
|
|
409
|
+
}
|
|
301
410
|
async #getElementTextOrDefault(el) {
|
|
302
411
|
return (await el?.text())?.trim() ?? '';
|
|
303
412
|
}
|
|
@@ -1897,24 +2006,6 @@ class SkySelectionBoxGridHarness extends SkyComponentHarness {
|
|
|
1897
2006
|
}
|
|
1898
2007
|
}
|
|
1899
2008
|
|
|
1900
|
-
/**
|
|
1901
|
-
* Harness for interacting with a toggle switch label component in tests.
|
|
1902
|
-
* @internal
|
|
1903
|
-
*/
|
|
1904
|
-
class SkyToggleSwitchLabelHarness extends ComponentHarness {
|
|
1905
|
-
/**
|
|
1906
|
-
* @internal
|
|
1907
|
-
*/
|
|
1908
|
-
static { this.hostSelector = 'sky-toggle-switch-label'; }
|
|
1909
|
-
#getLabelContent = this.locatorFor('span[skyTrim]');
|
|
1910
|
-
/**
|
|
1911
|
-
* Gets the text content of the toggle switch label.
|
|
1912
|
-
*/
|
|
1913
|
-
async getText() {
|
|
1914
|
-
return await (await this.#getLabelContent()).text();
|
|
1915
|
-
}
|
|
1916
|
-
}
|
|
1917
|
-
|
|
1918
2009
|
/**
|
|
1919
2010
|
* Harness for interacting with a toggle switch component in tests.
|
|
1920
2011
|
*/
|
|
@@ -1924,7 +2015,6 @@ class SkyToggleSwitchHarness extends SkyComponentHarness {
|
|
|
1924
2015
|
*/
|
|
1925
2016
|
static { this.hostSelector = 'sky-toggle-switch'; }
|
|
1926
2017
|
#getButton = this.locatorFor('button.sky-toggle-switch-button');
|
|
1927
|
-
#getLabel = this.locatorForOptional(SkyToggleSwitchLabelHarness);
|
|
1928
2018
|
#getLabelText = this.locatorForOptional('span.sky-toggle-switch-label-text');
|
|
1929
2019
|
/**
|
|
1930
2020
|
* Gets a `HarnessPredicate` that can be used to search for a
|
|
@@ -1976,13 +2066,7 @@ class SkyToggleSwitchHarness extends SkyComponentHarness {
|
|
|
1976
2066
|
*/
|
|
1977
2067
|
async getLabelHidden() {
|
|
1978
2068
|
const labelText = await this.#getLabelText();
|
|
1979
|
-
|
|
1980
|
-
if (labelComponent) {
|
|
1981
|
-
throw new Error('`labelHidden` is only supported when setting the toggle switch label via the `labelText` input.');
|
|
1982
|
-
}
|
|
1983
|
-
else {
|
|
1984
|
-
return !(await labelText?.text());
|
|
1985
|
-
}
|
|
2069
|
+
return !(await labelText?.text());
|
|
1986
2070
|
}
|
|
1987
2071
|
/**
|
|
1988
2072
|
* Gets the toggle switch's label text. If the label is set via `labelText` and `labelHidden` is true,
|
|
@@ -1991,7 +2075,7 @@ class SkyToggleSwitchHarness extends SkyComponentHarness {
|
|
|
1991
2075
|
async getLabelText() {
|
|
1992
2076
|
const labelText = await (await this.#getLabelText())?.text();
|
|
1993
2077
|
const ariaLabel = await this.#getAriaLabel();
|
|
1994
|
-
return
|
|
2078
|
+
return labelText || ariaLabel || undefined;
|
|
1995
2079
|
}
|
|
1996
2080
|
/**
|
|
1997
2081
|
* Whether the toggle switch is checked.
|