1
- import { test , expect } from '@playwright/test ' ;
1
+ import { test , expect } from './fixtures/app ' ;
2
2
import { uid } from 'uid' ;
3
3
import { IntervalType } from '../src/types' ;
4
4
@@ -12,69 +12,111 @@ test.describe('initial state', () => {
12
12
test . beforeEach ( async ( { page } ) => {
13
13
await page . goto ( '/' ) ;
14
14
} ) ;
15
- test ( 'default timer' , async ( { page } ) => {
16
- await expect ( page . getByRole ( ' timer' ) ) . toContainText ( '45:00' ) ;
15
+ test ( 'default timer' , async ( { appPage } ) => {
16
+ await expect ( appPage . timer ) . toContainText ( '45:00' ) ;
17
17
} ) ;
18
- test ( 'default timer - accessible name' , async ( { page } ) => {
19
- await expect ( page . getByRole ( ' timer' ) ) . toContainText ( '45 minutes left' ) ;
18
+ test ( 'default timer - accessible name' , async ( { appPage } ) => {
19
+ await expect ( appPage . timer ) . toContainText ( '45 minutes left' ) ;
20
20
} ) ;
21
- test ( 'cycle list' , async ( { page } ) => {
22
- const list = page . getByRole ( 'list' , { name : 'Intervals' } ) ;
23
- await expect ( list . getByRole ( 'listitem' ) ) . toHaveCount ( 1 ) ;
24
- await expect ( list . getByRole ( 'listitem' ) ) . toContainText ( 'W' ) ;
25
- await expect ( list . getByRole ( 'listitem' ) ) . toContainText ( '45:00' ) ;
21
+ test ( 'cycle list' , async ( { appPage } ) => {
22
+ await expect ( appPage . list . getByRole ( 'listitem' ) ) . toHaveCount ( 1 ) ;
23
+ await expect ( appPage . list . getByRole ( 'listitem' ) ) . toContainText ( 'W' ) ;
24
+ await expect ( appPage . list . getByRole ( 'listitem' ) ) . toContainText ( '45:00' ) ;
26
25
} ) ;
27
26
28
- test ( 'controls' , async ( { page } ) => {
29
- const controls = page . getByRole ( 'group' , { name : 'Timer controls' } ) ;
30
- await expect ( controls . getByRole ( 'button' , { name : 'Play' } ) ) . toBeVisible ( ) ;
31
- await expect ( controls . getByRole ( 'button' , { name : 'Skip' } ) ) . toBeVisible ( ) ;
32
- await expect ( controls . getByRole ( 'button' , { name : 'Reset' } ) ) . toBeVisible ( ) ;
27
+ test ( 'controls' , async ( { appPage } ) => {
33
28
await expect (
34
- controls . getByRole ( 'button' , { name : 'Settings' } ) ,
29
+ appPage . controls . getByRole ( 'button' , { name : 'Play' } ) ,
30
+ ) . toBeVisible ( ) ;
31
+ await expect (
32
+ appPage . controls . getByRole ( 'button' , { name : 'Skip' } ) ,
33
+ ) . toBeVisible ( ) ;
34
+ await expect (
35
+ appPage . controls . getByRole ( 'button' , { name : 'Reset' } ) ,
36
+ ) . toBeVisible ( ) ;
37
+ await expect (
38
+ appPage . controls . getByRole ( 'button' , { name : 'Settings' } ) ,
35
39
) . toBeVisible ( ) ;
36
40
} ) ;
37
41
} ) ;
38
42
39
43
test . describe ( 'functionality' , ( ) => {
40
- test . beforeEach ( async ( { page } ) => {
41
- // set two intervals
42
- await page . addInitScript (
43
- ( intervals ) => {
44
- window . localStorage . setItem ( 'intervals' , JSON . stringify ( intervals ) ) ;
45
- } ,
46
- [
47
- mockInterval ( IntervalType . Work , 1 ) ,
48
- mockInterval ( IntervalType . ShortBreak , 2 ) ,
49
- ] ,
50
- ) ;
44
+ test . beforeEach ( async ( { page, appPage } ) => {
45
+ await appPage . setStorage ( [
46
+ mockInterval ( IntervalType . Work , 1 ) ,
47
+ mockInterval ( IntervalType . ShortBreak , 2 ) ,
48
+ ] ) ;
51
49
await page . goto ( '/' ) ;
52
50
} ) ;
53
- test ( 'list of two intervals' , async ( { page } ) => {
54
- const list = page . getByRole ( 'list' , { name : 'Intervals' } ) ;
55
- await expect ( list . getByRole ( 'listitem' ) ) . toHaveCount ( 2 ) ;
51
+
52
+ test ( ' list of two intervals' , async ( { appPage } ) => {
53
+ await expect ( appPage . list . getByRole ( 'listitem' ) ) . toHaveCount ( 2 ) ;
56
54
} ) ;
57
55
58
- test ( 'play' , async ( { page } ) => {
59
- await page . getByRole ( 'button' , { name : 'Play' } ) . click ( ) ;
56
+ test ( 'play' , async ( { appPage } ) => {
57
+ await appPage . controls . getByRole ( 'button' , { name : 'Play' } ) . click ( ) ;
60
58
61
- await expect ( page . getByRole ( 'button' , { name : 'Play' } ) ) . not . toBeVisible ( ) ;
62
- await expect ( page . getByRole ( 'button' , { name : 'Pause' } ) ) . toBeVisible ( ) ;
59
+ await expect (
60
+ appPage . controls . getByRole ( 'button' , { name : 'Play' } ) ,
61
+ ) . not . toBeVisible ( ) ;
62
+ await expect (
63
+ appPage . controls . getByRole ( 'button' , { name : 'Pause' } ) ,
64
+ ) . toBeVisible ( ) ;
63
65
} ) ;
64
66
65
- test ( 'pause' , async ( { page } ) => {
66
- await page . getByRole ( 'button' , { name : 'Play' } ) . click ( ) ;
67
+ test ( 'pause' , async ( { appPage } ) => {
68
+ await appPage . controls . getByRole ( 'button' , { name : 'Play' } ) . click ( ) ;
67
69
68
- await expect ( page . getByRole ( 'button' , { name : 'Play' } ) ) . not . toBeVisible ( ) ;
69
- await page . getByRole ( 'button' , { name : 'Pause' } ) . click ( ) ;
70
- await expect ( page . getByRole ( 'button' , { name : 'Play' } ) ) . toBeVisible ( ) ;
70
+ await expect (
71
+ appPage . controls . getByRole ( 'button' , { name : 'Play' } ) ,
72
+ ) . not . toBeVisible ( ) ;
73
+ await appPage . controls . getByRole ( 'button' , { name : 'Pause' } ) . click ( ) ;
74
+ await expect (
75
+ appPage . controls . getByRole ( 'button' , { name : 'Play' } ) ,
76
+ ) . toBeVisible ( ) ;
71
77
} ) ;
72
78
73
- test ( 'skip' , async ( { page } ) => {
74
- await expect ( page . getByRole ( 'timer' ) ) . toContainText ( '01:00' ) ;
75
- await page . getByRole ( 'button' , { name : 'Skip' } ) . click ( ) ;
76
- await page . waitForTimeout ( 700 ) ;
79
+ test ( 'skip' , async ( { appPage } ) => {
80
+ await expect ( appPage . timer ) . toContainText ( '01:00' ) ;
77
81
78
- await expect ( page . getByRole ( 'timer' ) ) . toContainText ( '02:00' ) ;
82
+ await appPage . controls . getByRole ( 'button' , { name : 'Skip' } ) . click ( ) ;
83
+ await appPage . page . waitForTimeout ( 700 ) ;
84
+
85
+ await expect ( appPage . timer ) . toContainText ( '02:00' ) ;
86
+ } ) ;
87
+
88
+ test ( 'skip cycle' , async ( { appPage } ) => {
89
+ await expect ( appPage . timer ) . toContainText ( '01:00' ) ;
90
+
91
+ await appPage . controls . getByRole ( 'button' , { name : 'Skip' } ) . click ( ) ;
92
+ await appPage . page . waitForTimeout ( 700 ) ;
93
+
94
+ await expect ( appPage . timer ) . toContainText ( '02:00' ) ;
95
+
96
+ await appPage . controls . getByRole ( 'button' , { name : 'Skip' } ) . click ( ) ;
97
+ await appPage . page . waitForTimeout ( 700 ) ;
98
+
99
+ await expect ( appPage . timer ) . toContainText ( '01:00' ) ;
100
+ } ) ;
101
+
102
+ test ( 'skip when paused' , async ( { appPage } ) => {
103
+ await appPage . controls . getByRole ( 'button' , { name : 'Skip' } ) . click ( ) ;
104
+ await appPage . page . waitForTimeout ( 700 ) ;
105
+
106
+ await expect ( appPage . timer ) . toContainText ( '02:00' ) ;
107
+ await expect (
108
+ appPage . controls . getByRole ( 'button' , { name : 'Play' } ) ,
109
+ ) . toBeVisible ( ) ;
110
+ } ) ;
111
+
112
+ test ( 'skip when playing' , async ( { appPage } ) => {
113
+ await appPage . controls . getByRole ( 'button' , { name : 'Play' } ) . click ( ) ;
114
+ await appPage . controls . getByRole ( 'button' , { name : 'Skip' } ) . click ( ) ;
115
+ await appPage . page . waitForTimeout ( 700 ) ;
116
+
117
+ await expect ( appPage . timer ) . toContainText ( '02:00' ) ;
118
+ await expect (
119
+ appPage . controls . getByRole ( 'button' , { name : 'Pause' } ) ,
120
+ ) . toBeVisible ( ) ;
79
121
} ) ;
80
122
} ) ;
0 commit comments