Skip to content

Commit 21ff39a

Browse files
authored
Merge pull request #254 from CrowdStrike/add-multiselect-test-helpers
Add Multiselect test helpers
2 parents 24df01b + 532ab89 commit 21ff39a

File tree

14 files changed

+1244
-675
lines changed

14 files changed

+1244
-675
lines changed

.changeset/fluffy-meals-hammer.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@crowdstrike/ember-toucan-core': minor
3+
'@crowdstrike/ember-toucan-form': minor
4+
---
5+
6+
Add Multiselect test helpers.

docs/components/autocomplete/index.md

+10-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ If you are building forms, you may be interested in the [AutocompleteField](./au
77

88
Required.
99

10-
`@noResultsText` is shown when there are no results after filtering.
10+
`@noResultsText` is shown when there are no results after filtering.
1111

1212
```hbs
1313
<Form::Controls::Autocomplete
@@ -37,7 +37,7 @@ A CSS class to add to this component's content container. Commonly used to speci
3737

3838
Optional.
3939

40-
`@options` forms the content of this component.
40+
`@options` forms the content of this component.
4141

4242
```hbs
4343
<Form::Controls::Autocomplete
@@ -86,8 +86,8 @@ export default class extends Component {
8686

8787
Optional.
8888

89-
Called when the user makes a selection.
90-
It is called with the selected option (derived from `@options`) as its only argument.
89+
Called when the user makes a selection.
90+
It is called with the selected option (derived from `@options`) as its only argument.
9191
You'll want to update `@selected` with the new value in your on change handler.
9292

9393
```hbs
@@ -125,8 +125,8 @@ export default class extends Component {
125125

126126
Optional.
127127

128-
By default, when `@options` are an array of strings, the built-in filtering does simple `String.prototype.startsWith` filtering.
129-
There may be cases where you need to write your own filtering logic completely that is more complex than the built-in `String.prototype.startsWith` filtering described.
128+
By default, when `@options` are an array of strings, the built-in filtering does simple `String.prototype.startsWith` filtering.
129+
There may be cases where you need to write your own filtering logic completely that is more complex than the built-in `String.prototype.startsWith` filtering described.
130130
To do so, leverage `@onFilter` instead. This function should return an array of items that will then be used to populate the dropdown results.
131131

132132
```hbs
@@ -224,3 +224,7 @@ Set the `@hasError` argument to apply an error box shadow to the `<input>`.
224224
```hbs
225225
<Form::Controls::Autocomplete @hasError={{true}} />
226226
```
227+
228+
## Test Helpers
229+
230+
Test helpers for selecting common elements are available via `@crowdstrike/ember-toucan-core/test-support`.

docs/components/multiselect/index.md

+2-32
Original file line numberDiff line numberDiff line change
@@ -346,36 +346,6 @@ Set the `@hasError` argument to apply an error box shadow to the `<input>`.
346346
<Form::Controls::Multiselect @hasError={{true}} />
347347
```
348348

349-
## Test Selectors
349+
## Test Helpers
350350

351-
### Container
352-
353-
`data-multiselect-container` is provided to target the wrapping div element for the entire component.
354-
355-
```js
356-
assert.dom('[data-multiselect-container]').hasClass('bg-overlay');
357-
```
358-
359-
### Selected Chips
360-
361-
Target selected chips via `data-multiselect-selected-option`.
362-
363-
```js
364-
// Query how many selected chips there are
365-
assert.dom('[data-multiselect-selected-option]').exists({ count: 2 });
366-
```
367-
368-
### Select Chip Remove Button
369-
370-
Target a selected chip's remove button via `data-multiselect-remove-option`.
371-
372-
```js
373-
// Query how many remove buttons there are
374-
assert.dom('[data-multiselect-remove-option]').exists({ count: 3 });
375-
376-
// Click a particular remove button
377-
let removeButtons = document.querySelectorAll(
378-
'[data-multiselect-remove-option]'
379-
);
380-
await click(removeButtons[1]);
381-
```
351+
Test helpers for selecting common elements are available via `@crowdstrike/ember-toucan-core/test-support`.

packages/ember-toucan-core/src/-private/components/form/controls/multiselect/chip.gts

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const ToucanCoreMultiselectChipComponent: TemplateOnlyComponent<ToucanCoreMultis
1818
<div
1919
class="min-h-6 bg-normal-idle flex items-center gap-x-2.5 rounded-sm px-2 py-1"
2020
data-index={{@index}}
21-
data-multiselect-selected-option
21+
data-multiselect-chip
2222
...attributes
2323
>
2424
{{yield}}

packages/ember-toucan-core/src/-private/components/form/controls/multiselect/option.gts

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,12 @@ export default class ToucanCoreMultiselectControlComponent extends Component<Tou
9797
{{! template-lint-disable require-presentational-children }}
9898
{{#let (uniqueId) as |id|}}
9999
<li
100+
aria-current={{if @isActive "true" "false"}}
100101
aria-selected={{if @isSelected "true" "false"}}
101102
class="my-0 flex cursor-default items-center gap-2 px-2 py-2 leading-4
102103
{{this.styles}}
103104
{{this.className}}
104105
"
105-
data-active={{if @isActive "true" "false"}}
106106
id="{{@popoverId}}-{{@index}}"
107107
role="option"
108108
{{on "click" this.onClick}}
@@ -129,7 +129,7 @@ export default class ToucanCoreMultiselectControlComponent extends Component<Tou
129129
@isDisabled={{@isDisabled}}
130130
@isReadOnly={{@isReadOnly}}
131131
@value={{@value}}
132-
data-multiselect-option-checkbox
132+
data-multiselect-checkbox
133133
/>
134134

135135
<span class="truncate">

packages/ember-toucan-core/src/-private/components/form/controls/multiselect/select-all.gts

+2-2
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,13 @@ export default class ToucanCoreMultiselectSelectAllControlComponent extends Comp
101101
{{! template-lint-disable require-presentational-children }}
102102
{{#let (uniqueId) as |id|}}
103103
<li
104+
aria-current={{if @isActive "true" "false"}}
104105
aria-selected={{if @isSelected "true" "false"}}
105106
class="my-0 cursor-default px-2 leading-4
106107
{{this.styles}}
107108
{{this.className}}
108109
"
109-
data-active={{if @isActive "true" "false"}}
110-
data-multiselect-select-all-option
110+
data-multiselect-select-all
111111
id="{{@popoverId}}-{{@index}}"
112112
role="option"
113113
{{on "click" this.onClick}}

0 commit comments

Comments
 (0)