|
10 | 10 | // ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃ |
11 | 11 | // ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ |
12 | 12 |
|
13 | | -use wasm_bindgen::JsCast; |
14 | | -use web_sys::{Document, HtmlElement}; |
| 13 | +import { test, expect } from "@finos/perspective-test"; |
15 | 14 |
|
16 | | -/// Blur the current active elemnt, triggering any blur handlers in the |
17 | | -/// application (e.g. modals). This is often necessary when a DOM update will |
18 | | -/// invalidate something that has a `"blur"` event handler. |
19 | | -#[extend::ext] |
20 | | -pub impl Document { |
21 | | - fn blur_active_element(&self) { |
22 | | - self.active_element() |
23 | | - .unwrap() |
24 | | - .unchecked_into::<HtmlElement>() |
25 | | - .blur() |
26 | | - .unwrap(); |
27 | | - } |
28 | | -} |
| 15 | +test.describe("browser focus", async () => { |
| 16 | + test.beforeEach(async function init({ page }) { |
| 17 | + await page.goto( |
| 18 | + "/node_modules/@finos/perspective-viewer/test/html/superstore_with_input.html" |
| 19 | + ); |
| 20 | + |
| 21 | + await page.evaluate(async () => { |
| 22 | + while (!window["__TEST_PERSPECTIVE_READY__"]) { |
| 23 | + await new Promise((x) => setTimeout(x, 10)); |
| 24 | + } |
| 25 | + }); |
| 26 | + |
| 27 | + await page.evaluate(async () => { |
| 28 | + await document.querySelector("perspective-viewer").restore({ |
| 29 | + plugin: "Debug", |
| 30 | + }); |
| 31 | + }); |
| 32 | + }); |
| 33 | + |
| 34 | + test("Focus is not lost on external widgets when a restore call takes place", async ({ |
| 35 | + page, |
| 36 | + }) => { |
| 37 | + const viewer = page.locator("perspective-viewer"); |
| 38 | + const tagName = await viewer.evaluate(async (viewer) => { |
| 39 | + const input = document.querySelector("input"); |
| 40 | + input.focus(); |
| 41 | + await viewer.restore({ group_by: ["State"] }); |
| 42 | + return document.activeElement.tagName; |
| 43 | + }); |
| 44 | + |
| 45 | + expect(tagName).toEqual("INPUT"); |
| 46 | + }); |
| 47 | +}); |
0 commit comments