1
+ import React from 'react' ;
2
+ import {
3
+ expect ,
4
+ test ,
5
+ } from '@playwright/experimental-ct-react' ;
6
+ import { propTests } from '../../../../tests/playwright' ;
7
+ import { TextLinkForTest } from './TextLink.story' ;
8
+
9
+ test . describe ( 'TextLink' , ( ) => {
10
+ test . describe ( 'visual' , ( ) => {
11
+ [
12
+ ...propTests . labelPropTest
13
+ ] . forEach ( ( {
14
+ name,
15
+ onBeforeTest,
16
+ props,
17
+ } ) => {
18
+ test ( name , async ( {
19
+ mount,
20
+ page
21
+ } ) => {
22
+ if ( onBeforeTest ) {
23
+ await onBeforeTest ( page ) ;
24
+ }
25
+
26
+ const component = await mount (
27
+ < TextLinkForTest
28
+ { ...props }
29
+ />
30
+ ) ;
31
+
32
+ const screenshot = await component . screenshot ( ) ;
33
+ expect ( screenshot ) . toMatchSnapshot ( ) ;
34
+ } ) ;
35
+ } ) ;
36
+ } )
37
+
38
+ test . describe ( 'non-visual' , ( ) => {
39
+ test ( 'href' , async ( { mount } ) => {
40
+ const component = await mount (
41
+ < TextLinkForTest
42
+ href = '/test/uri'
43
+ label = 'test-label'
44
+ />
45
+ )
46
+
47
+ await expect ( component ) . toHaveAttribute ( 'href' , '/test/uri' ) ;
48
+ } ) ;
49
+ } )
50
+
51
+ test . describe ( 'functionality' , ( ) => {
52
+ test ( 'calls onClick when clicked' , async ( { mount} ) => {
53
+ let clicked = false ;
54
+ const component = await mount (
55
+ < TextLinkForTest
56
+ href = '/test/uri'
57
+ label = 'test-label'
58
+ onClick = { ( ) => {
59
+ clicked = true ;
60
+ } }
61
+ /> ,
62
+ ) ;
63
+ await component . click ( ) ;
64
+
65
+ expect ( clicked ) . toBeTruthy ( ) ;
66
+ } ) ;
67
+
68
+ test ( 'calls onClick when Enter pressed' , async ( { mount } ) => {
69
+ let clicked = false ;
70
+ const component = await mount (
71
+ < TextLinkForTest
72
+ href = '/test/uri'
73
+ label = 'test-label'
74
+ onClick = { ( ) => {
75
+ clicked = true ;
76
+ } }
77
+ /> ,
78
+ ) ;
79
+ await component . press ( 'Enter' ) ;
80
+
81
+ expect ( clicked ) . toBeTruthy ( ) ;
82
+ } ) ;
83
+ } )
84
+ } ) ;
0 commit comments