| 1 | import { describe, expect, it } from "vite-plus/test"; |
| 2 | |
| 3 | import { |
| 4 | HIDDEN_BROWSER_WEBVIEW_OFFSET, |
| 5 | resolveHostedBrowserWebviewWrapperStyle, |
| 6 | } from "./hostedBrowserWebviewStyle"; |
| 7 | |
| 8 | describe("resolveHostedBrowserWebviewWrapperStyle", () => { |
| 9 | it("places an active webview on its presented surface", () => { |
| 10 | expect( |
| 11 | resolveHostedBrowserWebviewWrapperStyle({ |
| 12 | active: true, |
| 13 | renderingActive: true, |
| 14 | rect: { x: 12, y: 34, width: 800, height: 600 }, |
| 15 | hiddenSize: { width: 1280, height: 800 }, |
| 16 | }), |
| 17 | ).toEqual({ |
| 18 | left: 12, |
| 19 | top: 34, |
| 20 | width: 800, |
| 21 | height: 600, |
| 22 | zIndex: 30, |
| 23 | pointerEvents: "auto", |
| 24 | }); |
| 25 | }); |
| 26 | |
| 27 | it("clips a floating webview to the mini-player frame", () => { |
| 28 | expect( |
| 29 | resolveHostedBrowserWebviewWrapperStyle({ |
| 30 | active: true, |
| 31 | renderingActive: true, |
| 32 | cornerRadius: 12, |
| 33 | zIndex: 48, |
| 34 | rect: { x: 12, y: 34, width: 360, height: 203 }, |
| 35 | hiddenSize: { width: 1280, height: 800 }, |
| 36 | }), |
| 37 | ).toMatchObject({ |
| 38 | left: 12, |
| 39 | top: 34, |
| 40 | width: 360, |
| 41 | height: 203, |
| 42 | borderRadius: 12, |
| 43 | zIndex: 48, |
| 44 | }); |
| 45 | }); |
| 46 | |
| 47 | it("suspends painting for an inactive webview", () => { |
| 48 | const style = resolveHostedBrowserWebviewWrapperStyle({ |
| 49 | active: false, |
| 50 | renderingActive: false, |
| 51 | rect: { x: 12, y: 34, width: 800, height: 600 }, |
| 52 | hiddenSize: { width: 393, height: 852 }, |
| 53 | }); |
| 54 | |
| 55 | expect(style).toEqual({ |
| 56 | left: HIDDEN_BROWSER_WEBVIEW_OFFSET, |
| 57 | top: HIDDEN_BROWSER_WEBVIEW_OFFSET, |
| 58 | width: 393, |
| 59 | height: 852, |
| 60 | zIndex: -1, |
| 61 | pointerEvents: "none", |
| 62 | visibility: "hidden", |
| 63 | }); |
| 64 | }); |
| 65 | |
| 66 | it("keeps an active background task paintable behind the app", () => { |
| 67 | const style = resolveHostedBrowserWebviewWrapperStyle({ |
| 68 | active: false, |
| 69 | renderingActive: true, |
| 70 | rect: null, |
| 71 | hiddenSize: { width: 1280, height: 800 }, |
| 72 | }); |
| 73 | |
| 74 | expect(style).toEqual({ |
| 75 | left: 0, |
| 76 | top: 0, |
| 77 | width: 1280, |
| 78 | height: 800, |
| 79 | zIndex: -1, |
| 80 | pointerEvents: "none", |
| 81 | visibility: "visible", |
| 82 | }); |
| 83 | }); |
| 84 | |
| 85 | it("keeps an inactive webview paintable without marking it as rendering-active", () => { |
| 86 | const style = resolveHostedBrowserWebviewWrapperStyle({ |
| 87 | active: false, |
| 88 | renderingActive: false, |
| 89 | keepPaintableWhenInactive: true, |
| 90 | rect: null, |
| 91 | hiddenSize: { width: 1280, height: 800 }, |
| 92 | }); |
| 93 | |
| 94 | expect(style).toEqual({ |
| 95 | left: HIDDEN_BROWSER_WEBVIEW_OFFSET, |
| 96 | top: HIDDEN_BROWSER_WEBVIEW_OFFSET, |
| 97 | width: 1280, |
| 98 | height: 800, |
| 99 | zIndex: -1, |
| 100 | pointerEvents: "none", |
| 101 | visibility: "visible", |
| 102 | }); |
| 103 | }); |
| 104 | }); |