@operato/popup 10.29.23 → 10.29.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,42 @@
1
+ import { expect } from '@open-wc/testing'
2
+ import { html } from 'lit'
3
+
4
+ import { openPopup } from '../src/open-popup.js'
5
+ import { OxFloatingOverlay } from '../src/ox-floating-overlay.js'
6
+
7
+ /*
8
+ * A popup of size 'fit' stands as tall as its content, and no taller than the screen.
9
+ * The other sizes are fractions of the screen; a form of five fields in a medium popup left half the card empty.
10
+ */
11
+ async function openWith(height: number) {
12
+ const handle = openPopup(html`<div class="content" style="height: ${height}px">content</div>`, { size: 'fit', title: 'form' })
13
+ const overlay = document.getElementById(handle.name) as OxFloatingOverlay
14
+ await overlay.updateComplete
15
+ const card = overlay.renderRoot.querySelector('[overlayed]') as HTMLElement
16
+ const header = overlay.renderRoot.querySelector('[header]') as HTMLElement
17
+ return { handle, card, header }
18
+ }
19
+
20
+ describe("openPopup size 'fit'", () => {
21
+ it('stands at its content height', async () => {
22
+ const { handle, card, header } = await openWith(120)
23
+ const expected = header.getBoundingClientRect().height + 120
24
+
25
+ expect(card.getBoundingClientRect().height).to.be.closeTo(expected, 2)
26
+ handle.close()
27
+ })
28
+
29
+ it('stays inside the screen when the content is taller', async () => {
30
+ const { handle, card } = await openWith(5000)
31
+
32
+ expect(card.getBoundingClientRect().height).to.be.at.most(window.innerHeight - 32 + 0.5)
33
+ handle.close()
34
+ })
35
+
36
+ it('is no wider than the form width', async () => {
37
+ const { handle, card } = await openWith(120)
38
+
39
+ expect(card.getBoundingClientRect().width).to.be.at.most(Math.min(480, window.innerWidth - 32) + 0.5)
40
+ handle.close()
41
+ })
42
+ })