Skip to content

Commit

Permalink
chore: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sprocketc authored and tiensonqin committed Apr 12, 2023
1 parent 7227722 commit e8817bc
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 18 deletions.
2 changes: 1 addition & 1 deletion e2e-tests/headings.spec.ts
Expand Up @@ -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')
Expand Down
51 changes: 51 additions & 0 deletions e2e-tests/history.spec.ts
@@ -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)
})
15 changes: 3 additions & 12 deletions e2e-tests/page-rename.spec.ts
@@ -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
Expand All @@ -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)

Expand Down Expand Up @@ -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);

Expand Down
15 changes: 15 additions & 0 deletions e2e-tests/util/page.ts
@@ -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')
}
6 changes: 1 addition & 5 deletions e2e-tests/utils.ts
Expand Up @@ -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
Expand Down Expand Up @@ -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')
}
Expand Down

0 comments on commit e8817bc

Please sign in to comment.