forked from logseq/logseq
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ee38781
commit 147b2cc
Showing
4 changed files
with
130 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { test as base } from '@playwright/test'; | ||
import { ElectronApplication, Page, BrowserContext, _electron as electron } from 'playwright' | ||
|
||
let electronApp: ElectronApplication | ||
let context: BrowserContext | ||
let page: Page | ||
|
||
base.beforeAll(async () => { | ||
if (electronApp) { | ||
return ; | ||
} | ||
|
||
electronApp = await electron.launch({ | ||
cwd: "./static", | ||
args: ["electron.js"], | ||
}) | ||
|
||
context = electronApp.context() | ||
await context.tracing.start({ screenshots: true, snapshots: true }); | ||
|
||
// NOTE: The following ensures App first start with the correct path. | ||
|
||
const appPath = await electronApp.evaluate(async ({ app }) => { | ||
return app.getAppPath() | ||
}) | ||
console.log("Test start with AppPath:", appPath) | ||
|
||
page = await electronApp.firstWindow() | ||
|
||
await page.waitForLoadState('domcontentloaded') | ||
await page.waitForFunction('window.document.title != "Loading"') | ||
await page.waitForSelector('text=This is a demo graph, changes will not be saved until you open a local folder') | ||
|
||
page.once('load', async () => { | ||
console.log('Page loaded!') | ||
await page.screenshot({ path: 'startup.png' }) | ||
}) | ||
}) | ||
|
||
base.beforeEach(async () => { | ||
// discard any dialog by ESC | ||
if (page) { | ||
await page.keyboard.press('Escape') | ||
await page.keyboard.press('Escape') | ||
} | ||
}) | ||
|
||
base.afterAll(async () => { | ||
// if (electronApp) { | ||
// await electronApp.close() | ||
//} | ||
}) | ||
|
||
|
||
|
||
// hijack electron app into the test context | ||
export const test = base.extend<{ page: Page, context: BrowserContext, app: ElectronApplication }>({ | ||
page: async ({ }, use) => { | ||
await use(page); | ||
}, | ||
context: async ({ }, use) => { | ||
await use(context); | ||
}, | ||
app: async ({ }, use) => { | ||
await use(electronApp); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,83 +1,55 @@ | ||
import { test, expect } from '@playwright/test' | ||
import { ElectronApplication, Page, BrowserContext, _electron as electron } from 'playwright' | ||
import { expect } from '@playwright/test' | ||
import { test } from './fixtures' | ||
import { createRandomPage, newBlock, lastBlock, appFirstLoaded, IsMac, IsLinux } from './utils' | ||
|
||
let electronApp: ElectronApplication | ||
let context: BrowserContext | ||
let page: Page | ||
|
||
test.beforeAll(async () => { | ||
electronApp = await electron.launch({ | ||
cwd: "./static", | ||
args: ["electron.js"], | ||
}) | ||
|
||
context = electronApp.context() | ||
await context.tracing.start({ screenshots: true, snapshots: true }); | ||
}) | ||
|
||
test.beforeEach(async () => { | ||
// discard any dialog by ESC | ||
if (page) { | ||
await page.keyboard.press('Escape') | ||
await page.keyboard.press('Escape') | ||
} else { | ||
page = await electronApp.firstWindow() | ||
} | ||
}) | ||
|
||
test.afterAll(async () => { | ||
await electronApp.close() | ||
}) | ||
|
||
test('open search dialog', async () => { | ||
await appFirstLoaded(page) | ||
|
||
if (IsMac) { | ||
await page.keyboard.press('Meta+k') | ||
} else if (IsLinux) { | ||
await page.keyboard.press('Control+k') | ||
} else { | ||
// TODO: test on Windows and other platforms | ||
expect(false) | ||
} | ||
|
||
await page.waitForSelector('[placeholder="Search or create page"]') | ||
test('open search dialog', async ({ page }) => { | ||
if (IsMac) { | ||
await page.keyboard.press('Meta+k') | ||
} else if (IsLinux) { | ||
await page.keyboard.press('Control+k') | ||
} else { | ||
// TODO: test on Windows and other platforms | ||
expect(false) | ||
} | ||
|
||
await page.waitForSelector('[placeholder="Search or create page"]') | ||
await page.keyboard.press('Escape') | ||
await page.waitForSelector('[placeholder="Search or create page"]', { state: 'hidden' }) | ||
}) | ||
|
||
// See-also: https://github.com/logseq/logseq/issues/3278 | ||
test('insert link', async () => { | ||
await createRandomPage(page) | ||
|
||
let hotKey = 'Control+l' | ||
let selectAll = 'Control+a' | ||
if (IsMac) { | ||
hotKey = 'Meta+l' | ||
selectAll = 'Meta+a' | ||
} | ||
|
||
// Case 1: empty link | ||
await lastBlock(page) | ||
await page.press(':nth-match(textarea, 1)', hotKey) | ||
expect(await page.inputValue(':nth-match(textarea, 1)')).toBe('[]()') | ||
await page.type(':nth-match(textarea, 1)', 'Logseq Website') | ||
expect(await page.inputValue(':nth-match(textarea, 1)')).toBe('[Logseq Website]()') | ||
|
||
// Case 2: link with label | ||
await newBlock(page) | ||
await page.type(':nth-match(textarea, 1)', 'Logseq') | ||
await page.press(':nth-match(textarea, 1)', selectAll) | ||
await page.press(':nth-match(textarea, 1)', hotKey) | ||
expect(await page.inputValue(':nth-match(textarea, 1)')).toBe('[Logseq]()') | ||
await page.type(':nth-match(textarea, 1)', 'https://logseq.com/') | ||
expect(await page.inputValue(':nth-match(textarea, 1)')).toBe('[Logseq](https://logseq.com/)') | ||
|
||
// Case 3: link with URL | ||
await newBlock(page) | ||
await page.type(':nth-match(textarea, 1)', 'https://logseq.com/') | ||
await page.press(':nth-match(textarea, 1)', selectAll) | ||
await page.press(':nth-match(textarea, 1)', hotKey) | ||
expect(await page.inputValue(':nth-match(textarea, 1)')).toBe('[](https://logseq.com/)') | ||
await page.type(':nth-match(textarea, 1)', 'Logseq') | ||
expect(await page.inputValue(':nth-match(textarea, 1)')).toBe('[Logseq](https://logseq.com/)') | ||
test('insert link', async ({ page }) => { | ||
await createRandomPage(page) | ||
|
||
let hotKey = 'Control+l' | ||
let selectAll = 'Control+a' | ||
if (IsMac) { | ||
hotKey = 'Meta+l' | ||
selectAll = 'Meta+a' | ||
} | ||
|
||
// Case 1: empty link | ||
await lastBlock(page) | ||
await page.press(':nth-match(textarea, 1)', hotKey) | ||
expect(await page.inputValue(':nth-match(textarea, 1)')).toBe('[]()') | ||
await page.type(':nth-match(textarea, 1)', 'Logseq Website') | ||
expect(await page.inputValue(':nth-match(textarea, 1)')).toBe('[Logseq Website]()') | ||
|
||
// Case 2: link with label | ||
await newBlock(page) | ||
await page.type(':nth-match(textarea, 1)', 'Logseq') | ||
await page.press(':nth-match(textarea, 1)', selectAll) | ||
await page.press(':nth-match(textarea, 1)', hotKey) | ||
expect(await page.inputValue(':nth-match(textarea, 1)')).toBe('[Logseq]()') | ||
await page.type(':nth-match(textarea, 1)', 'https://logseq.com/') | ||
expect(await page.inputValue(':nth-match(textarea, 1)')).toBe('[Logseq](https://logseq.com/)') | ||
|
||
// Case 3: link with URL | ||
await newBlock(page) | ||
await page.type(':nth-match(textarea, 1)', 'https://logseq.com/') | ||
await page.press(':nth-match(textarea, 1)', selectAll) | ||
await page.press(':nth-match(textarea, 1)', hotKey) | ||
expect(await page.inputValue(':nth-match(textarea, 1)')).toBe('[](https://logseq.com/)') | ||
await page.type(':nth-match(textarea, 1)', 'Logseq') | ||
expect(await page.inputValue(':nth-match(textarea, 1)')).toBe('[Logseq](https://logseq.com/)') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters