Skip to content

Commit

Permalink
fix: e2e tests
Browse files Browse the repository at this point in the history
This PR moves the cursor to the end of the editor in `enterNextBlock`.
  • Loading branch information
tiensonqin committed Mar 23, 2023
1 parent cb2c1f1 commit 69bd4e9
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 16 deletions.
7 changes: 4 additions & 3 deletions e2e-tests/hotkey.spec.ts
@@ -1,8 +1,9 @@
import { expect } from '@playwright/test'
import { test } from './fixtures'
import { createRandomPage, newBlock, lastBlock, modKey, IsLinux } from './utils'
import { createRandomPage, enterNextBlock, lastBlock, modKey, IsLinux } from './utils'

test('open search dialog', async ({ page }) => {
await page.waitForTimeout(200)
await page.keyboard.press(modKey + '+k')

await page.waitForSelector('[placeholder="Search or create page"]')
Expand All @@ -25,7 +26,7 @@ test('insert link #3278', async ({ page }) => {
await page.fill('textarea >> nth=0', '[Logseq Website](https://logseq.com)')

// Case 2: link with label
await newBlock(page)
await enterNextBlock(page)
await page.type('textarea >> nth=0', 'Logseq')
await page.press('textarea >> nth=0', selectAll)
await page.press('textarea >> nth=0', hotKey)
Expand All @@ -34,7 +35,7 @@ test('insert link #3278', async ({ page }) => {
expect(await page.inputValue('textarea >> nth=0')).toBe('[Logseq](https://logseq.com/)')

// Case 3: link with URL
await newBlock(page)
await enterNextBlock(page)
await page.type('textarea >> nth=0', 'https://logseq.com/')
await page.press('textarea >> nth=0', selectAll)
await page.press('textarea >> nth=0', hotKey)
Expand Down
2 changes: 1 addition & 1 deletion e2e-tests/page-rename.spec.ts
@@ -1,6 +1,6 @@
import { expect, Page } from '@playwright/test'
import { test } from './fixtures'
import { IsMac, createPage, randomLowerString, newBlock, newInnerBlock, randomString, lastBlock } from './utils'
import { IsMac, createPage, randomLowerString, newInnerBlock, randomString, lastBlock } from './utils'

/***
* Test rename feature
Expand Down
2 changes: 1 addition & 1 deletion e2e-tests/page-search.spec.ts
@@ -1,7 +1,7 @@
import { expect, Page } from '@playwright/test'
import { test } from './fixtures'
import { Block } from './types'
import { modKey, createRandomPage, newBlock, newInnerBlock, randomString, lastBlock, enterNextBlock } from './utils'
import { modKey, createRandomPage, newInnerBlock, randomString, lastBlock, enterNextBlock } from './utils'
import { searchPage, closeSearchBox } from './util/search-modal'

/***
Expand Down
17 changes: 6 additions & 11 deletions e2e-tests/utils.ts
@@ -1,6 +1,7 @@
import { Page, Locator } from 'playwright'
import { expect, ConsoleMessage } from '@playwright/test'
import * as pathlib from 'path'
import { modKey } from './util/basic'

// TODO: The file should be a facade of utils in the /util folder
// No more additional functions should be added to this file
Expand Down Expand Up @@ -34,6 +35,9 @@ export async function lastBlock(page: Page): Promise<Locator> {
* @param page The Playwright Page object.
*/
export async function enterNextBlock(page: Page): Promise<Locator> {
// Move cursor to the end of the editor
await page.press('textarea >> nth=0', modKey + '+a') // select all
await page.press('textarea >> nth=0', 'ArrowRight')
let blockCount = await page.locator('.page-blocks-inner .ls-block').count()
await page.press('textarea >> nth=0', 'Enter')
await page.waitForTimeout(10)
Expand All @@ -53,15 +57,6 @@ export async function newInnerBlock(page: Page): Promise<Locator> {
return page.locator('textarea >> nth=0')
}

// Deprecated by block.enterNext
export async function newBlock(page: Page): Promise<Locator> {
let blockNumber = await page.locator('.page-blocks-inner .ls-block').count()
await lastBlock(page)
await page.press('textarea >> nth=0', 'Enter')
await page.waitForSelector(`.page-blocks-inner .ls-block >> nth=${blockNumber} >> textarea`, { state: 'visible' })
return page.locator('textarea >> nth=0')
}

export async function escapeToCodeEditor(page: Page): Promise<void> {
await page.press('.block-editor textarea', 'Escape')
await page.waitForSelector('.CodeMirror pre', { state: 'visible' })
Expand Down Expand Up @@ -173,8 +168,8 @@ export async function editFirstBlock(page: Page) {
/**
* Wait for a console message with a given prefix to appear, and return the full text of the message
* Or reject after a timeout
*
* @param page
*
* @param page
* @param prefix - the prefix to look for
* @param timeout - the timeout in ms
* @returns the full text of the console message
Expand Down

0 comments on commit 69bd4e9

Please sign in to comment.