mirror of
https://github.com/vrtmrz/obsidian-livesync.git
synced 2026-05-16 04:21:16 +00:00
WIP: Add test
This commit is contained in:
@@ -1,82 +0,0 @@
|
||||
/**
|
||||
* tests/basic.spec.ts
|
||||
*
|
||||
* Smoke tests for the Self-hosted LiveSync plugin running inside the real
|
||||
* Obsidian desktop application.
|
||||
*
|
||||
* What these tests verify
|
||||
* -----------------------
|
||||
* 1. Obsidian can launch with a fresh vault that has the plugin pre-installed.
|
||||
* 2. The vault workspace loads without errors.
|
||||
* 3. The plugin's settings tab is reachable via Settings > Self-hosted LiveSync.
|
||||
* 4. The initial (unconfigured) setup screen is displayed on the first open.
|
||||
*
|
||||
* Prerequisites
|
||||
* -------------
|
||||
* - `main.js` must exist at the repository root (run `npm run buildDev` first).
|
||||
* - Obsidian must be installed at the default path, or `OBSIDIAN_PATH` must be set.
|
||||
*
|
||||
* How to run
|
||||
* ----------
|
||||
* npm run test:obsidian:e2e
|
||||
* npm run test:obsidian:e2e:headed
|
||||
*/
|
||||
|
||||
import { test, expect } from "playwright/test";
|
||||
import { setupTestVault } from "../helpers/vault";
|
||||
import type { VaultSetupResult } from "../helpers/vault";
|
||||
import {
|
||||
launchObsidian,
|
||||
getMainWindow,
|
||||
waitForVaultReady,
|
||||
openLiveSyncSettings,
|
||||
SELECTOR_SETTINGS_CONTENT,
|
||||
} from "../helpers/obsidian";
|
||||
import type { ObsidianHandle } from "../helpers/obsidian";
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Shared state
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
let app: ObsidianHandle;
|
||||
let vault: VaultSetupResult;
|
||||
|
||||
test.beforeAll(async () => {
|
||||
vault = setupTestVault();
|
||||
app = await launchObsidian(vault.fakeAppData, vault.vaultDir);
|
||||
});
|
||||
|
||||
test.afterAll(async () => {
|
||||
if (app) {
|
||||
await app.close().catch(() => {});
|
||||
}
|
||||
vault?.cleanup();
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Test 1 – basic launch
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
test("Obsidian launches and vault workspace loads", async () => {
|
||||
const page = await getMainWindow(app);
|
||||
await waitForVaultReady(page);
|
||||
|
||||
const title = await page.title();
|
||||
expect(title).toBeTruthy();
|
||||
expect(title.length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Test 2 – settings tab
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
test("Self-hosted LiveSync settings tab is accessible", async () => {
|
||||
const page = await getMainWindow(app);
|
||||
await waitForVaultReady(page);
|
||||
|
||||
await openLiveSyncSettings(page);
|
||||
|
||||
const content = page.locator(SELECTOR_SETTINGS_CONTENT);
|
||||
await expect(content).toBeVisible();
|
||||
await expect(content.filter({ hasText: "Self-hosted LiveSync" })).toBeVisible({ timeout: 10_000 });
|
||||
});
|
||||
69
test_e2e/tests/dialogue1.spec.ts
Normal file
69
test_e2e/tests/dialogue1.spec.ts
Normal file
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
* tests/sample.spec.ts
|
||||
*
|
||||
* Example e2e test that opens a vault with pre-seeded settings.
|
||||
*/
|
||||
import {
|
||||
getMainWindow,
|
||||
waitForVaultReady,
|
||||
enablePluginInObsidian,
|
||||
isPluginEnabledInObsidian,
|
||||
} from "../helpers/obsidian";
|
||||
import type { ObsidianLiveSyncSettings } from "@lib/common/types";
|
||||
import { PartialMessages } from "@lib/common/messages/def";
|
||||
import { locateModalByTitle, withSeededVault } from "test_e2e/helpers/helpers";
|
||||
import { test, expect } from "test_e2e/helpers/wrapper";
|
||||
const def = PartialMessages.def;
|
||||
|
||||
test("show Welcome when isConfigured is false", async () => {
|
||||
await withSeededVault(
|
||||
{
|
||||
appJson: {
|
||||
promptDelete: false,
|
||||
},
|
||||
communityPlugins: [],
|
||||
pluginData: {
|
||||
"obsidian-livesync": {
|
||||
deviceAndVaultName: "e2e-configured-device",
|
||||
isConfigured: true,
|
||||
notifyThresholdOfRemoteStorageSize: 10000,
|
||||
} satisfies Partial<ObsidianLiveSyncSettings>,
|
||||
},
|
||||
},
|
||||
async ({ app }) => {
|
||||
const page = await getMainWindow(app);
|
||||
|
||||
await waitForVaultReady(page);
|
||||
await expect(enablePluginInObsidian(page, "obsidian-livesync")).resolves.not.toThrow();
|
||||
expect(isPluginEnabledInObsidian(page, "obsidian-livesync")).toBeTruthy();
|
||||
const welcome = locateModalByTitle(page, def["moduleMigration.titleWelcome"]);
|
||||
await expect(welcome).toBeHidden({ timeout: 1_000 });
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
test("does not show Welcome when isConfigured is true", async () => {
|
||||
await withSeededVault(
|
||||
{
|
||||
appJson: {
|
||||
promptDelete: false,
|
||||
},
|
||||
communityPlugins: [],
|
||||
pluginData: {
|
||||
"obsidian-livesync": {
|
||||
deviceAndVaultName: "e2e-configured-device",
|
||||
isConfigured: true,
|
||||
notifyThresholdOfRemoteStorageSize: 10000,
|
||||
} satisfies Partial<ObsidianLiveSyncSettings>,
|
||||
},
|
||||
},
|
||||
async ({ app }) => {
|
||||
const page = await getMainWindow(app);
|
||||
await waitForVaultReady(page);
|
||||
await expect(enablePluginInObsidian(page, "obsidian-livesync")).resolves.not.toThrow();
|
||||
expect(isPluginEnabledInObsidian(page, "obsidian-livesync")).toBeTruthy();
|
||||
const welcome = locateModalByTitle(page, def["moduleMigration.titleWelcome"]);
|
||||
await expect(welcome).toBeHidden({ timeout: 1_000 });
|
||||
}
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user