Skip to content

chore: update overlay tests and Popover dev page #340

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions dev/pages/Popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export default function PopoverPage() {
const [withBackdrop, setWithBackdrop] = useState(false);
const [theme, setTheme] = useState('');
const [useTooltip, setUseTooltip] = useState(false);
const [contentWidth, setContentWidth] = useState('');
const [contentHeight, setContentHeight] = useState('');
const [width, setWidth] = useState<string | null>(null);
const [height, setHeight] = useState<string | null>(null);
const [content, setContent] = useState('This is the popover content');
const [useRichContent, setUseRichContent] = useState(false);

Expand Down Expand Up @@ -50,8 +50,8 @@ export default function PopoverPage() {
modal={modal}
withBackdrop={withBackdrop}
theme={theme}
contentWidth={contentWidth}
contentHeight={contentHeight}
width={width}
height={height}
trigger={
[
...(triggerClick ? ['click'] : []),
Expand Down Expand Up @@ -182,20 +182,20 @@ export default function PopoverPage() {
rich content
</label>
<label>
Content Width:
Width:
<input
type="text"
value={contentWidth}
onChange={(e) => setContentWidth(e.target.value)}
value={width || ''}
onChange={(e) => setWidth(e.target.value || null)}
placeholder="e.g., 300px, 50%, etc."
/>
</label>
<label>
Content Height:
Height:
<input
type="text"
value={contentHeight}
onChange={(e) => setContentHeight(e.target.value)}
value={height || ''}
onChange={(e) => setHeight(e.target.value || null)}
placeholder="e.g., 200px, auto, etc."
/>
</label>
Expand Down
38 changes: 9 additions & 29 deletions test/Popover.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,53 +1,33 @@
import { afterEach, describe, expect, it } from 'vitest';
import { describe, expect, it } from 'vitest';
import { render } from 'vitest-browser-react';
import { Popover, type PopoverElement } from '../packages/react-components/src/Popover.js';
import createOverlayCloseCatcher from './utils/createOverlayCloseCatcher.js';

describe('Popover', () => {
const overlayTag = 'vaadin-popover-overlay';

const [ref, catcher] = createOverlayCloseCatcher<PopoverElement>(overlayTag, (ref) => {
ref.opened = false;
});

async function assert() {
async function assert(popover: PopoverElement) {
await new Promise((r) => requestAnimationFrame(r));
await new Promise((r) => requestAnimationFrame(r));

const overlay = document.querySelector(overlayTag);
expect(overlay).to.exist;

const childNodes = Array.from(overlay!.childNodes);
const childNodes = Array.from(popover.childNodes);

const body = childNodes.find((node) => node.nodeType === Node.TEXT_NODE);
expect(body).to.have.text('FooBar');
}

afterEach(catcher);

it('should use children if no renderer property set', async () => {
render(
<Popover ref={ref} opened>
FooBar
</Popover>,
);
render(<Popover opened>FooBar</Popover>);

await assert();
await assert(document.querySelector('vaadin-popover') as PopoverElement);
});

it('should use renderer prop if it is set', async () => {
render(<Popover ref={ref} opened renderer={() => <>FooBar</>}></Popover>);
render(<Popover opened renderer={() => <>FooBar</>}></Popover>);

await assert();
await assert(document.querySelector('vaadin-popover') as PopoverElement);
});

it('should use children as renderer prop', async () => {
render(
<Popover ref={ref} opened>
{() => <>FooBar</>}
</Popover>,
);
render(<Popover opened>{() => <>FooBar</>}</Popover>);

await assert();
await assert(document.querySelector('vaadin-popover') as PopoverElement);
});
});
8 changes: 6 additions & 2 deletions test/Select.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@ describe('Select', () => {

await user.click(valueButton);

const overlay = await findByQuerySelector('vaadin-select-overlay');
await vi.waitFor(() => {
expect(overlay).to.have.text('FooBar');
const listBox = select.querySelector('vaadin-list-box, vaadin-select-list-box');
expect(listBox).to.exist;

const items = listBox!.querySelectorAll('vaadin-item, vaadin-select-item');
expect(items[0]).to.have.text('Foo');
expect(items[1]).to.have.text('Bar');
});
}

Expand Down