Skip to content

Commit 8aa64a2

Browse files
authored
feat: Add test-util for to check if an Option is disabled (#3933)
1 parent ee7ac59 commit 8aa64a2

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

src/__tests__/snapshot-tests/__snapshots__/documenter.test.ts.snap

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34230,6 +34230,14 @@ Note: This function returns the specified component's wrapper even if the specif
3423034230
"name": "ElementType",
3423134231
},
3423234232
},
34233+
{
34234+
"name": "isDisabled",
34235+
"parameters": [],
34236+
"returnType": {
34237+
"isNullable": false,
34238+
"name": "boolean",
34239+
},
34240+
},
3423334241
{
3423434242
"inheritedFrom": {
3423534243
"name": "AbstractWrapper.keydown",

src/select/__tests__/select.test.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,23 @@ describe.each([false, true])('expandToViewport=%s', expandToViewport => {
149149
expect(wrapper.findTrigger().getElement()).toHaveTextContent('Fifth');
150150
});
151151

152+
test('correctly identifies disabled options', () => {
153+
const { wrapper } = renderSelect({
154+
options: [
155+
...defaultOptions,
156+
{ label: 'Enabled Option', value: 'enabled' },
157+
{ label: 'Disabled Option', value: 'disabled', disabled: true },
158+
],
159+
});
160+
wrapper.openDropdown();
161+
162+
const enabledOption = wrapper.findDropdown({ expandToViewport })!.findOptionByValue('enabled')!;
163+
const disabledOption = wrapper.findDropdown({ expandToViewport })!.findOptionByValue('disabled')!;
164+
165+
expect(enabledOption.isDisabled()).toBe(false);
166+
expect(disabledOption.isDisabled()).toBe(true);
167+
});
168+
152169
describe('Filtering feature', () => {
153170
test('fires onLoadItems event after a delay', async () => {
154171
const onLoadItems = jest.fn();

src/test-utils/dom/internal/option.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
3-
import { ComponentWrapper, createWrapper, ElementWrapper } from '@cloudscape-design/test-utils-core/dom';
3+
import { ComponentWrapper, createWrapper, ElementWrapper, usesDom } from '@cloudscape-design/test-utils-core/dom';
44

55
import styles from '../../../internal/components/option/styles.selectors.js';
66
import selectPartsStyles from '../../../select/parts/styles.selectors.js';
@@ -27,4 +27,9 @@ export default class OptionWrapper extends ComponentWrapper {
2727
findDisabledReason(): ElementWrapper | null {
2828
return createWrapper().find(`.${selectPartsStyles['disabled-reason-tooltip']}`);
2929
}
30+
31+
@usesDom
32+
isDisabled(): boolean {
33+
return this.element.classList.contains(styles.disabled);
34+
}
3035
}

0 commit comments

Comments
 (0)