Skip to content

Commit

Permalink
test: implement file tree automatic location
Browse files Browse the repository at this point in the history
  • Loading branch information
Ricbet committed Oct 11, 2022
1 parent 65d33e9 commit b136438
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 4 deletions.
22 changes: 19 additions & 3 deletions tools/playwright/src/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,22 @@ export class OpenSumiEditor extends OpenSumiView {
});
}

async getTab() {
const path = (await this.filestatElement.getFsPath()) || '';
const tabsItems = await (await this.getTabElement())?.$$("[class*='kt_editor_tab___']");

if (!tabsItems) {
return;
}

for (const item of tabsItems) {
const uri = await item.getAttribute('data-uri');
if (uri?.includes(path)) {
return item;
}
}
}

async getCurrentTab() {
return await (await this.getTabElement())?.waitForSelector("[class*='kt_editor_tab_current___']");
}
Expand All @@ -24,13 +40,13 @@ export class OpenSumiEditor extends OpenSumiView {
}

async isPreview() {
const currentTab = await this.getCurrentTab();
const currentTab = await this.getTab();
const isPreview = (await currentTab?.getAttribute('class'))?.includes('kt_editor_tab_preview___');
return !!isPreview;
}

async isDirty() {
const dirtyIcon = await (await this.getCurrentTab())?.$("[class*='dirty___']");
const dirtyIcon = await (await this.getTab())?.$("[class*='dirty___']");
const className = await dirtyIcon?.getAttribute('class');
const hidden = className?.includes('hidden__');
return !hidden;
Expand All @@ -41,7 +57,7 @@ export class OpenSumiEditor extends OpenSumiView {
if (!(await this.isDirty())) {
return;
}
const dirtyIcon = await (await this.getCurrentTab())?.$("[class*='dirty___']");
const dirtyIcon = await (await this.getTab())?.$("[class*='dirty___']");
await this.app.menubar.trigger('File', 'Save File');
// waiting for saved
await dirtyIcon?.waitForElementState('hidden');
Expand Down
15 changes: 15 additions & 0 deletions tools/playwright/src/tests/editor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,21 @@ console.log(a);`,
await editor.close();
});

test('File tree automatic location', async () => {
editor = await app.openEditor(OpenSumiTextEditor, explorer, 'editor.js', false);
const editor2 = await app.openEditor(OpenSumiTextEditor, explorer, 'editor2.js', false);
await app.page.waitForTimeout(1000);
const firstFileTab = await editor.getTab();
await firstFileTab?.click();
await app.page.waitForTimeout(1000);
const node = await explorer.getFileStatTreeNodeByPath('editor.js');
expect(await node?.isSelected()).toBeTruthy();
const node2 = await explorer.getFileStatTreeNodeByPath('editor2.js');
expect(await node2?.isSelected()).toBeFalsy();
await editor.close();
await editor2.close();
});

test('Close All Editors should be worked', async () => {
editor = await app.openEditor(OpenSumiTextEditor, explorer, 'editor.js', false);
const editor2 = await app.openEditor(OpenSumiTextEditor, explorer, 'editor2.js', false);
Expand Down
2 changes: 1 addition & 1 deletion tools/playwright/src/text-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class OpenSumiTextEditor extends OpenSumiEditor {
}

async openTabContextMenu() {
const view = await this.getCurrentTab();
const view = await this.getTab();
if (!view) {
return;
}
Expand Down
11 changes: 11 additions & 0 deletions tools/playwright/src/tree-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ export class OpenSumiTreeNode {
},
) {}

async parentElementHandle() {
const parent = await this.elementHandle.getProperty('parentNode');
return parent.asElement();
}

async label() {
const labelElement = await this.elementHandle.$(this.selector.labelClass);
if (!labelElement) {
Expand All @@ -42,6 +47,12 @@ export class OpenSumiTreeNode {
return descriptionElement.textContent();
}

async isSelected() {
const id = await this.elementHandle.getAttribute('data-id');
const parent = await this.parentElementHandle();
return !!(await parent?.$(`[data-id='${id}']${this.selector.selectedClass}`));
}

async isCollapsed() {
return !!(await this.elementHandle.$(this.selector.collapsedClass));
}
Expand Down

0 comments on commit b136438

Please sign in to comment.