From d94f04fec4a882585fcad9c2aaa1435b2d0348e5 Mon Sep 17 00:00:00 2001 From: Hufe921 Date: Wed, 6 Apr 2022 21:57:28 +0800 Subject: [PATCH] feat:add control test case --- cypress/integration/control/select.spec.ts | 54 ++++++++++++++++++++++ cypress/integration/control/text.spec.ts | 45 ++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 cypress/integration/control/select.spec.ts create mode 100644 cypress/integration/control/text.spec.ts diff --git a/cypress/integration/control/select.spec.ts b/cypress/integration/control/select.spec.ts new file mode 100644 index 0000000..0910363 --- /dev/null +++ b/cypress/integration/control/select.spec.ts @@ -0,0 +1,54 @@ +import Editor, { ControlType, ElementType } from '../../../src/editor' + +describe('控件-列举型', () => { + + beforeEach(() => { + cy.visit('http://localhost:3000/canvas-editor/') + + cy.get('canvas').first().as('canvas').should('have.length', 1) + }) + + const text = `有` + const elementType: ElementType = 'control' + const controlType: ControlType = 'select' + + 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() + + editor.command.executeInsertElementList([{ + type: elementType, + value: '', + control: { + type: controlType, + value: null, + placeholder: '列举型', + valueSets: [{ + value: '有', + code: '98175' + }, { + value: '无', + code: '98176' + }] + } + }]) + + cy.get('@canvas').type(`{leftArrow}`) + + cy.get('.select-control-popup li').eq(0).click() + + cy.get('@canvas').type('{ctrl}s') + }) + }) + +}) diff --git a/cypress/integration/control/text.spec.ts b/cypress/integration/control/text.spec.ts new file mode 100644 index 0000000..fb392f6 --- /dev/null +++ b/cypress/integration/control/text.spec.ts @@ -0,0 +1,45 @@ +import Editor, { ControlType, ElementType } 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 elementType: ElementType = 'control' + const controlType: ControlType = 'text' + + 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() + + editor.command.executeInsertElementList([{ + type: elementType, + value: '', + control: { + type: controlType, + value: null, + placeholder: '文本型' + } + }]) + + cy.get('@canvas').type(`{leftArrow}`) + + cy.get('.inputarea').type(text) + + cy.get('@canvas').type('{ctrl}s') + }) + }) + +})