Skip to content

Commit

Permalink
test(e2e): title property change name tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cnrpman committed Apr 26, 2022
1 parent cf6de97 commit c1d6aba
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
27 changes: 26 additions & 1 deletion e2e-tests/page-rename.spec.ts
@@ -1,6 +1,6 @@
import { expect } from '@playwright/test'
import { test } from './fixtures'
import { IsMac, createPage, newBlock, newInnerBlock, randomString, lastBlock } from './utils'
import { IsMac, createPage, randomLowerString, newBlock, newInnerBlock, randomString, lastBlock } from './utils'

/***
* Test rename feature
Expand Down Expand Up @@ -36,3 +36,28 @@ test('page rename test', async ({ page }) => {
await page_rename_test(page, "abcd", "a.b.c.d")
await page_rename_test(page, "abcd", "a/b/c/d")
})

// TODO introduce more samples when #4722 is fixed
test('page title property test', async ({ page }) => {
// Edit Title Property and Double Enter (ETPDE)
// exit editing via insert new block
let rand = randomLowerString(10)
let original_name = "etpde old" + rand
let new_name = "etpde new" + rand
await createPage(page, original_name)
// add some spaces to test if it is trimmed
await page.type(':nth-match(textarea, 1)', 'title:: ' + new_name + " ")
await page.press(':nth-match(textarea, 1)', 'Enter') // DWIM property mode creates new line
await page.press(':nth-match(textarea, 1)', 'Enter')
expect(await page.innerText('.page-title .title')).toBe(new_name)

// Edit Title Property and Esc (ETPE)
// exit editing via moving out focus
rand = randomLowerString(10)
original_name = "etpe old " + rand
new_name = "etpe new " + rand
await createPage(page, original_name)
await page.type(':nth-match(textarea, 1)', 'title:: ' + new_name)
await page.press(':nth-match(textarea, 1)', 'Escape')
expect(await page.innerText('.page-title .title')).toBe(new_name)
})
12 changes: 12 additions & 0 deletions e2e-tests/utils.ts
Expand Up @@ -19,6 +19,18 @@ export function randomString(length: number) {
return result;
}

export function randomLowerString(length: number) {
const characters = 'abcdefghijklmnopqrstuvwxyz0123456789';

let result = '';
const charactersLength = characters.length;
for (let i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}

return result;
}

export async function createRandomPage(page: Page) {
const randomTitle = randomString(20)

Expand Down

0 comments on commit c1d6aba

Please sign in to comment.