chore: upgrade cypress version
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
import Editor from '../../../src/editor'
|
||||
|
||||
describe('菜单-内容块', () => {
|
||||
const url = 'http://localhost:3000/canvas-editor/'
|
||||
|
||||
beforeEach(() => {
|
||||
cy.visit(url)
|
||||
|
||||
cy.get('canvas').first().as('canvas').should('have.length', 1)
|
||||
})
|
||||
|
||||
it('内容块', () => {
|
||||
cy.getEditor().then((editor: Editor) => {
|
||||
editor.command.executeSelectAll()
|
||||
|
||||
editor.command.executeBackspace()
|
||||
|
||||
cy.get('.menu-item__block').click()
|
||||
|
||||
cy.get('.dialog-option__item [name="width"]').type('500')
|
||||
|
||||
cy.get('.dialog-option__item [name="height"]').type('300')
|
||||
|
||||
cy.get('.dialog-option__item [name="value"]').type(url)
|
||||
|
||||
cy.get('.dialog-menu button')
|
||||
.eq(1)
|
||||
.click()
|
||||
.then(() => {
|
||||
const data = editor.command.getValue().data.main
|
||||
|
||||
expect(data[0].type).to.eq('block')
|
||||
|
||||
expect(data[0].block?.iframeBlock?.src).to.eq(url)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,33 @@
|
||||
import Editor, { ElementType } from '../../../src/editor'
|
||||
|
||||
describe('菜单-复选框', () => {
|
||||
beforeEach(() => {
|
||||
cy.visit('http://localhost:3000/canvas-editor/')
|
||||
|
||||
cy.get('canvas').first().as('canvas').should('have.length', 1)
|
||||
})
|
||||
|
||||
const type: ElementType = <ElementType>'checkbox'
|
||||
|
||||
it('代码块', () => {
|
||||
cy.getEditor().then((editor: Editor) => {
|
||||
editor.command.executeSelectAll()
|
||||
|
||||
editor.command.executeBackspace()
|
||||
|
||||
editor.command.executeInsertElementList([
|
||||
{
|
||||
type,
|
||||
value: '',
|
||||
checkbox: {
|
||||
value: true
|
||||
}
|
||||
}
|
||||
])
|
||||
|
||||
const data = editor.command.getValue().data.main[0]
|
||||
|
||||
expect(data.checkbox?.value).to.eq(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,34 @@
|
||||
import Editor from '../../../src/editor'
|
||||
|
||||
describe('菜单-代码块', () => {
|
||||
beforeEach(() => {
|
||||
cy.visit('http://localhost:3000/canvas-editor/')
|
||||
|
||||
cy.get('canvas').first().as('canvas').should('have.length', 1)
|
||||
})
|
||||
|
||||
const text = `console.log('canvas-editor')`
|
||||
|
||||
it('代码块', () => {
|
||||
cy.getEditor().then((editor: Editor) => {
|
||||
editor.command.executeSelectAll()
|
||||
|
||||
editor.command.executeBackspace()
|
||||
|
||||
cy.get('.menu-item__codeblock').click()
|
||||
|
||||
cy.get('.dialog-option [name="codeblock"]').type(text)
|
||||
|
||||
cy.get('.dialog-menu button')
|
||||
.eq(1)
|
||||
.click()
|
||||
.then(() => {
|
||||
const data = editor.command.getValue().data.main[2]
|
||||
|
||||
expect(data.value).to.eq('log')
|
||||
|
||||
expect(data.color).to.eq('#b9a40a')
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,28 @@
|
||||
import Editor from '../../../src/editor'
|
||||
|
||||
describe('菜单-日期选择器', () => {
|
||||
beforeEach(() => {
|
||||
cy.visit('http://localhost:3000/canvas-editor/')
|
||||
|
||||
cy.get('canvas').first().as('canvas').should('have.length', 1)
|
||||
})
|
||||
|
||||
it('LaTeX', () => {
|
||||
cy.getEditor().then((editor: Editor) => {
|
||||
editor.command.executeSelectAll()
|
||||
|
||||
editor.command.executeBackspace()
|
||||
|
||||
cy.get('.menu-item__date').click()
|
||||
|
||||
cy.get('.menu-item__date li')
|
||||
.first()
|
||||
.click()
|
||||
.then(() => {
|
||||
const data = editor.command.getValue().data.main
|
||||
|
||||
expect(data[0].type).to.eq('date')
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,40 @@
|
||||
import Editor from '../../../src/editor'
|
||||
|
||||
describe('菜单-清除格式', () => {
|
||||
beforeEach(() => {
|
||||
cy.visit('http://localhost:3000/canvas-editor/')
|
||||
|
||||
cy.get('canvas').first().as('canvas').should('have.length', 1)
|
||||
})
|
||||
|
||||
const text = 'canvas-editor'
|
||||
const textLength = text.length
|
||||
|
||||
it('清除格式', () => {
|
||||
cy.getEditor().then((editor: Editor) => {
|
||||
editor.command.executeSelectAll()
|
||||
|
||||
editor.command.executeBackspace()
|
||||
|
||||
editor.command.executeInsertElementList([
|
||||
{
|
||||
value: text,
|
||||
bold: true,
|
||||
italic: true
|
||||
}
|
||||
])
|
||||
|
||||
editor.command.executeSetRange(0, textLength)
|
||||
|
||||
cy.get('.menu-item__format')
|
||||
.click()
|
||||
.then(() => {
|
||||
const data = editor.command.getValue().data.main
|
||||
|
||||
expect(data[0].italic).to.eq(false)
|
||||
|
||||
expect(data[0].bold).to.eq(false)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,39 @@
|
||||
import Editor from '../../../src/editor'
|
||||
|
||||
describe('菜单-超链接', () => {
|
||||
beforeEach(() => {
|
||||
cy.visit('http://localhost:3000/canvas-editor/')
|
||||
|
||||
cy.get('canvas').first().as('canvas').should('have.length', 1)
|
||||
})
|
||||
|
||||
const text = 'canvas-editor'
|
||||
const url = 'https://hufe.club/canvas-editor'
|
||||
|
||||
it('超链接', () => {
|
||||
cy.getEditor().then((editor: Editor) => {
|
||||
editor.command.executeSelectAll()
|
||||
|
||||
editor.command.executeBackspace()
|
||||
|
||||
cy.get('.menu-item__hyperlink').click()
|
||||
|
||||
cy.get('.dialog-option__item [name="name"]').type(text)
|
||||
|
||||
cy.get('.dialog-option__item [name="url"]').type(url)
|
||||
|
||||
cy.get('.dialog-menu button')
|
||||
.eq(1)
|
||||
.click()
|
||||
.then(() => {
|
||||
const data = editor.command.getValue().data.main
|
||||
|
||||
expect(data[0].type).to.eq('hyperlink')
|
||||
|
||||
expect(data[0].url).to.eq(url)
|
||||
|
||||
expect(data[0]?.valueList?.[0].value).to.eq(text)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,25 @@
|
||||
import Editor from '../../../src/editor'
|
||||
|
||||
describe('菜单-图片', () => {
|
||||
beforeEach(() => {
|
||||
cy.visit('http://localhost:3000/canvas-editor/')
|
||||
|
||||
cy.get('canvas').first().as('canvas').should('have.length', 1)
|
||||
})
|
||||
|
||||
it('图片', () => {
|
||||
cy.getEditor().then((editor: Editor) => {
|
||||
editor.command.executeSelectAll()
|
||||
|
||||
editor.command.executeBackspace()
|
||||
|
||||
cy.get('#image').attachFile('test.png')
|
||||
|
||||
cy.wait(200).then(() => {
|
||||
const data = editor.command.getValue().data.main
|
||||
|
||||
expect(data[0].type).to.eq('image')
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,34 @@
|
||||
import Editor from '../../../src/editor'
|
||||
|
||||
describe('菜单-LaTeX', () => {
|
||||
beforeEach(() => {
|
||||
cy.visit('http://localhost:3000/canvas-editor/')
|
||||
|
||||
cy.get('canvas').first().as('canvas').should('have.length', 1)
|
||||
})
|
||||
|
||||
const text = 'canvas-editor'
|
||||
|
||||
it('LaTeX', () => {
|
||||
cy.getEditor().then((editor: Editor) => {
|
||||
editor.command.executeSelectAll()
|
||||
|
||||
editor.command.executeBackspace()
|
||||
|
||||
cy.get('.menu-item__latex').click()
|
||||
|
||||
cy.get('.dialog-option__item [name="value"]').type(text)
|
||||
|
||||
cy.get('.dialog-menu button')
|
||||
.eq(1)
|
||||
.click()
|
||||
.then(() => {
|
||||
const data = editor.command.getValue().data.main
|
||||
|
||||
expect(data[0].type).to.eq('latex')
|
||||
|
||||
expect(data[0].value).to.eq(text)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,21 @@
|
||||
import Editor from '../../../src/editor'
|
||||
|
||||
describe('菜单-分页符', () => {
|
||||
beforeEach(() => {
|
||||
cy.visit('http://localhost:3000/canvas-editor/')
|
||||
|
||||
cy.get('canvas').first().as('canvas').should('have.length', 1)
|
||||
})
|
||||
|
||||
it('分页符', () => {
|
||||
cy.getEditor().then((editor: Editor) => {
|
||||
editor.command.executeSelectAll()
|
||||
|
||||
editor.command.executeBackspace()
|
||||
|
||||
cy.get('.menu-item__page-break').click().click()
|
||||
|
||||
cy.get('canvas').should('have.length', 2)
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,52 @@
|
||||
import Editor from '../../../src/editor'
|
||||
|
||||
describe('菜单-格式刷', () => {
|
||||
beforeEach(() => {
|
||||
cy.visit('http://localhost:3000/canvas-editor/')
|
||||
|
||||
cy.get('canvas').first().as('canvas').should('have.length', 1)
|
||||
})
|
||||
|
||||
const text = 'canvas-editor'
|
||||
const textLength = text.length
|
||||
|
||||
it('格式刷', () => {
|
||||
cy.getEditor().then((editor: Editor) => {
|
||||
editor.command.executeSelectAll()
|
||||
|
||||
editor.command.executeBackspace()
|
||||
|
||||
editor.command.executeInsertElementList([
|
||||
{
|
||||
value: text,
|
||||
bold: true,
|
||||
italic: true
|
||||
}
|
||||
])
|
||||
|
||||
editor.command.executeInsertElementList([
|
||||
{
|
||||
value: text
|
||||
}
|
||||
])
|
||||
|
||||
editor.command.executeSetRange(0, textLength)
|
||||
|
||||
cy.get('.menu-item__painter')
|
||||
.click()
|
||||
.then(() => {
|
||||
editor.command.executeSetRange(textLength, 2 * textLength)
|
||||
|
||||
editor.command.executeApplyPainterStyle()
|
||||
|
||||
const data = editor.command.getValue().data.main
|
||||
|
||||
expect(data.length).to.eq(1)
|
||||
|
||||
expect(data[0].italic).to.eq(true)
|
||||
|
||||
expect(data[0].bold).to.eq(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,25 @@
|
||||
import Editor from '../../../src/editor'
|
||||
|
||||
describe('菜单-打印', () => {
|
||||
beforeEach(() => {
|
||||
cy.visit('http://localhost:3000/canvas-editor/')
|
||||
|
||||
cy.get('canvas').should('have.length', 2)
|
||||
})
|
||||
|
||||
it('打印', () => {
|
||||
cy.getEditor().then(async (editor: Editor) => {
|
||||
const imageList2 = await editor.command.getImage()
|
||||
expect(imageList2.length).to.eq(2)
|
||||
|
||||
editor.command.executeSelectAll()
|
||||
|
||||
editor.command.executeBackspace()
|
||||
|
||||
cy.wait(200).then(async () => {
|
||||
const imageList1 = await editor.command.getImage()
|
||||
expect(imageList1.length).to.eq(1)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,103 @@
|
||||
import Editor from '../../../src/editor'
|
||||
|
||||
describe('菜单-行处理', () => {
|
||||
beforeEach(() => {
|
||||
cy.visit('http://localhost:3000/canvas-editor/')
|
||||
|
||||
cy.get('canvas').first().as('canvas').should('have.length', 1)
|
||||
})
|
||||
|
||||
const text = 'canvas-editor'
|
||||
|
||||
it('左对齐', () => {
|
||||
cy.getEditor().then((editor: Editor) => {
|
||||
editor.command.executeSelectAll()
|
||||
|
||||
editor.command.executeBackspace()
|
||||
|
||||
editor.command.executeInsertElementList([
|
||||
{
|
||||
value: text
|
||||
}
|
||||
])
|
||||
|
||||
cy.get('.menu-item__left')
|
||||
.click()
|
||||
.then(() => {
|
||||
const data = editor.command.getValue().data.main
|
||||
|
||||
expect(data[0].rowFlex).to.eq('left')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('居中对齐', () => {
|
||||
cy.getEditor().then((editor: Editor) => {
|
||||
editor.command.executeSelectAll()
|
||||
|
||||
editor.command.executeBackspace()
|
||||
|
||||
editor.command.executeInsertElementList([
|
||||
{
|
||||
value: text
|
||||
}
|
||||
])
|
||||
|
||||
cy.get('.menu-item__center')
|
||||
.click()
|
||||
.then(() => {
|
||||
const data = editor.command.getValue().data.main
|
||||
|
||||
expect(data[0].rowFlex).to.eq('center')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('靠右对齐', () => {
|
||||
cy.getEditor().then((editor: Editor) => {
|
||||
editor.command.executeSelectAll()
|
||||
|
||||
editor.command.executeBackspace()
|
||||
|
||||
editor.command.executeInsertElementList([
|
||||
{
|
||||
value: text
|
||||
}
|
||||
])
|
||||
|
||||
cy.get('.menu-item__right')
|
||||
.click()
|
||||
.then(() => {
|
||||
const data = editor.command.getValue().data.main
|
||||
|
||||
expect(data[0].rowFlex).to.eq('right')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('行间距', () => {
|
||||
cy.getEditor().then((editor: Editor) => {
|
||||
editor.command.executeSelectAll()
|
||||
|
||||
editor.command.executeBackspace()
|
||||
|
||||
editor.command.executeInsertElementList([
|
||||
{
|
||||
value: text
|
||||
}
|
||||
])
|
||||
|
||||
cy.get('.menu-item__row-margin').as('rowMargin').click()
|
||||
|
||||
cy.get('@rowMargin')
|
||||
.find('li')
|
||||
.eq(1)
|
||||
.click()
|
||||
.then(() => {
|
||||
const data = editor.command.getValue().data.main
|
||||
|
||||
expect(data[0].rowMargin).to.eq(1.25)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,112 @@
|
||||
import Editor, { ElementType } from '../../../src/editor'
|
||||
|
||||
describe('菜单-搜索', () => {
|
||||
beforeEach(() => {
|
||||
cy.visit('http://localhost:3000/canvas-editor/')
|
||||
|
||||
cy.get('canvas').first().as('canvas').should('have.length', 1)
|
||||
})
|
||||
|
||||
const searchText = 'canvas-editor'
|
||||
const replaceText = 'replace'
|
||||
const type: ElementType = <ElementType>'table'
|
||||
|
||||
it('搜索', () => {
|
||||
cy.getEditor().then((editor: Editor) => {
|
||||
editor.command.executeSelectAll()
|
||||
|
||||
editor.command.executeBackspace()
|
||||
|
||||
editor.command.executeInsertElementList([
|
||||
{
|
||||
value: searchText
|
||||
},
|
||||
{
|
||||
value: '\n',
|
||||
type,
|
||||
trList: [
|
||||
{
|
||||
height: 42,
|
||||
tdList: [
|
||||
{
|
||||
colspan: 1,
|
||||
rowspan: 1,
|
||||
value: [
|
||||
{
|
||||
value: searchText
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
colspan: 1,
|
||||
rowspan: 1,
|
||||
value: []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
height: 42,
|
||||
tdList: [
|
||||
{
|
||||
colspan: 1,
|
||||
rowspan: 1,
|
||||
value: []
|
||||
},
|
||||
{
|
||||
colspan: 1,
|
||||
rowspan: 1,
|
||||
value: [
|
||||
{
|
||||
value: searchText
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
colgroup: [
|
||||
{
|
||||
width: 200
|
||||
},
|
||||
{
|
||||
width: 200
|
||||
}
|
||||
]
|
||||
}
|
||||
])
|
||||
|
||||
cy.get('.menu-item__search').click()
|
||||
|
||||
cy.get('.menu-item__search__collapse input').eq(0).type(searchText)
|
||||
|
||||
// 搜索导航
|
||||
cy.get('.menu-item__search__collapse .arrow-right').click()
|
||||
cy.get('.menu-item__search__collapse__search .search-result').should(
|
||||
'have.text',
|
||||
'1/3'
|
||||
)
|
||||
|
||||
cy.get('.menu-item__search__collapse__replace').as('replace')
|
||||
|
||||
cy.get('@replace').find('input').type(replaceText)
|
||||
|
||||
cy.get('@replace')
|
||||
.find('button')
|
||||
.click()
|
||||
.then(() => {
|
||||
const data = editor.command.getValue().data.main
|
||||
|
||||
// 普通文本
|
||||
expect(data[0].value).to.be.eq(replaceText)
|
||||
|
||||
// 表格内文本
|
||||
expect(data[1].trList![0].tdList[0].value[0].value).to.be.eq(
|
||||
replaceText
|
||||
)
|
||||
expect(data[1].trList![1].tdList[1].value[0].value).to.be.eq(
|
||||
replaceText
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,32 @@
|
||||
import Editor from '../../../src/editor'
|
||||
|
||||
describe('菜单-分割线', () => {
|
||||
beforeEach(() => {
|
||||
cy.visit('http://localhost:3000/canvas-editor/')
|
||||
|
||||
cy.get('canvas').first().as('canvas').should('have.length', 1)
|
||||
})
|
||||
|
||||
it('分割线', () => {
|
||||
cy.getEditor().then((editor: Editor) => {
|
||||
editor.command.executeSelectAll()
|
||||
|
||||
editor.command.executeBackspace()
|
||||
|
||||
cy.get('.menu-item__separator').click()
|
||||
|
||||
cy.get('.menu-item__separator li')
|
||||
.eq(1)
|
||||
.click()
|
||||
.then(() => {
|
||||
const data = editor.command.getValue().data.main
|
||||
|
||||
expect(data[0].type).to.eq('separator')
|
||||
|
||||
expect(data[0]?.dashArray?.[0]).to.eq(1)
|
||||
|
||||
expect(data[0]?.dashArray?.[1]).to.eq(1)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,25 @@
|
||||
import Editor from '../../../src/editor'
|
||||
|
||||
describe('菜单-表格', () => {
|
||||
beforeEach(() => {
|
||||
cy.visit('http://localhost:3000/canvas-editor/')
|
||||
|
||||
cy.get('canvas').first().as('canvas').should('have.length', 1)
|
||||
})
|
||||
|
||||
it('表格', () => {
|
||||
cy.getEditor().then((editor: Editor) => {
|
||||
editor.command.executeSelectAll()
|
||||
|
||||
editor.command.executeBackspace()
|
||||
|
||||
editor.command.executeInsertTable(8, 8)
|
||||
|
||||
const data = editor.command.getValue().data.main
|
||||
|
||||
expect(data[0].type).to.eq('table')
|
||||
|
||||
expect(data[0].trList?.length).to.eq(8)
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,304 @@
|
||||
import Editor from '../../../src/editor'
|
||||
|
||||
describe('菜单-文本处理', () => {
|
||||
beforeEach(() => {
|
||||
cy.visit('http://localhost:3000/canvas-editor/')
|
||||
|
||||
cy.get('canvas').first().as('canvas').should('have.length', 1)
|
||||
})
|
||||
|
||||
const text = 'canvas-editor'
|
||||
const textLength = text.length
|
||||
|
||||
it('字体', () => {
|
||||
cy.getEditor().then((editor: Editor) => {
|
||||
editor.command.executeSelectAll()
|
||||
|
||||
editor.command.executeBackspace()
|
||||
|
||||
editor.command.executeInsertElementList([
|
||||
{
|
||||
value: text
|
||||
}
|
||||
])
|
||||
|
||||
editor.command.executeSetRange(0, textLength)
|
||||
|
||||
cy.get('.menu-item__font').as('font').click()
|
||||
|
||||
cy.get('@font')
|
||||
.find('li')
|
||||
.eq(1)
|
||||
.click()
|
||||
.then(() => {
|
||||
const data = editor.command.getValue().data.main
|
||||
|
||||
expect(data[0].font).to.eq('宋体')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('字号设置', () => {
|
||||
cy.getEditor().then((editor: Editor) => {
|
||||
editor.command.executeSelectAll()
|
||||
|
||||
editor.command.executeBackspace()
|
||||
|
||||
editor.command.executeInsertElementList([
|
||||
{
|
||||
value: text
|
||||
}
|
||||
])
|
||||
|
||||
editor.command.executeSetRange(0, textLength)
|
||||
|
||||
cy.get('.menu-item__size').as('size').click()
|
||||
|
||||
cy.get('@size')
|
||||
.find('li')
|
||||
.eq(0)
|
||||
.click()
|
||||
.then(() => {
|
||||
const data = editor.command.getValue().data.main
|
||||
|
||||
expect(data[0].size).to.eq(56)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('字体增大', () => {
|
||||
cy.getEditor().then((editor: Editor) => {
|
||||
editor.command.executeSelectAll()
|
||||
|
||||
editor.command.executeBackspace()
|
||||
|
||||
editor.command.executeInsertElementList([
|
||||
{
|
||||
value: text
|
||||
}
|
||||
])
|
||||
|
||||
editor.command.executeSetRange(0, textLength)
|
||||
|
||||
cy.get('.menu-item__size-add')
|
||||
.click()
|
||||
.then(() => {
|
||||
const data = editor.command.getValue().data.main
|
||||
|
||||
expect(data[0].size).to.eq(18)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('字体减小', () => {
|
||||
cy.getEditor().then((editor: Editor) => {
|
||||
editor.command.executeSelectAll()
|
||||
|
||||
editor.command.executeBackspace()
|
||||
|
||||
editor.command.executeInsertElementList([
|
||||
{
|
||||
value: text
|
||||
}
|
||||
])
|
||||
|
||||
editor.command.executeSetRange(0, textLength)
|
||||
|
||||
cy.get('.menu-item__size-minus')
|
||||
.click()
|
||||
.then(() => {
|
||||
const data = editor.command.getValue().data.main
|
||||
|
||||
expect(data[0].size).to.eq(14)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('加粗', () => {
|
||||
cy.getEditor().then((editor: Editor) => {
|
||||
editor.command.executeSelectAll()
|
||||
|
||||
editor.command.executeBackspace()
|
||||
|
||||
editor.command.executeInsertElementList([
|
||||
{
|
||||
value: text
|
||||
}
|
||||
])
|
||||
|
||||
editor.command.executeSetRange(0, textLength)
|
||||
|
||||
cy.get('.menu-item__bold')
|
||||
.click()
|
||||
.then(() => {
|
||||
const data = editor.command.getValue().data.main
|
||||
|
||||
expect(data[0].bold).to.eq(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('斜体', () => {
|
||||
cy.getEditor().then((editor: Editor) => {
|
||||
editor.command.executeSelectAll()
|
||||
|
||||
editor.command.executeBackspace()
|
||||
|
||||
editor.command.executeInsertElementList([
|
||||
{
|
||||
value: text
|
||||
}
|
||||
])
|
||||
|
||||
editor.command.executeSetRange(0, textLength)
|
||||
|
||||
cy.get('.menu-item__italic')
|
||||
.click()
|
||||
.then(() => {
|
||||
const data = editor.command.getValue().data.main
|
||||
|
||||
expect(data[0].italic).to.eq(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('下划线', () => {
|
||||
cy.getEditor().then((editor: Editor) => {
|
||||
editor.command.executeSelectAll()
|
||||
|
||||
editor.command.executeBackspace()
|
||||
|
||||
editor.command.executeInsertElementList([
|
||||
{
|
||||
value: text
|
||||
}
|
||||
])
|
||||
|
||||
editor.command.executeSetRange(0, textLength)
|
||||
|
||||
cy.get('.menu-item__underline')
|
||||
.click()
|
||||
.then(() => {
|
||||
const data = editor.command.getValue().data.main
|
||||
|
||||
expect(data[0].underline).to.eq(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('删除线', () => {
|
||||
cy.getEditor().then((editor: Editor) => {
|
||||
editor.command.executeSelectAll()
|
||||
|
||||
editor.command.executeBackspace()
|
||||
|
||||
editor.command.executeInsertElementList([
|
||||
{
|
||||
value: text
|
||||
}
|
||||
])
|
||||
|
||||
editor.command.executeSetRange(0, textLength)
|
||||
|
||||
cy.get('.menu-item__strikeout')
|
||||
.click()
|
||||
.then(() => {
|
||||
const data = editor.command.getValue().data.main
|
||||
|
||||
expect(data[0].strikeout).to.eq(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('上标', () => {
|
||||
cy.getEditor().then((editor: Editor) => {
|
||||
editor.command.executeSelectAll()
|
||||
|
||||
editor.command.executeBackspace()
|
||||
|
||||
editor.command.executeInsertElementList([
|
||||
{
|
||||
value: text
|
||||
}
|
||||
])
|
||||
|
||||
editor.command.executeSetRange(0, textLength)
|
||||
|
||||
cy.get('.menu-item__superscript')
|
||||
.click()
|
||||
.then(() => {
|
||||
const data = editor.command.getValue().data.main
|
||||
|
||||
expect(data[0].type).to.eq('superscript')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('下标', () => {
|
||||
cy.getEditor().then((editor: Editor) => {
|
||||
editor.command.executeSelectAll()
|
||||
|
||||
editor.command.executeBackspace()
|
||||
|
||||
editor.command.executeInsertElementList([
|
||||
{
|
||||
value: text
|
||||
}
|
||||
])
|
||||
|
||||
editor.command.executeSetRange(0, textLength)
|
||||
|
||||
cy.get('.menu-item__subscript')
|
||||
.click()
|
||||
.then(() => {
|
||||
const data = editor.command.getValue().data.main
|
||||
|
||||
expect(data[0].type).to.eq('subscript')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('字体颜色', () => {
|
||||
cy.getEditor().then((editor: Editor) => {
|
||||
editor.command.executeSelectAll()
|
||||
|
||||
editor.command.executeBackspace()
|
||||
|
||||
editor.command.executeInsertElementList([
|
||||
{
|
||||
value: text
|
||||
}
|
||||
])
|
||||
|
||||
editor.command.executeSetRange(0, textLength)
|
||||
|
||||
editor.command.executeColor('red')
|
||||
|
||||
const data = editor.command.getValue().data.main
|
||||
|
||||
expect(data[0].color).to.eq('red')
|
||||
})
|
||||
})
|
||||
|
||||
it('高亮', () => {
|
||||
cy.getEditor().then((editor: Editor) => {
|
||||
editor.command.executeSelectAll()
|
||||
|
||||
editor.command.executeBackspace()
|
||||
|
||||
editor.command.executeInsertElementList([
|
||||
{
|
||||
value: text
|
||||
}
|
||||
])
|
||||
|
||||
editor.command.executeSetRange(0, textLength)
|
||||
|
||||
editor.command.executeHighlight('red')
|
||||
|
||||
const data = editor.command.getValue().data.main
|
||||
|
||||
expect(data[0].highlight).to.eq('red')
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,43 @@
|
||||
import Editor, { ElementType, TitleLevel } from '../../../src/editor'
|
||||
|
||||
describe('菜单-标题', () => {
|
||||
const url = 'http://localhost:3000/canvas-editor/'
|
||||
|
||||
beforeEach(() => {
|
||||
cy.visit(url)
|
||||
|
||||
cy.get('canvas').first().as('canvas').should('have.length', 1)
|
||||
})
|
||||
|
||||
const text = 'canvas-editor'
|
||||
const elementType = <ElementType>'title'
|
||||
const level = <TitleLevel>'first'
|
||||
|
||||
it('标题', () => {
|
||||
cy.getEditor().then((editor: Editor) => {
|
||||
editor.command.executeSelectAll()
|
||||
|
||||
editor.command.executeBackspace()
|
||||
|
||||
editor.command.executeInsertElementList([
|
||||
{
|
||||
value: text
|
||||
}
|
||||
])
|
||||
|
||||
cy.get('.menu-item__title').as('title').click()
|
||||
|
||||
cy.get('@title')
|
||||
.find('li')
|
||||
.eq(1)
|
||||
.click()
|
||||
.then(() => {
|
||||
const data = editor.command.getValue().data.main
|
||||
|
||||
expect(data[0].type).to.eq(elementType)
|
||||
|
||||
expect(data[0].level).to.eq(level)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,49 @@
|
||||
import Editor from '../../../src/editor'
|
||||
|
||||
describe('菜单-撤销&重做', () => {
|
||||
beforeEach(() => {
|
||||
cy.visit('http://localhost:3000/canvas-editor/')
|
||||
|
||||
cy.get('canvas').first().as('canvas').should('have.length', 1)
|
||||
})
|
||||
|
||||
const text = 'canvas-editor'
|
||||
|
||||
it('撤销', () => {
|
||||
cy.getEditor().then((editor: Editor) => {
|
||||
editor.command.executeSelectAll()
|
||||
|
||||
editor.command.executeBackspace()
|
||||
|
||||
cy.get('@canvas').type(`${text}1`)
|
||||
|
||||
cy.get('.menu-item__undo')
|
||||
.click()
|
||||
.then(() => {
|
||||
const data = editor.command.getValue().data.main
|
||||
|
||||
expect(data[0].value).to.eq(text)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('重做', () => {
|
||||
cy.getEditor().then((editor: Editor) => {
|
||||
editor.command.executeSelectAll()
|
||||
|
||||
editor.command.executeBackspace()
|
||||
|
||||
cy.get('@canvas').type(`${text}1`)
|
||||
|
||||
cy.get('.menu-item__undo').click()
|
||||
|
||||
cy.get('.menu-item__redo')
|
||||
.click()
|
||||
.then(() => {
|
||||
const data = editor.command.getValue().data.main
|
||||
|
||||
expect(data[0].value).to.eq(`${text}1`)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,60 @@
|
||||
import Editor from '../../../src/editor'
|
||||
|
||||
describe('菜单-水印', () => {
|
||||
beforeEach(() => {
|
||||
cy.visit('http://localhost:3000/canvas-editor/')
|
||||
|
||||
cy.get('canvas').first().as('canvas').should('have.length', 1)
|
||||
})
|
||||
|
||||
const text = 'canvas-editor'
|
||||
const size = 80
|
||||
|
||||
it('添加水印', () => {
|
||||
cy.getEditor().then((editor: Editor) => {
|
||||
cy.get('.menu-item__watermark').click()
|
||||
|
||||
cy.get('.menu-item__watermark li').eq(0).click()
|
||||
|
||||
cy.get('.dialog-option [name="data"]').type(text)
|
||||
|
||||
cy.get('.dialog-option [name="size"]').as('size')
|
||||
|
||||
cy.get('@size').clear()
|
||||
|
||||
cy.get('@size').type(`${size}`)
|
||||
|
||||
cy.get('.dialog-menu button')
|
||||
.eq(1)
|
||||
.click()
|
||||
.then(() => {
|
||||
const payload = editor.command.getValue()
|
||||
|
||||
const { watermark } = payload
|
||||
|
||||
expect(watermark?.data).to.eq(text)
|
||||
|
||||
expect(watermark?.size).to.eq(size)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('删除水印', () => {
|
||||
cy.getEditor().then((editor: Editor) => {
|
||||
cy.get('.menu-item__watermark').click()
|
||||
|
||||
cy.get('.menu-item__watermark li')
|
||||
.eq(1)
|
||||
.click()
|
||||
.then(() => {
|
||||
const payload = editor.command.getValue()
|
||||
|
||||
const { watermark } = payload
|
||||
|
||||
expect(watermark?.data).to.eq(undefined)
|
||||
|
||||
expect(watermark?.size).to.eq(undefined)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user