提交 108b3f0a 编写于 作者: Anne_LXM's avatar Anne_LXM

test(editor.test.js): 优化测试例

上级 31f85185
...@@ -16,6 +16,14 @@ describe('editor.uvue', () => { ...@@ -16,6 +16,14 @@ describe('editor.uvue', () => {
await page.setData({autoTest:true}) 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 () => { it('editor-wrapper', async () => {
expect(await editor.attribute("placeholder")).toBe("开始输入...") expect(await editor.attribute("placeholder")).toBe("开始输入...")
expect(await editor.attribute("read-only")).toBe("false") expect(await editor.attribute("read-only")).toBe("false")
...@@ -41,8 +49,9 @@ describe('editor.uvue', () => { ...@@ -41,8 +49,9 @@ describe('editor.uvue', () => {
}); });
it('editor-screenshot', async () => { it('editor-screenshot', async () => {
expect(await program.screenshot()).toSaveImageSnapshot(); await setBlur()
await page.waitFor(500); await page.waitFor(500);
expect(await program.screenshot()).toSaveImageSnapshot();
}) })
it('clear', async () => { it('clear', async () => {
...@@ -61,7 +70,13 @@ describe('editor.uvue', () => { ...@@ -61,7 +70,13 @@ describe('editor.uvue', () => {
}) })
it('insertImage', async () => { it('insertImage', async () => {
await page.waitFor(500)
await page.callMethod('insertImage','https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/uni-app.png') 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) await page.waitFor(2000)
expect(await program.screenshot()).toSaveImageSnapshot(); expect(await program.screenshot()).toSaveImageSnapshot();
}) })
......
...@@ -75,9 +75,9 @@ ...@@ -75,9 +75,9 @@
show-img-resize @statuschange="onStatusChange" :read-only="readOnly" @ready="onEditorReady"> show-img-resize @statuschange="onStatusChange" :read-only="readOnly" @ready="onEditorReady">
</editor> </editor>
</view> </view>
<view> <view>
<button @tap="getCon">打印文本内容</button> <button @tap="getCon">打印文本内容</button>
</view> </view>
</view> </view>
</view> </view>
</view> </view>
...@@ -99,7 +99,9 @@ ...@@ -99,7 +99,9 @@
autoTest:false, autoTest:false,
undoTest:false, undoTest:false,
redoTest:false, redoTest:false,
removeFormatTest:false removeFormatTest:false,
insertImageTest:false,
blurTest:false
} }
}, },
onLoad() { onLoad() {
...@@ -137,6 +139,17 @@ ...@@ -137,6 +139,17 @@
} }
}) })
}, },
blur() {
this.editorCtx.blur({
success: (res) => {
console.log('编辑器失焦:', res)
this.blurTest = true
},
fail: (err) => {
console.log(err)
}
})
},
getCon() { getCon() {
this.editorCtx.getContents({ this.editorCtx.getContents({
success: (res) => { success: (res) => {
...@@ -224,8 +237,9 @@ ...@@ -224,8 +237,9 @@
this.editorCtx.insertImage({ this.editorCtx.insertImage({
src:image, src:image,
alt: '图像', alt: '图像',
success: function() { success: ()=> {
console.log('insert image success') console.log('insert image success')
this.insertImageTest = true
} }
}) })
}, },
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册