Skip to content

Commit

Permalink
test: add more children tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cycleccc committed Aug 16, 2024
1 parent 0227cb7 commit b6628d5
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 16 deletions.
22 changes: 14 additions & 8 deletions packages/basic-modules/__tests__/header/parse-html.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,37 @@ describe('header - parse html', () => {
it('with children', () => {
const $h1 = $(`<h1></h1>`)
const children = [{ text: 'hello ' }, { text: 'world', bold: true }]
const image = [{ type: 'image', children: [{ text: '' }] }]
// match selector
expect($h1[0].matches(parseHeader1HtmlConf.selector)).toBeTruthy()

// parse html
let res = parseHeader1HtmlConf.parseElemHtml($h1[0], children, editor)
const res = parseHeader1HtmlConf.parseElemHtml($h1[0], children, editor)
expect(res).toEqual({
type: `header1`,
children: [{ text: 'hello ' }, { text: 'world', bold: true }],
})
res = parseHeader1HtmlConf.parseElemHtml($h1[0], image, editor)
expect(res).toEqual({
type: `header1`,
children: [{ type: 'image', children: [{ text: '' }] }],
})
})

it('without children', () => {
const $h1 = $(`<h1>hello world</h1>`)
const image = [{ type: 'image', children: [{ text: '' }] }]
const table = [{ type: 'table-cell', children: [{ text: 'hello world' }] }]

// match selector
expect($h1[0].matches(parseHeader1HtmlConf.selector)).toBeTruthy()

// parse html
const res = parseHeader1HtmlConf.parseElemHtml($h1[0], [], editor)
let res = parseHeader1HtmlConf.parseElemHtml($h1[0], [], editor)
expect(res).toEqual({
type: `header1`,
children: [{ text: 'hello world' }],
})
res = parseHeader1HtmlConf.parseElemHtml($h1[0], image, editor)
expect(res).toEqual({
type: `header1`,
children: [{ type: 'image', children: [{ text: '' }] }],
})
res = parseHeader1HtmlConf.parseElemHtml($h1[0], table, editor)
expect(res).toEqual({
type: `header1`,
children: [{ text: 'hello world' }],
Expand Down
22 changes: 14 additions & 8 deletions packages/basic-modules/__tests__/paragraph/parse-html.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,24 @@ describe('paragraph - parse html', () => {

it('without children', () => {
const $elem = $('<p>hello&nbsp;world</p>')
const image = [{ type: 'image', children: [{ text: '' }] }]
const table = [{ type: 'table-cell', children: [{ text: 'hello world' }] }]

// match selector
expect($elem[0].matches(parseParagraphHtmlConf.selector)).toBeTruthy()

// parse
const res = parseParagraphHtmlConf.parseElemHtml($elem[0], [], editor)
let res = parseParagraphHtmlConf.parseElemHtml($elem[0], [], editor)
expect(res).toEqual({
type: 'paragraph',
children: [{ text: 'hello world' }],
})
res = parseParagraphHtmlConf.parseElemHtml($elem[0], image, editor)
expect(res).toEqual({
type: 'paragraph',
children: [{ type: 'image', children: [{ text: '' }] }],
})
res = parseParagraphHtmlConf.parseElemHtml($elem[0], table, editor)
expect(res).toEqual({
type: 'paragraph',
children: [{ text: 'hello world' }],
Expand All @@ -27,18 +39,12 @@ describe('paragraph - parse html', () => {
it('with children', () => {
const $elem = $('<p></p>')
const children = [{ text: 'hello ' }, { text: 'world', bold: true }]
const image = [{ type: 'image', children: [{ text: '' }] }]

// parse
let res = parseParagraphHtmlConf.parseElemHtml($elem[0], children, editor)
const res = parseParagraphHtmlConf.parseElemHtml($elem[0], children, editor)
expect(res).toEqual({
type: 'paragraph',
children: [{ text: 'hello ' }, { text: 'world', bold: true }],
})
res = parseParagraphHtmlConf.parseElemHtml($elem[0], image, editor)
expect(res).toEqual({
type: 'paragraph',
children: [{ type: 'image', children: [{ text: '' }] }],
})
})
})
7 changes: 7 additions & 0 deletions packages/basic-modules/__tests__/todo/parse-html.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ describe('todo - parse html', () => {
const $todo = $('<div data-w-e-type="todo"><input type="checkbox" disabled></div>')
const children = [{ text: 'hello ' }, { text: 'world', bold: true }]
const image = [{ type: 'image', children: [{ text: '' }] }]
const table = [{ type: 'table-cell', children: [{ text: 'hello world' }] }]

// match selector
expect($todo[0].matches(parseHtmlConf.selector)).toBeTruthy()
Expand All @@ -46,5 +47,11 @@ describe('todo - parse html', () => {
checked: false,
children: [{ type: 'image', children: [{ text: '' }] }],
})
res = parseHtmlConf.parseElemHtml($todo[0], table, editor)
expect(res).toEqual({
type: 'todo',
checked: false,
children: [{ text: '' }],
})
})
})

0 comments on commit b6628d5

Please sign in to comment.