mirror of
https://github.com/jesse-r-s-hines/obsidian-open-tab-settings.git
synced 2026-07-22 05:43:41 +00:00
Add preview tab tests
This commit is contained in:
parent
ec54faa8f9
commit
ace8e3074b
5 changed files with 277 additions and 12 deletions
|
|
@ -14,6 +14,7 @@ type LeafInfo = {
|
|||
active: boolean,
|
||||
/** True if this leaf is selected within its tab group */
|
||||
currentTab: boolean,
|
||||
isPreview: boolean,
|
||||
}
|
||||
|
||||
class WorkspacePage {
|
||||
|
|
@ -85,6 +86,7 @@ class WorkspacePage {
|
|||
deferred: leaf.isDeferred, pinned: leaf.pinned,
|
||||
active: activeLeaf == leaf,
|
||||
currentTab: leaf.parent.children.indexOf(leaf) === leaf.parent.currentTab,
|
||||
isPreview: leaf.openTabSettings?.isPreview ?? false,
|
||||
};
|
||||
})
|
||||
);
|
||||
|
|
@ -239,6 +241,10 @@ class WorkspacePage {
|
|||
await browser.executeObsidianCommand("switcher:open");
|
||||
await browser.keys(path);
|
||||
await browser.keys(Key.Enter);
|
||||
|
||||
if ((await obsidianPage.getPlatform()).isMobile) {
|
||||
await browser.pause(500); // have to wait a bit for the animation to complete
|
||||
}
|
||||
}
|
||||
|
||||
async openFileViaFileExplorer(path: string): Promise<void> {
|
||||
|
|
@ -262,10 +268,28 @@ class WorkspacePage {
|
|||
}, name, value)
|
||||
}
|
||||
|
||||
async removeFile(file: string) {
|
||||
await browser.executeObsidian(async ({app}, file) => {
|
||||
await app.vault.delete(app.vault.getAbstractFileByPath(file)!);
|
||||
}, file);
|
||||
/** Replaces the leaf's content */
|
||||
async editLeaf(pathOrId: string, text: string) {
|
||||
const leafInfo = await workspacePage.getLeaf(pathOrId);
|
||||
await browser.executeObsidian(async ({app, obsidian}, leafInfo, text) => {
|
||||
const leaf = app.workspace.getLeafById(leafInfo.id)!;
|
||||
app.workspace.setActiveLeaf(leaf, {focus: true});
|
||||
await leaf.view.setState({...leaf.view.getState(), mode: "source"}, {history: false});
|
||||
if (leaf.view instanceof obsidian.MarkdownView) {
|
||||
leaf.view.editor.replaceSelection(text);
|
||||
} else {
|
||||
throw Error("Not a markdown view")
|
||||
}
|
||||
}, leafInfo, text);
|
||||
}
|
||||
|
||||
/** double click on the leaf's tab header (for testing tab preview) */
|
||||
async doubleClickTab(pathOrId: string) {
|
||||
const leafInfo = await workspacePage.getLeaf(pathOrId);
|
||||
await browser.executeObsidian(({app}, leafInfo) => {
|
||||
const elem = app.workspace.getLeafById(leafInfo.id)!.tabHeaderEl;
|
||||
elem.dispatchEvent(new MouseEvent("dblclick", {bubbles: true}));
|
||||
}, leafInfo);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -34,7 +34,6 @@ describe('Test disable options', function() {
|
|||
|
||||
describe('Test disabling the plugin', function() {
|
||||
before(async function() {
|
||||
await obsidianPage.disablePlugin("open-tab-settings");
|
||||
await workspacePage.setConfig('focusNewTab', false);
|
||||
});
|
||||
|
||||
|
|
@ -42,18 +41,19 @@ describe('Test disabling the plugin', function() {
|
|||
await workspacePage.loadPlatformWorkspaceLayout("empty");
|
||||
});
|
||||
|
||||
|
||||
after(async function() {
|
||||
afterEach(async function() {
|
||||
await obsidianPage.enablePlugin("open-tab-settings");
|
||||
});
|
||||
|
||||
it("Test disabling the plugin new tabs", async function() {
|
||||
it("new tabs", async function() {
|
||||
await obsidianPage.disablePlugin("open-tab-settings");
|
||||
await workspacePage.openFile("A.md");
|
||||
await workspacePage.openLink(await workspacePage.getLink("B"));
|
||||
await workspacePage.matchWorkspace([[{type: "markdown", file: "B.md", active: true}]]);
|
||||
})
|
||||
|
||||
it("Test disable deduplicateTabs", async function() {
|
||||
it("deduplicateTabs", async function() {
|
||||
await obsidianPage.disablePlugin("open-tab-settings");
|
||||
await workspacePage.openFile("A.md");
|
||||
await workspacePage.openFile("B.md");
|
||||
await workspacePage.setActiveFile("A.md");
|
||||
|
|
@ -63,6 +63,24 @@ describe('Test disabling the plugin', function() {
|
|||
{type: "markdown", file: "B.md", active: true}, {type: "markdown", file: "B.md"},
|
||||
]]);
|
||||
})
|
||||
|
||||
it('previewTabs', async function() {
|
||||
await workspacePage.setSettings({ openInNewTab: true, previewTabs: true });
|
||||
|
||||
await workspacePage.openFile("A.md");
|
||||
await workspacePage.openLink(await workspacePage.getLink("B"));
|
||||
await workspacePage.matchWorkspace([[
|
||||
{type: "markdown", file: "A.md", isPreview: false},
|
||||
{type: "markdown", file: "B.md", active: true, isPreview: true},
|
||||
]]);
|
||||
|
||||
await obsidianPage.disablePlugin("open-tab-settings");
|
||||
|
||||
await workspacePage.matchWorkspace([[
|
||||
{type: "markdown", file: "A.md", isPreview: false},
|
||||
{type: "markdown", file: "B.md", active: true, isPreview: false},
|
||||
]]);
|
||||
})
|
||||
})
|
||||
|
||||
describe('Test menu options', function() {
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ describe("Mod click", function() {
|
|||
})
|
||||
beforeEach(async function() {
|
||||
await workspacePage.loadPlatformWorkspaceLayout("empty");
|
||||
await workspacePage.setSettings({ openInNewTab: true, deduplicateTabs: true });
|
||||
await workspacePage.setSettings({ openInNewTab: true, deduplicateTabs: true, previewTabs: false });
|
||||
});
|
||||
|
||||
it('Test mod click same', async function() {
|
||||
|
|
@ -115,7 +115,7 @@ describe("Mod click", function() {
|
|||
]]);
|
||||
});
|
||||
|
||||
it("mode click opposite", async function() {
|
||||
it("mod click opposite", async function() {
|
||||
if ((await obsidianPage.getPlatform()).isMobile) this.skip();
|
||||
await workspacePage.setSettings({
|
||||
openInNewTab: true, deduplicateTabs: false, newTabTabGroupPlacement: "opposite",
|
||||
|
|
@ -131,4 +131,16 @@ describe("Mod click", function() {
|
|||
[{type: "markdown", file: "B.md"}, {type: "markdown", file: "B.md"}]
|
||||
]);
|
||||
})
|
||||
|
||||
it("mod click preview", async function() {
|
||||
await workspacePage.setSettings({ openInNewTab: true, previewTabs: true, deduplicateTabs: false });
|
||||
|
||||
await workspacePage.setSettings({ modClickBehavior: "no_preview" });
|
||||
await workspacePage.openFile("A.md");
|
||||
await (await workspacePage.getLink("B")).click({"button": "middle"});
|
||||
await workspacePage.matchWorkspace([[
|
||||
{type: "markdown", file: "A.md", isPreview: false},
|
||||
{type: "markdown", file: "B.md", active: true, isPreview: false},
|
||||
]]);
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ const tests = () => {
|
|||
await workspacePage.openFile("A.md");
|
||||
await browser.executeObsidianCommand("workspace:new-tab");
|
||||
await workspacePage.matchWorkspace([[
|
||||
{type: "markdown", file: "A.md"}, {type: "empty", active: true},
|
||||
{type: "markdown", file: "A.md", isPreview: false}, {type: "empty", active: true, isPreview: false},
|
||||
]]);
|
||||
})
|
||||
|
||||
|
|
|
|||
211
test/specs/previewTabs.e2e.ts
Normal file
211
test/specs/previewTabs.e2e.ts
Normal file
|
|
@ -0,0 +1,211 @@
|
|||
import { browser } from '@wdio/globals'
|
||||
import workspacePage from 'test/pageobjects/workspace.page';
|
||||
import { obsidianPage } from 'wdio-obsidian-service';
|
||||
|
||||
|
||||
describe('Preview tabs', function() {
|
||||
beforeEach(async function() {
|
||||
await obsidianPage.resetVault();
|
||||
await workspacePage.loadPlatformWorkspaceLayout("empty");
|
||||
await workspacePage.setSettings({ openInNewTab: true, previewTabs: true, deduplicateTabs: false });
|
||||
await workspacePage.setConfig('focusNewTab', false);
|
||||
});
|
||||
|
||||
it('opens new tabs as preview tabs', async function() {
|
||||
await workspacePage.openFile("A.md");
|
||||
await workspacePage.openLink(await workspacePage.getLink("B"));
|
||||
|
||||
await workspacePage.matchWorkspace([[
|
||||
{type: "markdown", file: "A.md", isPreview: false},
|
||||
{type: "markdown", file: "B.md", active: true, isPreview: true},
|
||||
]]);
|
||||
})
|
||||
|
||||
it('replaces the preview tab instead of opening a new tab', async function() {
|
||||
await workspacePage.openFile("A.md");
|
||||
await workspacePage.openLink(await workspacePage.getLink("B"));
|
||||
await workspacePage.matchWorkspace([[
|
||||
{type: "markdown", file: "A.md", isPreview: false},
|
||||
{type: "markdown", file: "B.md", active: true, isPreview: true},
|
||||
]]);
|
||||
|
||||
await workspacePage.openFileViaQuickSwitcher("D.md");
|
||||
await workspacePage.matchWorkspace([[
|
||||
{type: "markdown", file: "A.md", isPreview: false},
|
||||
{type: "markdown", file: "D.md", active: true, isPreview: true},
|
||||
]]);
|
||||
})
|
||||
|
||||
it('promotes previews on edit', async function() {
|
||||
await workspacePage.openFile("A.md");
|
||||
await workspacePage.openLink(await workspacePage.getLink("B"));
|
||||
await workspacePage.matchWorkspace([[
|
||||
{type: "markdown", file: "A.md", isPreview: false},
|
||||
{type: "markdown", file: "B.md", active: true, isPreview: true},
|
||||
]]);
|
||||
|
||||
await workspacePage.editLeaf("B.md", "some edit");
|
||||
await workspacePage.matchWorkspace([[
|
||||
{type: "markdown", file: "A.md", isPreview: false},
|
||||
{type: "markdown", file: "B.md", isPreview: false},
|
||||
]]);
|
||||
|
||||
await workspacePage.openFileViaQuickSwitcher("D.md");
|
||||
await workspacePage.matchWorkspace([[
|
||||
{type: "markdown", file: "A.md", isPreview: false},
|
||||
{type: "markdown", file: "B.md", isPreview: false},
|
||||
{type: "markdown", file: "D.md", active: true, isPreview: true},
|
||||
]]);
|
||||
})
|
||||
|
||||
it('promotes previews on double click', async function() {
|
||||
await workspacePage.openFile("A.md");
|
||||
await workspacePage.openLink(await workspacePage.getLink("B"));
|
||||
await workspacePage.matchWorkspace([[
|
||||
{type: "markdown", file: "A.md", isPreview: false},
|
||||
{type: "markdown", file: "B.md", active: true, isPreview: true},
|
||||
]]);
|
||||
|
||||
await workspacePage.doubleClickTab("B.md");
|
||||
await workspacePage.matchWorkspace([[
|
||||
{type: "markdown", file: "A.md", isPreview: false},
|
||||
{type: "markdown", file: "B.md", isPreview: false},
|
||||
]]);
|
||||
})
|
||||
|
||||
it('promotes previews on pin', async function() {
|
||||
await workspacePage.openFile("A.md");
|
||||
await workspacePage.openLink(await workspacePage.getLink("B"));
|
||||
await workspacePage.matchWorkspace([[
|
||||
{type: "markdown", file: "A.md", isPreview: false},
|
||||
{type: "markdown", file: "B.md", active: true, isPreview: true},
|
||||
]]);
|
||||
|
||||
await workspacePage.pinTab("B.md");
|
||||
await workspacePage.matchWorkspace([[
|
||||
{type: "markdown", file: "A.md", isPreview: false},
|
||||
{type: "markdown", file: "B.md", isPreview: false},
|
||||
]]);
|
||||
})
|
||||
|
||||
it('promote twice', async function() {
|
||||
await workspacePage.openFile("A.md");
|
||||
await workspacePage.openLink(await workspacePage.getLink("B"));
|
||||
await workspacePage.matchWorkspace([[
|
||||
{type: "markdown", file: "A.md", isPreview: false},
|
||||
{type: "markdown", file: "B.md", active: true, isPreview: true},
|
||||
]]);
|
||||
|
||||
await workspacePage.editLeaf("B.md", "some edit");
|
||||
await browser.pause(500)
|
||||
await workspacePage.editLeaf("B.md", "another edit");
|
||||
// edits after the first should be ignored
|
||||
await workspacePage.matchWorkspace([[
|
||||
{type: "markdown", file: "A.md", isPreview: false},
|
||||
{type: "markdown", file: "B.md", isPreview: false},
|
||||
]]);
|
||||
})
|
||||
|
||||
it('multiple tabs in a group', async function() {
|
||||
await workspacePage.openFile("A.md");
|
||||
await workspacePage.openLink(await workspacePage.getLink("B"));
|
||||
await workspacePage.doubleClickTab("B.md");
|
||||
await workspacePage.matchWorkspace([[
|
||||
{type: "markdown", file: "A.md", isPreview: false},
|
||||
{type: "markdown", file: "B.md", isPreview: false},
|
||||
]]);
|
||||
await workspacePage.setActiveFile("A.md");
|
||||
|
||||
await workspacePage.openFileViaQuickSwitcher("D.md");
|
||||
await workspacePage.openFileViaQuickSwitcher("Loop.md");
|
||||
|
||||
await workspacePage.matchWorkspace([[
|
||||
{type: "markdown", file: "A.md", isPreview: false},
|
||||
{type: "markdown", file: "Loop.md", active: true, isPreview: true},
|
||||
{type: "markdown", file: "B.md", isPreview: false},
|
||||
]]);
|
||||
})
|
||||
|
||||
it('open to right does not make a preview tab', async function() {
|
||||
if ((await obsidianPage.getPlatform()).isPhone) this.skip();
|
||||
|
||||
await workspacePage.openFileViaFileExplorer("A.md");
|
||||
|
||||
await workspacePage.openLinkToRight(await workspacePage.getLink("B"));
|
||||
await workspacePage.matchWorkspace([
|
||||
[{type: "markdown", file: "A.md", isPreview: true}],
|
||||
[{type: "markdown", file: "B.md", active: true, isPreview: false}],
|
||||
]);
|
||||
})
|
||||
|
||||
it('can have a single preview tab per group', async function() {
|
||||
if ((await obsidianPage.getPlatform()).isPhone) this.skip();
|
||||
|
||||
await workspacePage.openFileViaFileExplorer("A.md");
|
||||
|
||||
await workspacePage.openLinkToRight(await workspacePage.getLink("B"));
|
||||
await workspacePage.openFileViaFileExplorer("D.md");
|
||||
|
||||
await workspacePage.matchWorkspace([
|
||||
[{file: "A.md", isPreview: true}],
|
||||
[{file: "B.md", isPreview: false}, {file: "D.md", active: true, isPreview: true}],
|
||||
]);
|
||||
|
||||
await workspacePage.openLink(await workspacePage.getLink("Loop"));
|
||||
|
||||
await workspacePage.matchWorkspace([
|
||||
[{file: "A.md", isPreview: true}],
|
||||
[{file: "B.md", isPreview: false}, {file: "Loop.md", active: true, isPreview: true}],
|
||||
]);
|
||||
|
||||
await workspacePage.doubleClickTab("Loop.md")
|
||||
await workspacePage.openLink(await workspacePage.getLink("B"));
|
||||
|
||||
await workspacePage.matchWorkspace([
|
||||
[{file: "A.md", isPreview: true}],
|
||||
[
|
||||
{file: "B.md", isPreview: false},
|
||||
{file: "Loop.md", isPreview: false},
|
||||
{file: "B.md", active: true, isPreview: true},
|
||||
],
|
||||
]);
|
||||
})
|
||||
|
||||
it('cleanup on setting disable', async function() {
|
||||
await workspacePage.openFile("A.md");
|
||||
await workspacePage.openLink(await workspacePage.getLink("B"));
|
||||
await workspacePage.matchWorkspace([[
|
||||
{type: "markdown", file: "A.md", isPreview: false},
|
||||
{type: "markdown", file: "B.md", active: true, isPreview: true},
|
||||
]]);
|
||||
|
||||
await workspacePage.setSettings({ previewTabs: false });
|
||||
await workspacePage.matchWorkspace([[
|
||||
{type: "markdown", file: "A.md", isPreview: false},
|
||||
{type: "markdown", file: "B.md", active: true, isPreview: false},
|
||||
]]);
|
||||
})
|
||||
|
||||
it('with deduplicate', async function() {
|
||||
await workspacePage.setSettings({ deduplicateTabs: true });
|
||||
|
||||
await workspacePage.openFile("A.md");
|
||||
await workspacePage.openLink(await workspacePage.getLink("B"));
|
||||
await workspacePage.matchWorkspace([[
|
||||
{type: "markdown", file: "A.md", isPreview: false},
|
||||
{type: "markdown", file: "B.md", active: true, isPreview: true},
|
||||
]]);
|
||||
|
||||
await workspacePage.openLink(await workspacePage.getLink("A"))
|
||||
await workspacePage.matchWorkspace([[
|
||||
{type: "markdown", file: "A.md", active: true, isPreview: false},
|
||||
{type: "markdown", file: "B.md", isPreview: true},
|
||||
]]);
|
||||
|
||||
await workspacePage.openLink(await workspacePage.getLink("B"))
|
||||
await workspacePage.matchWorkspace([[
|
||||
{type: "markdown", file: "A.md", isPreview: false},
|
||||
{type: "markdown", file: "B.md", active: true, isPreview: true},
|
||||
]]);
|
||||
})
|
||||
})
|
||||
Loading…
Reference in a new issue