Skip to content

Commit 5dbe404

Browse files
committed
Fix ui-tests
1 parent 3e8fe05 commit 5dbe404

File tree

1 file changed

+72
-28
lines changed

1 file changed

+72
-28
lines changed

ui-tests/tests/jupyterlab-unfold.spec.ts

Lines changed: 72 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,68 +11,112 @@ function item(name: string) {
1111

1212
test.describe.serial('jupyterlab-unfold', () => {
1313
test('should unfold', async ({ page }) => {
14+
let workspace = { data: {}, metadata: { id: 'default' } };
15+
await page.route(/.*\/api\/workspaces.*/, (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+
1429
await page.goto(`${TARGET_URL}/lab`);
1530
await page.waitForSelector('#jupyterlab-splash', { state: 'detached' });
1631
await page.waitForSelector('div[role="main"] >> text=Launcher');
1732

1833
// Let time for JupyterLab to finish rendering
19-
await page.waitForTimeout(2000);
34+
await page.hover(item('dir1'));
2035

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+
);
2439

2540
await page.click(item('dir1'));
2641
await page.waitForSelector(item('dir2'));
2742

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+
);
3146

3247
await page.click(item('dir2'));
3348
await page.waitForSelector(item('dir3'));
3449

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+
);
3853

3954
await page.click(item('dir3'));
4055
await page.waitForSelector(item('file211.txt'));
4156

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+
);
4560

4661
await page.click(item('dir2'));
4762
await page.waitForSelector(item('dir3'), { state: 'detached' });
4863

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+
]);
5477
await page.waitForSelector(item('dir3'));
5578

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+
);
5982
});
6083

61-
6284
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(/.*\/api\/workspaces.*/, (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+
63107
await page.goto(`${TARGET_URL}/lab`);
64108
await page.waitForSelector('#jupyterlab-splash', { state: 'detached' });
65109
await page.waitForSelector('div[role="main"] >> text=Launcher');
66110

67111
// Let time for JupyterLab to finish rendering
68-
await page.waitForTimeout(2000);
112+
await page.hover(item('dir1'));
69113

70114
await page.dblclick(item('file211.txt'));
71-
// TODO Use something more reliable
72-
await page.waitForTimeout(1000);
73115

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+
);
77121
});
78122
});

0 commit comments

Comments
 (0)