File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed
libs/components/src/label Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change
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
+ } ) ;
You can’t perform that action at this time.
0 commit comments