|
3 | 3 | import { BasePageObject } from '@cloudscape-design/browser-test-tools/page-objects'; |
4 | 4 | import useBrowser from '@cloudscape-design/browser-test-tools/use-browser'; |
5 | 5 |
|
6 | | -import createWrapper from '../../../../lib/components/test-utils/selectors'; |
7 | | - |
8 | | -import tooltipStyles from '../../../../lib/components/tooltip/styles.selectors.js'; |
9 | | - |
10 | | -test( |
11 | | - 'should not close any wrapping modals when the tooltip detects an Escape keypress', |
12 | | - useBrowser(async browser => { |
13 | | - await browser.url('/#/light/modal/with-tooltip'); |
14 | | - const page = new BasePageObject(browser); |
15 | | - |
16 | | - const openButtonSelector = createWrapper().findButton().toSelector(); |
17 | | - await page.waitForVisible(openButtonSelector); |
18 | | - await page.click(openButtonSelector); |
19 | | - |
20 | | - const modal = createWrapper().findModal(); |
21 | | - const slider = modal.findContent().findSlider(); |
22 | | - await page.waitForVisible(slider.toSelector()); |
23 | | - |
24 | | - // Slider on the page is set at 50% on purpose. `hoverElement` will move the |
25 | | - // mouse to the center of the track where the "thumb" is. |
26 | | - await page.hoverElement(slider.findNativeInput().toSelector()); |
27 | | - await page.waitForVisible(`.${tooltipStyles.root}`); |
28 | | - |
29 | | - // Press once to close the tooltip |
30 | | - await page.keys(['Escape']); |
31 | | - await expect(page.isDisplayed(`.${tooltipStyles.root}`)).resolves.toBe(false); |
32 | | - await expect(page.isDisplayed(modal.toSelector())).resolves.toBe(true); |
33 | | - |
34 | | - // Press again to close the modal |
35 | | - await page.keys(['Escape']); |
36 | | - await expect(page.isDisplayed(modal.toSelector())).resolves.toBe(false); |
37 | | - }) |
38 | | -); |
| 6 | +import tooltipStyles from '../../../lib/components/tooltip/styles.selectors.js'; |
| 7 | + |
| 8 | +class TooltipPageObject extends BasePageObject { |
| 9 | + async waitForTooltip() { |
| 10 | + console.log('Waiting for tooltip with selector:', `.${tooltipStyles.root}`); |
| 11 | + await this.waitForVisible(`.${tooltipStyles.root}`); |
| 12 | + } |
| 13 | + |
| 14 | + isTooltipVisible() { |
| 15 | + return this.isDisplayed(`.${tooltipStyles.root}`); |
| 16 | + } |
| 17 | + |
| 18 | + getTooltipContent() { |
| 19 | + return this.getText(`.${tooltipStyles.root}`); |
| 20 | + } |
| 21 | +} |
| 22 | + |
| 23 | +describe('Tooltip', () => { |
| 24 | + test( |
| 25 | + 'shows tooltip on hover, checks content and closes with escape', |
| 26 | + useBrowser(async browser => { |
| 27 | + await browser.url('/#/light/tooltip/simple'); |
| 28 | + const page = new TooltipPageObject(browser); |
| 29 | + |
| 30 | + // Wait for page to load |
| 31 | + await page.waitForVisible('[data-testid="hover-button"]'); |
| 32 | + |
| 33 | + // // Test hover |
| 34 | + await page.hoverElement('[data-testid="hover-button"]'); |
| 35 | + |
| 36 | + // await page.waitForTooltip(); |
| 37 | + await expect(page.isTooltipVisible()).resolves.toBe(true); |
| 38 | + console.log('JJAAAA'); |
| 39 | + |
| 40 | + const content = await page.getTooltipContent(); |
| 41 | + expect(content).toBe('Tooltip positioned on top'); |
| 42 | + console.log(content); |
| 43 | + |
| 44 | + await browser.keys('Escape'); |
| 45 | + await expect(page.isTooltipVisible()).resolves.toBe(false); |
| 46 | + |
| 47 | + // await expect(page.isTooltipVisible()).resolves.toBe(false); |
| 48 | + |
| 49 | + // Verify content is not accessible when tooltip is hidden |
| 50 | + // await expect(page.getTooltipContent()).resolves.toBe(''); |
| 51 | + // expect(content).toBe('Expected tooltip text'); |
| 52 | + // // Move away to hide tooltip |
| 53 | + // await page.hoverElement('body'); |
| 54 | + // await expect(page.isTooltipVisible()).resolves.toBe(false); |
| 55 | + |
| 56 | + // // Test keyboard focus |
| 57 | + // await page.click('[data-testid="hover-button"]'); |
| 58 | + // await page.waitForTooltip(); |
| 59 | + // await expect(page.isTooltipVisible()).resolves.toBe(true); |
| 60 | + }) |
| 61 | + ); |
| 62 | +}); |
0 commit comments