Skip to content

Commit 627449b

Browse files
revert: "fix: Ensure toggle button test utils only find toggle buttons (#3868)" (#3938)
1 parent 8aa64a2 commit 627449b

File tree

15 files changed

+25
-109
lines changed

15 files changed

+25
-109
lines changed

pages/button/legacy-button.page.tsx

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/__tests__/snapshot-tests/__snapshots__/test-utils-selectors.test.tsx.snap

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@ exports[`test-utils selectors 1`] = `
8484
"awsui_item_d19fg",
8585
],
8686
"button": [
87+
"awsui_button_vjswe",
8788
"awsui_content_vjswe",
8889
"awsui_disabled-reason-tooltip_1ueyk",
8990
"awsui_icon-left_vjswe",
90-
"awsui_root_1ueyk",
9191
],
9292
"button-dropdown": [
9393
"awsui_button-dropdown_sne0l",
@@ -652,9 +652,6 @@ exports[`test-utils selectors 1`] = `
652652
"toggle": [
653653
"awsui_root_4yi2u",
654654
],
655-
"toggle-button": [
656-
"awsui_root_1qd09",
657-
],
658655
"token": [
659656
"awsui_dismiss-button_1epxo",
660657
"awsui_root_1epxo",

src/button/__integ__/button.test.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,3 @@ describe('Button Style API', () => {
6969
})
7070
);
7171
});
72-
73-
describe('legacy selectors', () => {
74-
test(
75-
'finds legacy and new buttons',
76-
useBrowser(async browser => {
77-
await browser.url('#/light/button/legacy-button');
78-
const page = new ButtonPageObject(browser);
79-
await expect(page.getText(wrapper.findButton().toSelector())).resolves.toBe('Legacy button');
80-
await expect(browser.$$(wrapper.findAllButtons().toSelector())).resolves.toHaveLength(3);
81-
})
82-
);
83-
});

src/button/__tests__/button.test.tsx

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -926,15 +926,4 @@ describe('Style API', () => {
926926
'0 0 8px green'
927927
);
928928
});
929-
930-
test('finds legacy buttons', () => {
931-
const renderResult = render(
932-
<div>
933-
<Button>Button</Button>
934-
<button className="awsui_button_vjswe_t8nlg_157">Legacy button</button>
935-
</div>
936-
);
937-
const wrapper = createWrapper(renderResult.container);
938-
expect(wrapper.findAllButtons()).toHaveLength(2);
939-
});
940929
});

src/button/__tests__/native-attributes.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ describe('Button native attributes', () => {
7575
const wrapper = createWrapper(container).findButton()!;
7676

7777
expect(wrapper.getElement()).toHaveClass('my-additional-class');
78-
expect(wrapper.getElement()).toHaveClass(styles.root);
78+
expect(wrapper.getElement()).toHaveClass(styles.button);
7979
});
8080

8181
test('events get chained', () => {

src/button/internal.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ export type InternalButtonProps = Omit<ButtonProps, 'variant'> & {
5656
__title?: string;
5757
__emitPerformanceMarks?: boolean;
5858
__skipNativeAttributesWarnings?: boolean;
59-
__hideFromTestUtils?: boolean;
6059
} & InternalBaseComponentProps;
6160

6261
export const InternalButton = React.forwardRef(
@@ -99,7 +98,6 @@ export const InternalButton = React.forwardRef(
9998
__title,
10099
__emitPerformanceMarks = true,
101100
__skipNativeAttributesWarnings,
102-
__hideFromTestUtils = false,
103101
analyticsAction = 'click',
104102
...props
105103
}: InternalButtonProps,
@@ -180,8 +178,7 @@ export const InternalButton = React.forwardRef(
180178
buttonContext.onClick({ variant });
181179
};
182180

183-
const buttonClass = clsx(props.className, styles.root, styles[`variant-${variant}`], {
184-
[testUtilStyles.root]: !__hideFromTestUtils,
181+
const buttonClass = clsx(props.className, styles.button, styles[`variant-${variant}`], {
185182
[styles.disabled]: isNotInteractive,
186183
[styles['disabled-with-reason']]: isDisabledWithReason,
187184
[styles['button-no-wrap']]: !wrapText,

src/button/styles.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
/* used in test-utils */
5454
}
5555

56-
.root {
56+
.button {
5757
@include styles.styles-reset;
5858
@include styles.text-wrapping;
5959
@include styles.font-button;

src/button/test-classes/styles.scss

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
.disabled-reason-tooltip,
7-
.external-icon,
8-
.root {
6+
.disabled-reason-tooltip {
7+
/* used in test-utils or tests */
8+
}
9+
10+
.external-icon {
911
/* used in test-utils or tests */
1012
}

src/table/internal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ const InternalTable = React.forwardRef(
201201
?.innerText ?? toolsHeaderPerformanceMarkRef.current?.innerText;
202202
const getPatternIdentifier = () => {
203203
const hasActions = !!toolsHeaderPerformanceMarkRef.current?.querySelector<HTMLElement>(
204-
`.${headerStyles.actions} .${buttonStyles.root}`
204+
`.${headerStyles.actions} .${buttonStyles.button}`
205205
);
206206

207207
if (hasActions) {

src/test-utils/dom/button-dropdown/index.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { act } from '@cloudscape-design/test-utils-core/utils-dom';
55

66
import ButtonWrapper from '../button/index.js';
77

8+
import buttonStyles from '../../../button/styles.selectors.js';
89
import categoryStyles from '../../../button-dropdown/category-elements/styles.selectors.js';
910
import itemStyles from '../../../button-dropdown/item-element/styles.selectors.js';
1011
import styles from '../../../button-dropdown/styles.selectors.js';
@@ -20,11 +21,15 @@ export default class ButtonDropdownWrapper extends ComponentWrapper {
2021
}
2122

2223
findTriggerButton(): ButtonWrapper | null {
23-
return this.findByClassName(styles['dropdown-trigger'])?.findButton() ?? null;
24+
return (
25+
this.findByClassName(styles['dropdown-trigger'])?.findComponent(`.${buttonStyles.button}`, ButtonWrapper) ?? null
26+
);
2427
}
2528

2629
findMainAction(): null | ButtonWrapper {
27-
return this.findByClassName(styles['split-trigger'])?.findButton() ?? null;
30+
return (
31+
this.findByClassName(styles['split-trigger'])?.findComponent(`.${buttonStyles.button}`, ButtonWrapper) ?? null
32+
);
2833
}
2934

3035
findOpenDropdown(): ElementWrapper | null {

0 commit comments

Comments
 (0)