mirror of
https://github.com/logseq/logseq.git
synced 2026-04-24 14:14:55 +00:00
chore: add tests
This commit is contained in:
committed by
Tienson Qin
parent
72277222d9
commit
e8817bcc41
@@ -2,7 +2,7 @@ import { expect } from '@playwright/test'
|
||||
import { test } from './fixtures'
|
||||
import { createRandomPage, editFirstBlock, newInnerBlock } from './utils'
|
||||
|
||||
test('set heading to 1 using', async ({ page }) => {
|
||||
test('set heading to 1', async ({ page }) => {
|
||||
await createRandomPage(page)
|
||||
|
||||
await page.type('textarea >> nth=0', 'foo')
|
||||
|
||||
51
e2e-tests/history.spec.ts
Normal file
51
e2e-tests/history.spec.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import { expect } from '@playwright/test'
|
||||
import { test } from './fixtures'
|
||||
import { createRandomPage, modKey, searchAndJumpToPage, renamePage, randomString } from './utils'
|
||||
|
||||
test('undo/redo on a page should work as expected', async ({ page, block }) => {
|
||||
const page1 = await createRandomPage(page)
|
||||
|
||||
await block.mustType('text 1')
|
||||
await page.waitForTimeout(500) // Wait for 500ms autosave period to expire
|
||||
await expect(page.locator('text="text 1"')).toHaveCount(1)
|
||||
|
||||
await page.keyboard.press(modKey + '+z')
|
||||
await page.waitForTimeout(100)
|
||||
await expect(page.locator('text="text 1"')).toHaveCount(0)
|
||||
|
||||
await page.keyboard.press(modKey + '+Shift+z')
|
||||
await page.waitForTimeout(100)
|
||||
await expect(page.locator('text="text 1"')).toHaveCount(1)
|
||||
})
|
||||
|
||||
test('should navigate to corresponding page on undo', async ({ page, block }) => {
|
||||
const page1 = await createRandomPage(page)
|
||||
|
||||
await block.mustType('text 1')
|
||||
await page.waitForTimeout(500) // Wait for 500ms autosave period to expire
|
||||
|
||||
const page2 = await createRandomPage(page)
|
||||
|
||||
await page.keyboard.press(modKey + '+z')
|
||||
await page.waitForTimeout(100)
|
||||
expect(await page.innerText('.page-title .title')).toBe(page1)
|
||||
|
||||
await page.keyboard.press(modKey + '+z')
|
||||
await page.waitForTimeout(100)
|
||||
await expect(page.locator('text="text 1"')).toHaveCount(0)
|
||||
})
|
||||
|
||||
|
||||
test('undo/redo of a renamed page should be preserved', async ({ page, block }) => {
|
||||
const page1 = await createRandomPage(page)
|
||||
|
||||
await block.mustType('text 1')
|
||||
await page.waitForTimeout(500) // Wait for 500ms autosave period to expire
|
||||
|
||||
await renamePage(page, randomString(10))
|
||||
|
||||
await page.keyboard.press(modKey + '+z')
|
||||
await page.waitForTimeout(100)
|
||||
|
||||
await expect(page.locator('text="text 1"')).toHaveCount(0)
|
||||
})
|
||||
@@ -1,20 +1,11 @@
|
||||
import { expect, Page } from '@playwright/test'
|
||||
import { test } from './fixtures'
|
||||
import { IsMac, createPage, randomLowerString, newInnerBlock, randomString, lastBlock } from './utils'
|
||||
import { createPage, randomLowerString, randomString, renamePage } from './utils'
|
||||
|
||||
/***
|
||||
* Test rename feature
|
||||
***/
|
||||
|
||||
async function rename_page(page: Page, new_name: string) {
|
||||
await page.click('.ls-page-title .page-title')
|
||||
await page.waitForSelector('input[type="text"]')
|
||||
await page.fill('input[type="text"]', '')
|
||||
await page.type('.title input', new_name)
|
||||
await page.keyboard.press('Enter')
|
||||
await page.click('.ui__confirm-modal button')
|
||||
}
|
||||
|
||||
async function page_rename_test(page: Page, original_page_name: string, new_page_name: string) {
|
||||
const rand = randomString(10)
|
||||
let original_name = original_page_name + rand
|
||||
@@ -23,7 +14,7 @@ async function page_rename_test(page: Page, original_page_name: string, new_page
|
||||
await createPage(page, original_name)
|
||||
|
||||
// Rename page in UI
|
||||
await rename_page(page, new_name)
|
||||
await renamePage(page, new_name)
|
||||
|
||||
expect(await page.innerText('.page-title .title')).toBe(new_name)
|
||||
|
||||
@@ -53,7 +44,7 @@ async function homepage_rename_test(page: Page, original_page_name: string, new_
|
||||
|
||||
expect(await page.locator('.home-nav span.flex-1').innerText()).toBe(original_name);
|
||||
|
||||
await rename_page(page, new_name)
|
||||
await renamePage(page, new_name)
|
||||
|
||||
expect(await page.locator('.home-nav span.flex-1').innerText()).toBe(new_name);
|
||||
|
||||
|
||||
15
e2e-tests/util/page.ts
Normal file
15
e2e-tests/util/page.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { Page } from '@playwright/test'
|
||||
|
||||
export async function activateNewPage(page: Page) {
|
||||
await page.click('.ls-block >> nth=0')
|
||||
await page.waitForTimeout(500)
|
||||
}
|
||||
|
||||
export async function renamePage(page: Page, new_name: string) {
|
||||
await page.click('.ls-page-title .page-title')
|
||||
await page.waitForSelector('input[type="text"]')
|
||||
await page.fill('input[type="text"]', '')
|
||||
await page.type('.title input', new_name)
|
||||
await page.keyboard.press('Enter')
|
||||
await page.click('.ui__confirm-modal button')
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import { modKey } from './util/basic'
|
||||
// Criteria: If the same selector is shared in multiple functions, they should be in the same file
|
||||
export * from './util/basic'
|
||||
export * from './util/search-modal'
|
||||
export * from './util/page'
|
||||
|
||||
/**
|
||||
* Locate the last block in the inner editor
|
||||
@@ -154,11 +155,6 @@ export async function loadLocalGraph(page: Page, path: string): Promise<void> {
|
||||
console.log('Graph loaded for ' + path)
|
||||
}
|
||||
|
||||
export async function activateNewPage(page: Page) {
|
||||
await page.click('.ls-block >> nth=0')
|
||||
await page.waitForTimeout(500)
|
||||
}
|
||||
|
||||
export async function editFirstBlock(page: Page) {
|
||||
await page.click('.ls-block .block-content >> nth=0')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user