File tree Expand file tree Collapse file tree 4 files changed +306
-267
lines changed
Expand file tree Collapse file tree 4 files changed +306
-267
lines changed Original file line number Diff line number Diff line change 1+ import { test , expect } from "@playwright/test" ;
2+
3+ test . use ( { viewport : { width : 480 , height : 360 } } ) ;
4+ test . describe ( "hooks" , ( ) => {
5+ test ( "counter" , async ( { page } ) => {
6+ await page . goto ( "/hooks" ) ;
7+ await expect ( page . locator ( '[data-testid="count"]' ) ) . toHaveText ( "0" ) ;
8+ await page . locator ( '[data-testid="add"]' ) . click ( ) ;
9+ await expect ( page . locator ( '[data-testid="count"]' ) ) . toHaveText ( "1" ) ;
10+ await page . locator ( '[data-testid="add"]' ) . click ( ) ;
11+ await expect ( page . locator ( '[data-testid="count"]' ) ) . toHaveText ( "2" ) ;
12+ } ) ;
13+
14+ test ( "authentication" , async ( { page } ) => {
15+ await page . goto ( "/hooks" , { waitUntil : "networkidle" } ) ;
16+ await expect (
17+ page . locator ( '[data-testid="not-authenticated"]' )
18+ ) . toBeVisible ( ) ;
19+ await expect (
20+ page . locator ( '[data-testid="authenticated"]' )
21+ ) . not . toBeVisible ( ) ;
22+ await page . locator ( '[data-testid="login"]' ) . click ( ) ;
23+ await expect ( page . locator ( '[data-testid="authenticated"]' ) ) . toBeVisible ( ) ;
24+ await page . locator ( '[data-testid="logout"]' ) . click ( ) ;
25+ await expect (
26+ page . locator ( '[data-testid="not-authenticated"]' )
27+ ) . toBeVisible ( ) ;
28+ } ) ;
29+ } ) ;
Original file line number Diff line number Diff line change 2222{#if $countHook }
2323 {@const [count , setCount ] = $countHook }
2424
25- <div >Count: {count }</div >
26- <button on:click ={() => setCount (count + 1 )}>+</button >
25+ <div >Count: < span data-testid = "count" > {count }</ span > </div >
26+ <button data-testid = "add" on:click ={() => setCount (count + 1 )}>+</button >
2727 <hr />
2828{/if }
2929<react:AuthProvider value ={auth }>
3030 <Nested />
3131</react:AuthProvider >
3232
3333{#if auth .authenticated }
34- <button on:click ={onLogout }>Logout</button >
34+ <button on:click ={onLogout } data-testid = " logout " >Logout</button >
3535{:else }
36- <button on:click ={onLogin }>Login</button >
36+ <button on:click ={onLogin } data-testid = " login " >Login</button >
3737{/if }
Original file line number Diff line number Diff line change 66 </script >
77
88{#if $auth ?.authenticated }
9- <div >Authenticated</div >
9+ <div data-testid = " authenticated " >Authenticated</div >
1010{:else }
11- <div >Not authenticated</div >
11+ <div data-testid = " not-authenticated " >Not authenticated</div >
1212{/if }
You can’t perform that action at this time.
0 commit comments