Skip to content

Commit 8cd6f64

Browse files
committed
fix: Add a new test utils
1 parent 7da28d7 commit 8cd6f64

File tree

1 file changed

+23
-1
lines changed

1 file changed

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

5+
import createWrapper from '../index.js';
6+
7+
import popoverStyles from '../../../popover/styles.selectors.js';
58
import styles from '../../../tooltip/styles.selectors.js';
69

710
export default class TooltipWrapper extends ComponentWrapper {
811
static rootSelector: string = styles.root;
12+
13+
/**
14+
* Returns the tooltip content element.
15+
* Searches within this tooltip's scope to avoid conflicts with popovers.
16+
*/
17+
findContent(): ElementWrapper | null {
18+
return this.findByClassName(popoverStyles.content);
19+
}
20+
21+
/**
22+
* Returns the tooltip element by its trackKey (data-testid attribute).
23+
* Useful when multiple tooltips are rendered and you need to find a specific one.
24+
*
25+
* @param trackKey - The trackKey value used when creating the tooltip
26+
*/
27+
static findByTrackKey(trackKey: string): TooltipWrapper | null {
28+
const element = createWrapper().find(`[data-testid="${trackKey}"]`);
29+
return element ? new TooltipWrapper(element.getElement()) : null;
30+
}
931
}

0 commit comments

Comments
 (0)