提交 65c59af0 编写于 作者: H hdx

feat(canvas): 增加 toBlob/toDataURL 测试

上级 f2559a38
let page
beforeAll(async () => {
page = await program.reLaunch('/pages/component/canvas/canvas')
await page.waitFor(2000)
})
describe('Canvas.uvue', () => {
it('toBlob', async () => {
if (process.env.uniTestPlatformInfo.toLowerCase().startsWith('web')) {
const {
testToBlobResult,
testToDataURLResult
} = await page.data()
expect(testToBlobResult).toBe(true)
expect(testToDataURLResult).toBe(true)
}
})
})
......@@ -33,6 +33,9 @@
canvasWidth: 0,
canvasHeight: 0,
image: null as Image | null,
// 仅测试
testToBlobResult: false,
testToDataURLResult: false
}
},
onReady() {
......@@ -41,6 +44,13 @@
hidpi(canvas);
this.canvasWidth = this.canvasContext!.canvas.width;
this.canvasHeight = this.canvasContext!.canvas.height;
// #ifdef WEB
canvas.toBlob((blob : Blob) => {
this.testToBlobResult = (blob.size > 0 && blob.type == 'image/jpeg')
}, 'image/jpeg', 0.95)
this.testToDataURLResult = canvas.toDataURL().startsWith('data:image/png;base64')
// #endif
},
methods: {
handleCanvasButton(name : string) {
......@@ -630,15 +640,14 @@
context.restore()
},
restore() {
const context = this.canvasContext!
;[3, 2, 1].forEach((item) => {
context.save()
context.beginPath()
context.scale(item, item)
context.rect(10, 10, 100, 100)
context.stroke()
context.restore()
const context = this.canvasContext!;
[3, 2, 1].forEach((item) => {
context.save()
context.beginPath()
context.scale(item, item)
context.rect(10, 10, 100, 100)
context.stroke()
context.restore()
})
},
drawImageLocal() {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册