Skip to content

Commit 2fdf9f1

Browse files
committed
test: implement file tree automatic location
1 parent 7e47655 commit 2fdf9f1

4 files changed

Lines changed: 46 additions & 4 deletions

File tree

tools/playwright/src/editor.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,22 @@ export class OpenSumiEditor extends OpenSumiView {
1212
});
1313
}
1414

15+
async getTab() {
16+
const path = (await this.filestatElement.getFsPath()) || '';
17+
const tabsItems = await (await this.getTabElement())?.$$("[class*='kt_editor_tab___']");
18+
19+
if (!tabsItems) {
20+
return;
21+
}
22+
23+
for (const item of tabsItems) {
24+
const uri = await item.getAttribute('data-uri');
25+
if (uri?.includes(path)) {
26+
return item;
27+
}
28+
}
29+
}
30+
1531
async getCurrentTab() {
1632
return await (await this.getTabElement())?.waitForSelector("[class*='kt_editor_tab_current___']");
1733
}
@@ -24,13 +40,13 @@ export class OpenSumiEditor extends OpenSumiView {
2440
}
2541

2642
async isPreview() {
27-
const currentTab = await this.getCurrentTab();
43+
const currentTab = await this.getTab();
2844
const isPreview = (await currentTab?.getAttribute('class'))?.includes('kt_editor_tab_preview___');
2945
return !!isPreview;
3046
}
3147

3248
async isDirty() {
33-
const dirtyIcon = await (await this.getCurrentTab())?.$("[class*='dirty___']");
49+
const dirtyIcon = await (await this.getTab())?.$("[class*='dirty___']");
3450
const className = await dirtyIcon?.getAttribute('class');
3551
const hidden = className?.includes('hidden__');
3652
return !hidden;
@@ -41,7 +57,7 @@ export class OpenSumiEditor extends OpenSumiView {
4157
if (!(await this.isDirty())) {
4258
return;
4359
}
44-
const dirtyIcon = await (await this.getCurrentTab())?.$("[class*='dirty___']");
60+
const dirtyIcon = await (await this.getTab())?.$("[class*='dirty___']");
4561
await this.app.menubar.trigger('File', 'Save File');
4662
// waiting for saved
4763
await dirtyIcon?.waitForElementState('hidden');

tools/playwright/src/tests/editor.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,21 @@ console.log(a);`,
5757
await editor.close();
5858
});
5959

60+
test('File tree automatic location', async () => {
61+
editor = await app.openEditor(OpenSumiTextEditor, explorer, 'editor.js', false);
62+
const editor2 = await app.openEditor(OpenSumiTextEditor, explorer, 'editor2.js', false);
63+
await app.page.waitForTimeout(1000);
64+
const firstFileTab = await editor.getTab();
65+
await firstFileTab?.click();
66+
await app.page.waitForTimeout(1000);
67+
const node = await explorer.getFileStatTreeNodeByPath('editor.js');
68+
expect(await node?.isSelected()).toBeTruthy();
69+
const node2 = await explorer.getFileStatTreeNodeByPath('editor2.js');
70+
expect(await node2?.isSelected()).toBeFalsy();
71+
await editor.close();
72+
await editor2.close();
73+
});
74+
6075
test('Close All Editors should be worked', async () => {
6176
editor = await app.openEditor(OpenSumiTextEditor, explorer, 'editor.js', false);
6277
const editor2 = await app.openEditor(OpenSumiTextEditor, explorer, 'editor2.js', false);

tools/playwright/src/text-editor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export class OpenSumiTextEditor extends OpenSumiEditor {
2323
}
2424

2525
async openTabContextMenu() {
26-
const view = await this.getCurrentTab();
26+
const view = await this.getTab();
2727
if (!view) {
2828
return;
2929
}

tools/playwright/src/tree-node.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ export class OpenSumiTreeNode {
2626
},
2727
) {}
2828

29+
async parentElementHandle() {
30+
const parent = await this.elementHandle.getProperty('parentNode');
31+
return parent.asElement();
32+
}
33+
2934
async label() {
3035
const labelElement = await this.elementHandle.$(this.selector.labelClass);
3136
if (!labelElement) {
@@ -42,6 +47,12 @@ export class OpenSumiTreeNode {
4247
return descriptionElement.textContent();
4348
}
4449

50+
async isSelected() {
51+
const id = await this.elementHandle.getAttribute('data-id');
52+
const parent = await this.parentElementHandle();
53+
return !!(await parent?.$(`[data-id='${id}']${this.selector.selectedClass}`));
54+
}
55+
4556
async isCollapsed() {
4657
return !!(await this.elementHandle.$(this.selector.collapsedClass));
4758
}

0 commit comments

Comments
 (0)