From 1bd26566d01cae03edc663ed42431aef5f5d7c57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=BA=9A=E7=90=AA?= Date: Tue, 26 Nov 2024 14:51:32 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E6=B5=8B=E8=AF=95=E4=B8=8E=E7=A4=BA?= =?UTF-8?q?=E4=BE=8B=E9=80=82=E9=85=8D=E5=B0=8F=E7=A8=8B=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../create-selector-query.test.js | 10 +- ...t-element-by-id-multiple-root-node.test.js | 6 +- .../get-element-by-id.test.js | 4 +- pages/API/upload-file/upload-file.test.js | 36 ++++---- pages/API/upload-file/upload-file.uvue | 10 +- pages/component/button/button.test.js | 2 +- pages/component/checkbox/checkbox.test.js | 92 ++++++++++++------- 7 files changed, 100 insertions(+), 60 deletions(-) diff --git a/pages/API/create-selector-query/create-selector-query.test.js b/pages/API/create-selector-query/create-selector-query.test.js index 719db99a..b13931be 100644 --- a/pages/API/create-selector-query/create-selector-query.test.js +++ b/pages/API/create-selector-query/create-selector-query.test.js @@ -76,7 +76,10 @@ describe('nodes-info', () => { // #endif it('test filelds', async () => { - if (process.env.uniTestPlatformInfo.startsWith('web')) { + if ( + process.env.uniTestPlatformInfo.startsWith('web') || + process.env.uniTestPlatformInfo.startsWith('mp') + ) { expect(true).toBe(true) } else { const pageData = await page.data() @@ -85,7 +88,10 @@ describe('nodes-info', () => { }) it('test node', async () => { - if (process.env.uniTestPlatformInfo.startsWith('web')) { + if ( + process.env.uniTestPlatformInfo.startsWith('web') || + process.env.uniTestPlatformInfo.startsWith('mp') + ) { expect(true).toBe(true) } else { const pageData = await page.data() diff --git a/pages/API/get-element-by-id/get-element-by-id-multiple-root-node.test.js b/pages/API/get-element-by-id/get-element-by-id-multiple-root-node.test.js index daa1d2cf..4e4f3928 100644 --- a/pages/API/get-element-by-id/get-element-by-id-multiple-root-node.test.js +++ b/pages/API/get-element-by-id/get-element-by-id-multiple-root-node.test.js @@ -11,8 +11,10 @@ describe("getElementByIdForMultipleRootNode", () => { const res = await page.callMethod("getElementByNotExistId"); expect(res).toBe(null); }); - it("changeStyle", async () => { - await page.callMethod("changePageHeadBackgroundColor"); + it("changeStyle", async () => { + if (!process.env.uniTestPlatformInfo.startsWith('mp')) { + await page.callMethod("changePageHeadBackgroundColor"); + } await page.callMethod("changeTextColor"); await page.callMethod("changeViewStyle"); await page.waitFor(500); diff --git a/pages/API/get-element-by-id/get-element-by-id.test.js b/pages/API/get-element-by-id/get-element-by-id.test.js index 74f2e9dd..9c5478ba 100644 --- a/pages/API/get-element-by-id/get-element-by-id.test.js +++ b/pages/API/get-element-by-id/get-element-by-id.test.js @@ -11,7 +11,9 @@ describe("getElementById", () => { expect(res).toBe(null); }); it("changeStyle", async () => { - await page.callMethod("changePageHeadBackgroundColor"); + if (!process.env.uniTestPlatformInfo.startsWith('mp')) { + await page.callMethod("changePageHeadBackgroundColor"); + } await page.callMethod("changeTextColor"); await page.callMethod("changeViewStyle"); await page.waitFor(500); diff --git a/pages/API/upload-file/upload-file.test.js b/pages/API/upload-file/upload-file.test.js index 9dad0a2f..524a117d 100644 --- a/pages/API/upload-file/upload-file.test.js +++ b/pages/API/upload-file/upload-file.test.js @@ -7,35 +7,39 @@ describe('ExtApi-UploadFile', () => { expect(1).toBe(1) }) return - } + } + + const isUploadProjectFileSupported = !process.env.uniTestPlatformInfo.startsWith('mp') let page; let res; beforeAll(async () => { page = await program.reLaunch(PAGE_PATH) - await page.waitFor(600); - await page.callMethod('jest_uploadFile'); - await page.waitFor(2000); - res = await page.data('jest_result'); }); beforeEach(async () => { await page.setData({ jest_result: false }) - }); - - it('Check ', async () => { - expect(res).toBe(true); - }); - - it('Check files upload', async () => { - res = await page.callMethod('jest_files_upload') - await page.waitFor(2000); - res = await page.data('jest_result'); - expect(res).toBe(true) }); + if(isUploadProjectFileSupported) { + it('Check ', async () => { + await page.waitFor(600); + await page.callMethod('jest_uploadFile'); + await page.waitFor(2000); + res = await page.data('jest_result'); + expect(res).toBe(true); + }); + + it('Check files upload', async () => { + res = await page.callMethod('jest_files_upload') + await page.waitFor(2000); + res = await page.data('jest_result'); + expect(res).toBe(true) + }); + } + it('Check uni.env', async () => { await page.callMethod('jest_uploadFile_with_uni_env'); await page.waitFor(2000); diff --git a/pages/API/upload-file/upload-file.uvue b/pages/API/upload-file/upload-file.uvue index 938c9a54..a7e4d7da 100644 --- a/pages/API/upload-file/upload-file.uvue +++ b/pages/API/upload-file/upload-file.uvue @@ -9,7 +9,8 @@ + 选择图片 - + + @@ -104,8 +105,11 @@ }, }) }, - jest_uploadFile_with_uni_env() { - const filePath = `${uni.env.CACHE_PATH}/download/uni-app.png` + jest_uploadFile_with_uni_env() { + /** + * 微信小程序只支持USER_DATA_PATH,且子目录未创建的情况下不能直接下载到子目录内 + */ + const filePath = `${uni.env.USER_DATA_PATH}/uni-app.png` uni.downloadFile({ url: "https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/uni-app.png", filePath: filePath, diff --git a/pages/component/button/button.test.js b/pages/component/button/button.test.js index ed8384a5..e6bcba6e 100644 --- a/pages/component/button/button.test.js +++ b/pages/component/button/button.test.js @@ -79,7 +79,7 @@ describe('Button.uvue', () => { }) it("checkUniButtonElement", async () => { - if (process.env.uniTestPlatformInfo.startsWith('web')) { + if (process.env.uniTestPlatformInfo.startsWith('mp')) { expect(1).toBe(1) return } diff --git a/pages/component/checkbox/checkbox.test.js b/pages/component/checkbox/checkbox.test.js index 7cfb5cc1..aa9c9cf9 100644 --- a/pages/component/checkbox/checkbox.test.js +++ b/pages/component/checkbox/checkbox.test.js @@ -14,18 +14,23 @@ beforeAll(async () => { }) describe('Checkbox.uvue', () => { + const isMP = process.env.uniTestPlatformInfo.startsWith('mp') it('change', async () => { expect(await getData('value')).toEqual([]) const cb1 = await page.$('.cb1') await cb1.tap() + await page.waitFor(100) expect(await getData('value')).toEqual(['cb', 'cb1']) const cb = await page.$('.cb') await cb.tap() + await page.waitFor(100) expect(await getData('value')).toEqual(['cb1']) const cb2 = await page.$('.cb2') await cb2.tap() + await page.waitFor(100) expect(await getData('value')).toEqual(['cb1']) await cb1.tap() + await page.waitFor(100) expect(await getData('value')).toEqual([]) }) it('length', async () => { @@ -42,6 +47,29 @@ describe('Checkbox.uvue', () => { }) expect(await cb.text()).toEqual('not selected') }) + if(isMP) { + it('disabled', async () => { + const cb = await page.$('.cb2') + const disabled1 = await cb.property('disabled') + expect(disabled1).toBe(true) + await page.setData({ + disabled: false, + }) + const disabled2 = await cb.property('disabled') + expect(disabled2).toBe(false) + }) + } else { + it('disabled', async () => { + const cb = await page.$('.cb2') + const disabled1 = await cb.attribute('disabled') + expect(disabled1).toBe(true + '') + await page.setData({ + disabled: false, + }) + const disabled2 = await cb.attribute('disabled') + expect(disabled2).toBe(false + '') + }) + } it('checked', async () => { const cb = await page.$('.cb') // TODO @@ -54,44 +82,38 @@ describe('Checkbox.uvue', () => { const newValue2 = await cb.property('checked') expect(newValue2.toString()).toBe(false + '') }) - it('color', async () => { - const cb = await page.$('.cb') - expect(await cb.attribute('color')).toBe('#007aff') - await page.setData({ - color: '#63acfc', + if(!isMP) { + it('color', async () => { + const cb = await page.$('.cb') + expect(await cb.attribute('color')).toBe('#007aff') + await page.setData({ + color: '#63acfc', + }) + expect(await cb.attribute('color')).toBe('#63acfc') }) - expect(await cb.attribute('color')).toBe('#63acfc') - }) - it('icon color', async () => { - const cb = await page.$('.cb') - expect(await cb.attribute('iconColor')).toBe('#211cfe') - await page.setData({ - iconColor: '#63acfc', + it('icon color', async () => { + const cb = await page.$('.cb') + expect(await cb.attribute('iconColor')).toBe('#211cfe') + await page.setData({ + iconColor: '#63acfc', + }) + expect(await cb.attribute('iconColor')).toBe('#63acfc') }) - expect(await cb.attribute('iconColor')).toBe('#63acfc') - }) - it('foreColor', async () => { - const cb = await page.$('.cb') - expect(await cb.attribute('foreColor')).toBe('#ff0000') - await page.setData({ - foreColor: '#63acfe', + it('foreColor', async () => { + const cb = await page.$('.cb') + expect(await cb.attribute('foreColor')).toBe('#ff0000') + await page.setData({ + foreColor: '#63acfe', + }) + expect(await cb.attribute('foreColor')).toBe('#63acfe') }) - expect(await cb.attribute('foreColor')).toBe('#63acfe') - }) - it('disabled', async () => { - const cb = await page.$('.cb2') - expect(await cb.attribute('disabled')).toBe(true + '') - await page.setData({ - disabled: false, + it('trigger UniCheckboxGroupChangeEvent', async () => { + const element = await page.$('.checkbox-item-0') + await element.tap() + await page.waitFor(1000) + const { testEvent } = await page.data() + expect(testEvent).toBe(true) }) - expect(await cb.attribute('disabled')).toBe(false + '') - }) - it('trigger UniCheckboxGroupChangeEvent', async () => { - const element = await page.$('.checkbox-item-0') - await element.tap() - await page.waitFor(1000) - const { testEvent } = await page.data() - expect(testEvent).toBe(true) - }) + } }) -- GitLab