2021-04-17 06:25:04 +08:00
|
|
|
/// <reference types="cypress" />
|
|
|
|
|
|
|
|
import { Extension } from '@tiptap/core/src/Extension'
|
|
|
|
|
|
|
|
describe('extension options', () => {
|
2021-04-18 03:25:04 +08:00
|
|
|
it('should set options', () => {
|
2021-04-17 06:25:04 +08:00
|
|
|
const extension = Extension.create({
|
|
|
|
defaultOptions: {
|
|
|
|
foo: 1,
|
|
|
|
bar: 1,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
expect(extension.options).to.deep.eq({
|
|
|
|
foo: 1,
|
|
|
|
bar: 1,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-18 03:25:04 +08:00
|
|
|
it('should pass through', () => {
|
|
|
|
const extension = Extension
|
|
|
|
.create({
|
|
|
|
defaultOptions: {
|
|
|
|
foo: 1,
|
|
|
|
bar: 1,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
.extend()
|
|
|
|
.configure()
|
|
|
|
|
|
|
|
expect(extension.options).to.deep.eq({
|
|
|
|
foo: 1,
|
|
|
|
bar: 1,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-17 06:25:04 +08:00
|
|
|
it('should be configurable', () => {
|
|
|
|
const extension = Extension
|
|
|
|
.create({
|
|
|
|
defaultOptions: {
|
|
|
|
foo: 1,
|
|
|
|
bar: 1,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
.configure({
|
|
|
|
bar: 2,
|
|
|
|
})
|
|
|
|
|
|
|
|
expect(extension.options).to.deep.eq({
|
|
|
|
foo: 1,
|
|
|
|
bar: 2,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-18 03:25:04 +08:00
|
|
|
it('should be extendable', () => {
|
|
|
|
const extension = Extension.create({
|
|
|
|
defaultOptions: {
|
|
|
|
foo: 1,
|
|
|
|
bar: 1,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
const newExtension = extension.extend({
|
|
|
|
defaultOptions: {
|
|
|
|
...extension.options,
|
|
|
|
baz: 1,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
expect(newExtension.options).to.deep.eq({
|
|
|
|
foo: 1,
|
|
|
|
bar: 1,
|
|
|
|
baz: 1,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should be overwritable', () => {
|
|
|
|
const extension = Extension
|
|
|
|
.create({
|
|
|
|
defaultOptions: {
|
|
|
|
foo: 1,
|
|
|
|
bar: 1,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
.extend({
|
|
|
|
defaultOptions: {
|
|
|
|
baz: 1,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
expect(extension.options).to.deep.eq({
|
|
|
|
baz: 1,
|
|
|
|
})
|
|
|
|
})
|
2021-04-19 05:14:33 +08:00
|
|
|
|
|
|
|
it('should configure nested objects', () => {
|
|
|
|
const extension = Extension
|
2021-04-19 05:25:25 +08:00
|
|
|
.create<{
|
|
|
|
foo: number[],
|
|
|
|
HTMLAttributes: Record<string, any>,
|
|
|
|
}>({
|
2021-04-19 05:14:33 +08:00
|
|
|
defaultOptions: {
|
|
|
|
foo: [1, 2, 3],
|
|
|
|
HTMLAttributes: {
|
|
|
|
class: 'foo',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
.configure({
|
|
|
|
foo: [1],
|
|
|
|
HTMLAttributes: {
|
|
|
|
id: 'bar',
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
expect(extension.options).to.deep.eq({
|
|
|
|
foo: [1],
|
|
|
|
HTMLAttributes: {
|
|
|
|
class: 'foo',
|
|
|
|
id: 'bar',
|
|
|
|
},
|
|
|
|
})
|
|
|
|
})
|
2021-04-17 06:25:04 +08:00
|
|
|
})
|