add a few tests
This commit is contained in:
@@ -26,26 +26,20 @@ test('can create editor', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
test('set HTML, get HTML', () => {
|
test('set HTML, get HTML', () => {
|
||||||
const result = '<p>Lorem <strong>ipsum</strong> dolor sit amet.</p>'
|
const content = '<p>Lorem <strong>ipsum</strong> dolor sit amet.</p>'
|
||||||
|
|
||||||
const editor = new Editor({
|
const editor = new Editor({
|
||||||
content: result,
|
content,
|
||||||
extensions: [
|
extensions: [
|
||||||
new Bold(),
|
new Bold(),
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(editor.getHTML()).toEqual(result)
|
expect(editor.getHTML()).toEqual(content)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('set HTML, get JSON', () => {
|
test('set HTML, get JSON', () => {
|
||||||
const editor = new Editor({
|
const content = '<p>Lorem <strong>ipsum</strong> dolor sit amet.</p>'
|
||||||
content: '<p>Lorem <strong>ipsum</strong> dolor sit amet.</p>',
|
|
||||||
extensions: [
|
|
||||||
new Bold(),
|
|
||||||
],
|
|
||||||
})
|
|
||||||
|
|
||||||
const result = {
|
const result = {
|
||||||
type: 'doc',
|
type: 'doc',
|
||||||
content: [
|
content: [
|
||||||
@@ -74,11 +68,18 @@ test('set HTML, get JSON', () => {
|
|||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const editor = new Editor({
|
||||||
|
content,
|
||||||
|
extensions: [
|
||||||
|
new Bold(),
|
||||||
|
],
|
||||||
|
})
|
||||||
|
|
||||||
expect(editor.getJSON()).toEqual(result)
|
expect(editor.getJSON()).toEqual(result)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('set JSON, get JSON', () => {
|
test('set JSON, get JSON', () => {
|
||||||
const result = {
|
const content = {
|
||||||
type: 'doc',
|
type: 'doc',
|
||||||
content: [
|
content: [
|
||||||
{
|
{
|
||||||
@@ -107,13 +108,13 @@ test('set JSON, get JSON', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const editor = new Editor({
|
const editor = new Editor({
|
||||||
content: result,
|
content,
|
||||||
extensions: [
|
extensions: [
|
||||||
new Bold(),
|
new Bold(),
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(editor.getJSON()).toEqual(result)
|
expect(editor.getJSON()).toEqual(content)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('set JSON, get HTML', () => {
|
test('set JSON, get HTML', () => {
|
||||||
@@ -155,3 +156,46 @@ test('set JSON, get HTML', () => {
|
|||||||
|
|
||||||
expect(editor.getHTML()).toEqual(result)
|
expect(editor.getHTML()).toEqual(result)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('set content (HTML)', () => {
|
||||||
|
const editor = new Editor({
|
||||||
|
content: '<p>Foo</p>',
|
||||||
|
})
|
||||||
|
|
||||||
|
editor.setContent('<p>Bar</p>')
|
||||||
|
|
||||||
|
expect(editor.getHTML()).toEqual('<p>Bar</p>')
|
||||||
|
})
|
||||||
|
|
||||||
|
test('set content (JSON)', () => {
|
||||||
|
const editor = new Editor({
|
||||||
|
content: '<p>Foo</p>',
|
||||||
|
})
|
||||||
|
|
||||||
|
editor.setContent({
|
||||||
|
type: 'doc',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'paragraph',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'text',
|
||||||
|
text: 'Bar',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(editor.getHTML()).toEqual('<p>Bar</p>')
|
||||||
|
})
|
||||||
|
|
||||||
|
test('clear content', () => {
|
||||||
|
const editor = new Editor({
|
||||||
|
content: '<p>Foo</p>',
|
||||||
|
})
|
||||||
|
|
||||||
|
editor.clearContent()
|
||||||
|
|
||||||
|
expect(editor.getHTML()).toEqual('<p></p>')
|
||||||
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user