Skip to content

Commit

Permalink
fix(rich-text-editor): tiny-tiptap unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
zzzp9527 committed Nov 5, 2024
1 parent 3eff2fc commit b21aa42
Show file tree
Hide file tree
Showing 9 changed files with 136 additions and 0 deletions.
17 changes: 17 additions & 0 deletions examples/sites/demos/pc/app/rich-text-editor/basic-usage.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { test, expect } from '@playwright/test'

test('基本用法', async ({ page }) => {
page.on('pageerror', (exception) => expect(exception).toBeNull())
await page.goto('rich-text-editor#basic-usage')

const wrap = page.locator('#basic-usage')
const editor = wrap.locator('.tiny-rich-text-editor > .tiny-rich-text-editor__container .ProseMirror')

await expect(editor).toBeVisible()
await expect(editor).toHaveAttribute('contenteditable', 'true')

await editor.focus()
await expect(editor).toHaveClass('ProseMirror-focused')

await editor.fill('hello')
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { test, expect } from '@playwright/test'

test('气泡菜单', async ({ page }) => {
page.on('pageerror', (exception) => expect(exception).toBeNull())
await page.goto('rich-text-editor#bubble-menu-usage')

const wrap = page.locator('#bubble-menu-usage')
const editor = wrap.locator('.tiny-rich-text-editor > .tiny-rich-text-editor__container .ProseMirror')

await expect(editor).toBeVisible()

const content = editor.locator('p')
await content.selectText()
const bubbleMenu = editor.locator('div[data-tippy-root]')

await expect(bubbleMenu).toBeDefined()
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { test, expect } from '@playwright/test'

test('协同编辑', async ({ page }) => {
page.on('pageerror', (exception) => expect(exception).toBeNull())
await page.goto('rich-text-editor#collaboration-usage')

const wrap = page.locator('#collaboration-usage')
const editor = wrap.locator('.tiny-rich-text-editor > .tiny-rich-text-editor__container .ProseMirror')

await expect(editor).toBeVisible()

const contents = editor.locator('p')
const content = contents.nth(0)
content.selectText()
const selection = editor.locator('.ProseMirror-yjs-selection')
await expect(selection).toBeDefined()
})
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,7 @@ export default {
.editor-container {
display: flex;
}
.editor-container .tiny-rich-text-editor {
max-width: 50%;
}
</style>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { test, expect } from '@playwright/test'

test('自定义工具栏', async ({ page }) => {
page.on('pageerror', (exception) => expect(exception).toBeNull())
await page.goto('rich-text-editor#custom-bar-usage')

const wrap = page.locator('#custom-bar-usage')
const toolbarMenu = wrap.locator('.tiny-rich-text-editor > .tiny-toolbar-menu__view')
const menuItems = toolbarMenu.locator('.tiny-toolbar-menu__item')

await expect(toolbarMenu).toBeVisible()
await expect(menuItems).toHaveCount(2)
})
24 changes: 24 additions & 0 deletions examples/sites/demos/pc/app/rich-text-editor/event-usage.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { test, expect } from '@playwright/test'

test('事件', async ({ page }) => {
page.on('pageerror', (exception) => expect(exception).toBeNull())
await page.goto('rich-text-editor#event-usage')

const wrap = page.locator('#event-usage')
const editor = wrap.locator('.tiny-rich-text-editor > .tiny-rich-text-editor__container .ProseMirror')

await expect(editor).toBeVisible()

editor.focus()
editor.blur()

const logs: string[] = []
// 将消息填充到 logs
page.on('console', (msg) => logs.push(msg.text()))
await expect(logs).toContain('beforeCreate')
await expect(logs).toContain('transaction')
await expect(logs).toContain('create')

await expect(logs).toContain('focus')
await expect(logs).toContain('blur')
})
15 changes: 15 additions & 0 deletions examples/sites/demos/pc/app/rich-text-editor/options-usage.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { test, expect } from '@playwright/test'

test('自定义配置', async ({ page }) => {
page.on('pageerror', (exception) => expect(exception).toBeNull())
await page.goto('rich-text-editor#options-usage')

const wrap = page.locator('#options-usage')
const editor = wrap.locator('.tiny-rich-text-editor > .tiny-rich-text-editor__container .ProseMirror')

await expect(editor).toBeVisible()
await expect(editor).toHaveAttribute('contenteditable', 'true')

await expect(editor).toBeFocused()
await expect(editor).toHaveClass('ProseMirror-focused')
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { test, expect } from '@playwright/test'

test('placeholder', async ({ page }) => {
page.on('pageerror', (exception) => expect(exception).toBeNull())
await page.goto('rich-text-editor#placeholder-usage')

const wrap = page.locator('#placeholder-usage')
const editor = wrap.locator('.tiny-rich-text-editor > .tiny-rich-text-editor__container .ProseMirror')
const placeholder = editor.locator('.is-editor-empty.is-empty')

await expect(placeholder).toBeVisible()
await expect(placeholder).toHaveAttribute('data-placeholder', '自定义placeholder')
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { test, expect } from '@playwright/test'

test('斜杠菜单', async ({ page }) => {
page.on('pageerror', (exception) => expect(exception).toBeNull())
await page.goto('rich-text-editor#slash-menu-usage')

const wrap = page.locator('#slash-menu-usage')
const editor = wrap.locator('.tiny-rich-text-editor > .tiny-rich-text-editor__container .ProseMirror')

await expect(editor).toBeVisible()

await editor.focus()
await editor.fill('/')

const slashMenu = page.locator('.tiny-slash-menu__view')
await expect(slashMenu).toBeDefined()
})

0 comments on commit b21aa42

Please sign in to comment.