@@ -11,68 +11,112 @@ function item(name: string) {
11
11
12
12
test . describe . serial ( 'jupyterlab-unfold' , ( ) => {
13
13
test ( 'should unfold' , async ( { page } ) => {
14
+ let workspace = { data : { } , metadata : { id : 'default' } } ;
15
+ await page . route ( / .* \/ a p i \/ w o r k s p a c e s .* / , ( route , request ) => {
16
+ if ( request . method ( ) === 'GET' ) {
17
+ route . fulfill ( {
18
+ status : 200 ,
19
+ body : JSON . stringify ( workspace )
20
+ } ) ;
21
+ } else if ( request . method ( ) === 'PUT' ) {
22
+ workspace = request . postDataJSON ( ) ;
23
+ route . fulfill ( { status : 204 } ) ;
24
+ } else {
25
+ route . continue ( ) ;
26
+ }
27
+ } ) ;
28
+
14
29
await page . goto ( `${ TARGET_URL } /lab` ) ;
15
30
await page . waitForSelector ( '#jupyterlab-splash' , { state : 'detached' } ) ;
16
31
await page . waitForSelector ( 'div[role="main"] >> text=Launcher' ) ;
17
32
18
33
// Let time for JupyterLab to finish rendering
19
- await page . waitForTimeout ( 2000 ) ;
34
+ await page . hover ( item ( 'dir1' ) ) ;
20
35
21
- expect (
22
- await page . locator ( TREE_LOCATOR ) . screenshot ( )
23
- ) . toMatchSnapshot ( 'first-render.png' ) ;
36
+ expect ( await page . locator ( TREE_LOCATOR ) . screenshot ( ) ) . toMatchSnapshot (
37
+ 'first-render.png'
38
+ ) ;
24
39
25
40
await page . click ( item ( 'dir1' ) ) ;
26
41
await page . waitForSelector ( item ( 'dir2' ) ) ;
27
42
28
- expect (
29
- await page . locator ( TREE_LOCATOR ) . screenshot ( )
30
- ) . toMatchSnapshot ( 'unfold-dir1.png' ) ;
43
+ expect ( await page . locator ( TREE_LOCATOR ) . screenshot ( ) ) . toMatchSnapshot (
44
+ 'unfold-dir1.png'
45
+ ) ;
31
46
32
47
await page . click ( item ( 'dir2' ) ) ;
33
48
await page . waitForSelector ( item ( 'dir3' ) ) ;
34
49
35
- expect (
36
- await page . locator ( TREE_LOCATOR ) . screenshot ( )
37
- ) . toMatchSnapshot ( 'unfold-dir2.png' ) ;
50
+ expect ( await page . locator ( TREE_LOCATOR ) . screenshot ( ) ) . toMatchSnapshot (
51
+ 'unfold-dir2.png'
52
+ ) ;
38
53
39
54
await page . click ( item ( 'dir3' ) ) ;
40
55
await page . waitForSelector ( item ( 'file211.txt' ) ) ;
41
56
42
- expect (
43
- await page . locator ( TREE_LOCATOR ) . screenshot ( )
44
- ) . toMatchSnapshot ( 'unfold-dir3.png' ) ;
57
+ expect ( await page . locator ( TREE_LOCATOR ) . screenshot ( ) ) . toMatchSnapshot (
58
+ 'unfold-dir3.png'
59
+ ) ;
45
60
46
61
await page . click ( item ( 'dir2' ) ) ;
47
62
await page . waitForSelector ( item ( 'dir3' ) , { state : 'detached' } ) ;
48
63
49
- expect (
50
- await page . locator ( TREE_LOCATOR ) . screenshot ( )
51
- ) . toMatchSnapshot ( 'fold-dir2.png' ) ;
52
-
53
- await page . click ( item ( 'dir2' ) ) ;
64
+ expect ( await page . locator ( TREE_LOCATOR ) . screenshot ( ) ) . toMatchSnapshot (
65
+ 'fold-dir2.png'
66
+ ) ;
67
+
68
+ await Promise . all ( [
69
+ page . waitForResponse (
70
+ response =>
71
+ response . request ( ) . method ( ) === 'PUT' &&
72
+ response . status ( ) === 204 &&
73
+ response . url ( ) . includes ( 'api/workspaces' )
74
+ ) ,
75
+ page . click ( item ( 'dir2' ) )
76
+ ] ) ;
54
77
await page . waitForSelector ( item ( 'dir3' ) ) ;
55
78
56
- expect (
57
- await page . locator ( TREE_LOCATOR ) . screenshot ( )
58
- ) . toMatchSnapshot ( 'unfold-dir2-2.png' ) ;
79
+ expect ( await page . locator ( TREE_LOCATOR ) . screenshot ( ) ) . toMatchSnapshot (
80
+ 'unfold-dir2-2.png'
81
+ ) ;
59
82
} ) ;
60
83
61
-
62
84
test ( 'should open file' , async ( { page } ) => {
85
+ let workspace = {
86
+ data : {
87
+ 'file-browser-jupyterlab-unfold:openState' : {
88
+ openState : { '.' : true , dir1 : true , dir2 : true , 'dir2/dir3' : true }
89
+ }
90
+ } ,
91
+ metadata : { id : 'default' }
92
+ } ;
93
+ await page . route ( / .* \/ a p i \/ w o r k s p a c e s .* / , ( route , request ) => {
94
+ if ( request . method ( ) === 'GET' ) {
95
+ route . fulfill ( {
96
+ status : 200 ,
97
+ body : JSON . stringify ( workspace )
98
+ } ) ;
99
+ } else if ( request . method ( ) === 'PUT' ) {
100
+ workspace = request . postDataJSON ( ) ;
101
+ route . fulfill ( { status : 204 } ) ;
102
+ } else {
103
+ route . continue ( ) ;
104
+ }
105
+ } ) ;
106
+
63
107
await page . goto ( `${ TARGET_URL } /lab` ) ;
64
108
await page . waitForSelector ( '#jupyterlab-splash' , { state : 'detached' } ) ;
65
109
await page . waitForSelector ( 'div[role="main"] >> text=Launcher' ) ;
66
110
67
111
// Let time for JupyterLab to finish rendering
68
- await page . waitForTimeout ( 2000 ) ;
112
+ await page . hover ( item ( 'dir1' ) ) ;
69
113
70
114
await page . dblclick ( item ( 'file211.txt' ) ) ;
71
- // TODO Use something more reliable
72
- await page . waitForTimeout ( 1000 ) ;
73
115
74
- expect (
75
- await page . locator ( TABS_LOCATOR ) . screenshot ( )
76
- ) . toMatchSnapshot ( 'open-file211.png' ) ;
116
+ await page . waitForSelector ( '[role="main"] >> text=file211.txt' ) ;
117
+
118
+ expect ( await page . locator ( TABS_LOCATOR ) . screenshot ( ) ) . toMatchSnapshot (
119
+ 'open-file211.png'
120
+ ) ;
77
121
} ) ;
78
122
} ) ;
0 commit comments