From 108b3f0a6ad45da1e7eca3b652a1188f773cc183 Mon Sep 17 00:00:00 2001 From: Anne_LXM Date: Fri, 16 Aug 2024 15:37:58 +0800 Subject: [PATCH] =?UTF-8?q?test(editor.test.js):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/component/editor/editor.test.js | 17 ++++++++++++++++- pages/component/editor/editor.uvue | 24 +++++++++++++++++++----- 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/pages/component/editor/editor.test.js b/pages/component/editor/editor.test.js index cef1f326..ae7dc718 100644 --- a/pages/component/editor/editor.test.js +++ b/pages/component/editor/editor.test.js @@ -16,6 +16,14 @@ describe('editor.uvue', () => { await page.setData({autoTest:true}) }); + async function setBlur() { + const start = Date.now(); + await page.callMethod('blur') + await page.waitFor(async () => { + return await page.data('blurTest') === true || (Date.now() - start > 2000) + }) + } + it('editor-wrapper', async () => { expect(await editor.attribute("placeholder")).toBe("开始输入...") expect(await editor.attribute("read-only")).toBe("false") @@ -41,8 +49,9 @@ describe('editor.uvue', () => { }); it('editor-screenshot', async () => { - expect(await program.screenshot()).toSaveImageSnapshot(); + await setBlur() await page.waitFor(500); + expect(await program.screenshot()).toSaveImageSnapshot(); }) it('clear', async () => { @@ -61,7 +70,13 @@ describe('editor.uvue', () => { }) it('insertImage', async () => { + await page.waitFor(500) await page.callMethod('insertImage','https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/uni-app.png') + const start1 = Date.now(); + await page.waitFor(async () => { + return await page.data('insertImageTest') === true || (Date.now() - start1 > 2000) + }) + await setBlur() await page.waitFor(2000) expect(await program.screenshot()).toSaveImageSnapshot(); }) diff --git a/pages/component/editor/editor.uvue b/pages/component/editor/editor.uvue index 88edd341..c0524a47 100644 --- a/pages/component/editor/editor.uvue +++ b/pages/component/editor/editor.uvue @@ -75,9 +75,9 @@ show-img-resize @statuschange="onStatusChange" :read-only="readOnly" @ready="onEditorReady"> - - - + + + @@ -99,7 +99,9 @@ autoTest:false, undoTest:false, redoTest:false, - removeFormatTest:false + removeFormatTest:false, + insertImageTest:false, + blurTest:false } }, onLoad() { @@ -137,6 +139,17 @@ } }) }, + blur() { + this.editorCtx.blur({ + success: (res) => { + console.log('编辑器失焦:', res) + this.blurTest = true + }, + fail: (err) => { + console.log(err) + } + }) + }, getCon() { this.editorCtx.getContents({ success: (res) => { @@ -224,8 +237,9 @@ this.editorCtx.insertImage({ src:image, alt: '图像', - success: function() { + success: ()=> { console.log('insert image success') + this.insertImageTest = true } }) }, -- GitLab