Skip to content

Commit fbe8c42

Browse files
v2 label vitest (#254)
Co-authored-by: thejackshelton-kunaico <[email protected]>
1 parent 1083c93 commit fbe8c42

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { component$ } from "@qwik.dev/core";
2+
import { page, userEvent } from "@vitest/browser/context";
3+
import { expect, test } from "vitest";
4+
import { render } from "vitest-browser-qwik";
5+
import { Label } from ".";
6+
7+
// Top-level locator constants using data-testid
8+
const LabelEl = page.getByTestId("label");
9+
const InputEl = page.getByTestId("input");
10+
11+
const Basic = component$(() => {
12+
const inputId = "name-input";
13+
return (
14+
<div>
15+
<Label data-testid="label" for={inputId}>
16+
Name
17+
</Label>
18+
<input id={inputId} data-testid="input" />
19+
</div>
20+
);
21+
});
22+
23+
test("label is visible", async () => {
24+
render(<Basic />);
25+
26+
await expect.element(LabelEl).toBeVisible();
27+
});
28+
29+
test("clicking label focuses the input", async () => {
30+
render(<Basic />);
31+
32+
await userEvent.click(LabelEl);
33+
await expect.element(InputEl).toHaveFocus();
34+
});
35+
36+
test("double clicking label does not select text", async () => {
37+
render(<Basic />);
38+
39+
await userEvent.dblClick(LabelEl);
40+
const selection = window.getSelection()?.toString();
41+
expect(selection).toBeFalsy();
42+
});

0 commit comments

Comments
 (0)