Skip to content

Commit

Permalink
test:optimize the method of get editor value
Browse files Browse the repository at this point in the history
  • Loading branch information
Hufe921 committed Feb 21, 2023
1 parent 63487d4 commit 708d578
Show file tree
Hide file tree
Showing 20 changed files with 287 additions and 301 deletions.
12 changes: 5 additions & 7 deletions cypress/integration/control/checkbox.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@ describe('控件-复选框', () => {

it('复选框', () => {
cy.getEditor().then((editor: Editor) => {
editor.listener.saved = function (payload) {
const data = payload.data[0]

expect(data.control!.code).to.be.eq('98175')
}

editor.command.executeSelectAll()

editor.command.executeBackspace()
Expand All @@ -40,7 +34,11 @@ describe('控件-复选框', () => {
}
}])

cy.get('@canvas').type('{ctrl}s')
const payload = editor.command.getValue()

const data = payload.data[0]

expect(data.control!.code).to.be.eq('98175')
})
})

Expand Down
21 changes: 11 additions & 10 deletions cypress/integration/control/select.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,6 @@ describe('控件-列举型', () => {

it('列举型', () => {
cy.getEditor().then((editor: Editor) => {
editor.listener.saved = function (payload) {
const data = payload.data[0]

expect(data.control!.value![0].value).to.be.eq(text)

expect(data.control!.code).to.be.eq('98175')
}

editor.command.executeSelectAll()

editor.command.executeBackspace()
Expand All @@ -45,9 +37,18 @@ describe('控件-列举型', () => {

cy.get('@canvas').type(`{leftArrow}`)

cy.get('.ce-select-control-popup li').eq(0).click()
cy.get('.ce-select-control-popup li')
.eq(0)
.click()
.then(() => {
const payload = editor.command.getValue()

const data = payload.data[0]

expect(data.control!.value![0].value).to.be.eq(text)

cy.get('@canvas').type('{ctrl}s')
expect(data.control!.code).to.be.eq('98175')
})
})
})

Expand Down
16 changes: 8 additions & 8 deletions cypress/integration/control/text.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@ describe('控件-文本型', () => {

it('文本型', () => {
cy.getEditor().then((editor: Editor) => {
editor.listener.saved = function (payload) {
const data = payload.data[0]

expect(data.control!.value![0].value).to.be.eq(text)
}

editor.command.executeSelectAll()

editor.command.executeBackspace()
Expand All @@ -36,9 +30,15 @@ describe('控件-文本型', () => {

cy.get('@canvas').type(`{leftArrow}`)

cy.get('.ce-inputarea').type(text)
cy.get('.ce-inputarea')
.type(text)
.then(() => {
const payload = editor.command.getValue()

const data = payload.data[0]

cy.get('@canvas').type('{ctrl}s')
expect(data.control!.value![0].value).to.be.eq(text)
})
})
})

Expand Down
22 changes: 9 additions & 13 deletions cypress/integration/editor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ describe('基础功能', () => {

it('编辑保存', () => {
cy.getEditor().then((editor: Editor) => {
editor.listener.saved = function (payload) {
expect(payload.data[0].value).to.eq(text)
}

editor.command.executeSelectAll()

editor.command.executeBackspace()

cy.get('@canvas').type(text)
cy.get('@canvas')
.type(text)
.then(() => {
const payload = editor.command.getValue()

cy.get('@canvas').type(`{ctrl}s`)
expect(payload.data[0].value).to.eq(text)
})
})
})

Expand Down Expand Up @@ -51,20 +51,16 @@ describe('基础功能', () => {
})

it('字数统计', () => {
cy.getEditor().then((editor: Editor) => {
editor.listener.contentChange = async function () {
const wordCount = await editor.command.getWordCount()

expect(7).to.be.eq(wordCount)
}

cy.getEditor().then(async (editor: Editor) => {
editor.command.executeSelectAll()

editor.command.executeBackspace()

editor.command.executeInsertElementList([{
value: 'canvas-editor 2022 编辑器'
}])

cy.get('.word-count').contains('7')
})
})

Expand Down
21 changes: 11 additions & 10 deletions cypress/integration/menus/block.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@ describe('菜单-内容块', () => {

it('内容块', () => {
cy.getEditor().then((editor: Editor) => {
editor.listener.saved = function (payload) {
const data = payload.data

expect(data[0].type).to.eq('block')

expect(data[0].block?.iframeBlock?.src).to.eq(url)
}

editor.command.executeSelectAll()

editor.command.executeBackspace()
Expand All @@ -32,9 +24,18 @@ describe('菜单-内容块', () => {

cy.get('.dialog-option__item [name="value"]').type(url)

cy.get('.dialog-menu button').eq(1).click()
cy.get('.dialog-menu button')
.eq(1)
.click()
.then(() => {
const payload = editor.command.getValue()

const data = payload.data

expect(data[0].type).to.eq('block')

cy.get('@canvas').type('{ctrl}s')
expect(data[0].block?.iframeBlock?.src).to.eq(url)
})
})
})

Expand Down
12 changes: 5 additions & 7 deletions cypress/integration/menus/checkbox.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ describe('菜单-复选框', () => {

it('代码块', () => {
cy.getEditor().then((editor: Editor) => {
editor.listener.saved = function (payload) {
const data = payload.data[0]

expect(data.checkbox?.value).to.eq(true)
}

editor.command.executeSelectAll()

editor.command.executeBackspace()
Expand All @@ -30,7 +24,11 @@ describe('菜单-复选框', () => {
}
}])

cy.get('@canvas').type('{ctrl}s')
const payload = editor.command.getValue()

const data = payload.data[0]

expect(data.checkbox?.value).to.eq(true)
})
})

Expand Down
21 changes: 11 additions & 10 deletions cypress/integration/menus/codeblock.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@ describe('菜单-代码块', () => {

it('代码块', () => {
cy.getEditor().then((editor: Editor) => {
editor.listener.saved = function (payload) {
const data = payload.data[2]

expect(data.value).to.eq('log')

expect(data.color).to.eq('#b9a40a')
}

editor.command.executeSelectAll()

editor.command.executeBackspace()
Expand All @@ -28,9 +20,18 @@ describe('菜单-代码块', () => {

cy.get('.dialog-option [name="codeblock"]').type(text)

cy.get('.dialog-menu button').eq(1).click()
cy.get('.dialog-menu button')
.eq(1)
.click()
.then(() => {
const payload = editor.command.getValue()

const data = payload.data[2]

expect(data.value).to.eq('log')

cy.get('@canvas').type('{ctrl}s')
expect(data.color).to.eq('#b9a40a')
})
})
})

Expand Down
17 changes: 9 additions & 8 deletions cypress/integration/menus/date.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,22 @@ describe('菜单-日期选择器', () => {

it('LaTeX', () => {
cy.getEditor().then((editor: Editor) => {
editor.listener.saved = function (payload) {
const data = payload.data

expect(data[0].type).to.eq('date')
}

editor.command.executeSelectAll()

editor.command.executeBackspace()

cy.get('.menu-item__date').click()

cy.get('.menu-item__date li').first().click()
cy.get('.menu-item__date li')
.first()
.click()
.then(() => {
const payload = editor.command.getValue()

const data = payload.data

cy.get('@canvas').type('{ctrl}s')
expect(data[0].type).to.eq('date')
})
})
})

Expand Down
16 changes: 7 additions & 9 deletions cypress/integration/menus/format.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,6 @@ describe('菜单-清除格式', () => {

it('清除格式', () => {
cy.getEditor().then((editor: Editor) => {
editor.listener.saved = function (payload) {
const data = payload.data

expect(data[0].italic).to.eq(false)

expect(data[0].bold).to.eq(false)
}

editor.command.executeSelectAll()

editor.command.executeBackspace()
Expand All @@ -36,7 +28,13 @@ describe('菜单-清除格式', () => {
cy.get('.menu-item__format')
.click()
.then(() => {
cy.get('@canvas').type('{ctrl}s')
const payload = editor.command.getValue()

const data = payload.data

expect(data[0].italic).to.eq(false)

expect(data[0].bold).to.eq(false)
})
})
})
Expand Down
25 changes: 13 additions & 12 deletions cypress/integration/menus/hyperlink.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,6 @@ describe('菜单-超链接', () => {

it('超链接', () => {
cy.getEditor().then((editor: Editor) => {
editor.listener.saved = function (payload) {
const data = payload.data

expect(data[0].type).to.eq('hyperlink')

expect(data[0].url).to.eq(url)

expect(data[0]?.valueList?.[0].value).to.eq(text)
}

editor.command.executeSelectAll()

editor.command.executeBackspace()
Expand All @@ -33,9 +23,20 @@ describe('菜单-超链接', () => {

cy.get('.dialog-option__item [name="url"]').type(url)

cy.get('.dialog-menu button').eq(1).click()
cy.get('.dialog-menu button')
.eq(1)
.click()
.then(() => {
const payload = editor.command.getValue()

const data = payload.data

expect(data[0].type).to.eq('hyperlink')

expect(data[0].url).to.eq(url)

cy.get('@canvas').type('{ctrl}s')
expect(data[0]?.valueList?.[0].value).to.eq(text)
})
})
})

Expand Down
11 changes: 5 additions & 6 deletions cypress/integration/menus/image.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,17 @@ describe('菜单-图片', () => {

it('图片', () => {
cy.getEditor().then((editor: Editor) => {
editor.listener.saved = function (payload) {
const data = payload.data
expect(data[0].type).to.eq('image')
}

editor.command.executeSelectAll()

editor.command.executeBackspace()

cy.get('#image').attachFile('test.png')

cy.get('@canvas').type('{ctrl}s')
cy.wait(200).then(() => {
const payload = editor.command.getValue()
const data = payload.data
expect(data[0].type).to.eq('image')
})
})
})

Expand Down
21 changes: 11 additions & 10 deletions cypress/integration/menus/latex.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@ describe('菜单-LaTeX', () => {

it('LaTeX', () => {
cy.getEditor().then((editor: Editor) => {
editor.listener.saved = function (payload) {
const data = payload.data

expect(data[0].type).to.eq('latex')

expect(data[0].value).to.eq(text)
}

editor.command.executeSelectAll()

editor.command.executeBackspace()
Expand All @@ -28,9 +20,18 @@ describe('菜单-LaTeX', () => {

cy.get('.dialog-option__item [name="value"]').type(text)

cy.get('.dialog-menu button').eq(1).click()
cy.get('.dialog-menu button')
.eq(1)
.click()
.then(() => {
const payload = editor.command.getValue()

const data = payload.data

expect(data[0].type).to.eq('latex')

cy.get('@canvas').type('{ctrl}s')
expect(data[0].value).to.eq(text)
})
})
})

Expand Down
Loading

0 comments on commit 708d578

Please sign in to comment.