diff --git a/.editorconfig b/.editorconfig index 1a3af920b098c1460143e5f5ef5174933e03cb54..59fdeac038dea1d594512f915d0c6a8ba400591a 100644 --- a/.editorconfig +++ b/.editorconfig @@ -2,7 +2,7 @@ root = true [*] charset = utf-8 -end_of_line = lf +end_of_line = auto indent_style = space indent_size = 2 trim_trailing_whitespace = true diff --git a/App.uvue b/App.uvue index 7d07afab16b0268105253c5373d4dbfef892798e..225b3e7cd07080b5acc36bad5f423a2bb72a170b 100644 --- a/App.uvue +++ b/App.uvue @@ -29,6 +29,7 @@ } as OnShowOptions }, onLaunch: function (res : OnLaunchOptions) { + this.globalData.launchOptions = res // 自动化测试 @@ -47,15 +48,28 @@ // } as PerformanceObserverOptions) // 统计上报 - 应用启动 - // uni.report({ - // name: 'uni-app-launch', - // options: res, - // success(res_data) { - // console.log(res_data); - // }, fail(err_data) { - // console.log(err_data); - // } - // }) + uni.report({ + name: 'uni-app-launch', + options: res, + success(res_data) { + console.log(res_data); + }, fail(err) { + console.log(err); + } + }) + // #ifdef APP + if (process.env.NODE_ENV !== 'development') { //真机运行可以注释此条件 + uni.getPrivacySetting({ + success(res1){ + if(res1.needAuthorization){ + uni.openDialogPage({ + url: '/pages/component/button/privacy', + }) + } + } + }) + } + // #endif }, onShow: function (res : OnShowOptions) { this.globalData.onShowOption = res @@ -73,14 +87,14 @@ console.log('App Show') // 统计上报 - 应用显示 - // uni.report({ - // name: 'uni-app-show', - // success(res_data) { - // console.log(res_data); - // }, fail(err_data) { - // console.log(err_data); - // } - // }) + uni.report({ + name: 'uni-app-show', + success(res_data) { + console.log(res_data); + }, fail(err) { + console.log(err); + } + }) }, onHide: function () { // 自动化测试 @@ -119,18 +133,18 @@ onExit() { console.log('App Exit') }, - // onError(err : any) { - // // 统计上报 - 应用发生错误 - // uni.report({ - // name: 'uni-app-error', - // options: err, - // success(res) { - // console.log(res); - // }, fail(err) { - // console.log(err); - // } - // }) - // }, + onError(err : any) { + // 统计上报 - 应用发生错误 + uni.report({ + name: 'uni-app-error', + options: err, + success(res) { + console.log(res); + }, fail(err) { + console.log(err); + } + }) + }, // #endif methods: { increasetLifeCycleNum() { @@ -182,10 +196,5 @@ .uni-top-window uni-tabbar .uni-tabbar { background-color: #fff !important; } - - .uni-app--showleftwindow .uni-page-head-btn { - display: none !important; - } - /* #endif */ diff --git a/changelog.md b/changelog.md index 51eefbede1b8b088599fb8be935b47f5f6a64d39..86bd1c81bd628582261bba7beecb7ef240a4a204 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,9 @@ +## 1.0.32 +* update 4.31.2024102414-alpha + +## 1.0.31 +* update 4.28.2024092105-alpha + ## 1.0.30 * update 4.27.2024091308-alpha diff --git a/components/boolean-data/boolean-data.vue b/components/boolean-data/boolean-data.vue index bf835cab8122ed72c75d72e31135298ec8b88d37..7b3440e02caa3f9ed77d64489afb9cc83dac4f86 100644 --- a/components/boolean-data/boolean-data.vue +++ b/components/boolean-data/boolean-data.vue @@ -6,6 +6,10 @@ type: String, default: '' }, + disabled: { + type: Boolean, + default: false + }, defaultValue: { type: Boolean, default: false @@ -32,7 +36,7 @@ diff --git a/main.uts b/main.uts index 932b57eae4d6e6c42833f4f6191d73b05fb5f14b..d7844ed0be2a9eab541216e08754098f7314f54e 100644 --- a/main.uts +++ b/main.uts @@ -1,26 +1,23 @@ -// 仅测试 console.log 时机问题 -import './test-main-console.uts' -import { uniStat } from '@/uni_modules/uni-stat/plugin.uts' - -import App from './App.uvue' +// 仅测试 console.log 时机问题 +import './test-main-console.uts' +import { uniStat } from '@/uni_modules/uni-stat/plugin.uts' +import App from './App.uvue' + +import { createSSRApp } from 'vue' + +// 统计配置 +const collectItems = { + uniStatPageLog: true +} + +const statOptions = { + debug: true, + collectItems: collectItems, +} -import { createSSRApp } from 'vue' - -// 统计配置 -const collectItems = { - uniStatPageLog: true -} - -const statOptions = { - debug: false, - collectItems: collectItems, -} - - export function createApp() { - const app = createSSRApp(App) - app.use(uniStat, statOptions) - + const app = createSSRApp(App) + app.use(uniStat, statOptions) // app.mixin({ // onReady() { // setTimeout(() => { diff --git a/manifest.json b/manifest.json index bacdc963887e135c2343d20f8ead950a87579977..4e439ee4c2f17c9479be6191a204899d8e4e1c7b 100644 --- a/manifest.json +++ b/manifest.json @@ -2,8 +2,8 @@ "name": "Hello uni-app x", "appid": "__UNI__HelloUniAppX", "description": "", - "versionName": "1.5", - "versionCode": 10500, + "versionName": "1.6", + "versionCode": 10600, "uni-app-x": {}, /* 快应用特有相关 */ "quickapp": {}, diff --git a/package.json b/package.json index 21bb6c1996bc61c22297a9a58f9873bbec2034a3..cc573431def7594e4f3cbaafcd36b771dcba5ea2 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "id": "hello-uniapp-x-alpha", "name": "hello-uniapp-x-alpha", "displayName": "hello-uniapp-x-alpha", - "version": "1.0.30", + "version": "1.0.32", "description": "演示 uni-app x 框架的组件、接口、模板", "scripts": { "check-commit": "node ./git-hooks/check-commit.cjs" diff --git a/pages.json b/pages.json index dbbd69713384ac94721133308cf1cac2bbefbbb2..fe4be91f43089f03f0d0a31fd5a1bcfbe12820a2 100644 --- a/pages.json +++ b/pages.json @@ -297,21 +297,21 @@ }, { "path": "pages/component/web-view/web-view", - "group": "0,8", + "group": "0,9", "style": { "navigationBarTitleText": "web-view" } }, { "path": "pages/component/web-view/web-view/web-view-local", - "group": "0,8", + "group": "0,9", "style": { "navigationBarTitleText": "本地网页" } }, { "path": "pages/component/unicloud-db/unicloud-db/contacts/list", - "group": "0,10", + "group": "0,11", "style": { "navigationBarTitleText": "联系人", "enablePullDownRefresh": true @@ -337,7 +337,7 @@ }, { "path": "pages/component/unicloud-db/unicloud-db/mixin-datacom/mixin-datacom", - "group": "0,10", + "group": "0,11", "style": { "navigationBarTitleText": "mixinDatacom" } @@ -370,12 +370,12 @@ "navigationBarTitleText": "Touch Events" } }, - { - "path": "pages/component/global-events/touch-events-bubbles", - "style": { - "navigationBarTitleText": "Touch Events bubbles" - } - }, + { + "path": "pages/component/global-events/touch-events-bubbles", + "style": { + "navigationBarTitleText": "Touch Events bubbles" + } + }, // #ifndef WEB { "path": "pages/component/nested-scroll-header/nested-scroll-header", @@ -428,7 +428,7 @@ } }, // #endif - // #ifdef WEB + // #ifdef WEB || APP { "path": "pages/component/map/map", "group": "0,6", @@ -489,6 +489,34 @@ "navigationBarTitleText": "涂鸦" } }, + // #ifndef WEB + { + "path": "pages/component/native-view/native-view", + "group": "0,2,4", + "style": { + "navigationBarTitleText": "native-view" + } + }, + // #endif + // #ifndef WEB + { + "path": "pages/component/ad/ad", + "group": "0,8", + "style": { + "navigationBarTitleText": "ad | 信息流广告", + "enablePullDownRefresh": false + } + }, + // #endif + // #ifndef WEB + { + "path": "pages/component/ad/list-view-ad", + "style": { + "navigationBarTitleText": "ad | 信息流广告", + "enablePullDownRefresh": false + } + }, + // #endif { "path": "pages/tabBar/API", "style": { @@ -567,14 +595,14 @@ }, { "path": "pages/API/set-navigation-bar-color/set-navigation-bar-color", - "group": "1,2,1", + "group": "1,2,2", "style": { "navigationBarTitleText": "setNavigationBarColor | 设置导航条颜色" } }, { "path": "pages/API/set-navigation-bar-title/set-navigation-bar-title", - "group": "1,2,2", + "group": "1,2,3", "style": { "navigationBarTitleText": "setNavigationBarTitle | 设置导航条标题" } @@ -606,7 +634,7 @@ }, { "path": "pages/API/pull-down-refresh/pull-down-refresh", - "group": "1,2,4", + "group": "1,2,5", "style": { "navigationBarTitleText": "pullDownRefresh | 页面下拉刷新", "enablePullDownRefresh": true @@ -899,7 +927,7 @@ }, { "path": "pages/API/page-scroll-to/page-scroll-to", - "group": "1,2,5", + "group": "1,2,6", "style": { "navigationBarTitleText": "pageScrollTo | 将页面滚动到指定位置" } @@ -939,6 +967,13 @@ "navigationBarTitleText": "getWindowInfo | 获取窗口信息" } }, + { + "path": "pages/API/get-window-info/window-area", + "style": { + "navigationBarTitleText": "window area", + "navigationStyle": "custom" + } + }, // #ifndef WEB { "path": "pages/API/element-draw/element-draw", @@ -1024,13 +1059,15 @@ "enablePullDownRefresh": false } }, - { - "path": "pages/API/virtual-payment/virtual-payment-uni-pay", - "style": { - "navigationBarTitleText": "苹果虚拟支付(uni-pay)", - "enablePullDownRefresh": false - } - }, + // #endif + // #ifdef APP-IOS + { + "path": "pages/API/virtual-payment/virtual-payment-uni-pay", + "style": { + "navigationBarTitleText": "苹果虚拟支付(uni-pay)", + "enablePullDownRefresh": false + } + }, // #endif { "path": "pages/API/request-payment/request-payment/order-detail", @@ -1146,8 +1183,14 @@ "navigationBarTitleText": "provider | 服务提供商" } }, + { + "path": "pages/API/privacy/privacy", + "group": "1,1,8", + "style": { + "navigationBarTitleText": "privacy | 隐私信息授权" + } + }, // #endif - // #ifndef WEB { "path": "pages/API/uni-push/uni-push", "group": "1,15,0", @@ -1155,6 +1198,40 @@ "navigationBarTitleText": "推送" } }, + { + "path": "pages/API/dialog-page/dialog-page", + "group": "1,2,1", + "style": { + "navigationBarTitleText": "dialogPage | 弹框页面" + } + }, + { + "path": "pages/API/dialog-page/next-page", + "style": { + "navigationBarTitleText": "dialogNextPage" + } + }, + { + "path": "pages/API/dialog-page/dialog-1", + "style": { + "navigationBarTitleText": "dialogPage1" + } + }, + { + "path": "pages/API/dialog-page/dialog-2", + "style": { + "navigationBarTitleText": "dialogPage1" + } + }, + // #ifndef WEB + { + "path": "pages/API/create-interstitial-ad/create-interstitial-ad", + "group": "1,13,1", + "style": { + "navigationBarTitleText": "createInterstitialAd | 插屏广告", + "enablePullDownRefresh": false + } + }, // #endif { "path": "pages/tabBar/CSS", @@ -1254,6 +1331,13 @@ "navigationBarTitleText": "border动态修改" } }, + { + "path": "pages/CSS/border/border-update", + "group": "2,13", + "style": { + "navigationBarTitleText": "border更新样式" + } + }, { "path": "pages/CSS/box-shadow/box-shadow", "group": "2,15", @@ -1782,15 +1866,37 @@ "navigationBarTitleText": "", "backgroundColorContent": "#fffae8" } + }, + // #ifdef APP-IOS + { + "path" : "pages/API/event-bus/uts-event-bus", + "style" : + { + "navigationBarTitleText" : "" + } + }, + // #endif + // #ifdef APP + { + "path": "pages/component/button/privacy", + "style": { + "navigationBarTitleText": "" + } } + // #endif ], "globalStyle": { + // #ifdef APP-ANDROID + "hideStatusBar": false, + "hideBottomNavigationIndicator": false, + // #endif "pageOrientation": "portrait", "navigationBarTitleText": "Hello uniapp x", "navigationBarTextStyle": "@navigationBarTextStyle", "navigationBarBackgroundColor": "@navigationBarBackgroundColor", "backgroundColorContent": "@backgroundColorContent", - "backgroundColor": "@backgroundColor" + "backgroundColor": "@backgroundColor", + "backgroundTextStyle": "@backgroundTextStyle" }, "tabBar": { "color": "@tabBarColor", @@ -1932,6 +2038,10 @@ { "id": "component.basic-content.progress", "name": "progress" + }, + { + "id": "component.basic-content.native-view", + "name": "native-view" } ] }, @@ -2021,6 +2131,10 @@ "id": "component.canvas", "name": "画布" }, + { + "id": "component.ad", + "name": "广告" + }, { "id": "component.web-view", "name": "网页" @@ -2092,7 +2206,12 @@ { "id": "api.base.provider", "name": "provider" - } + }, + null, + { + "id": "api.base.privacy", + "name": "privacy" + } ] }, { @@ -2103,6 +2222,10 @@ "id": "api.page.navigator", "name": "navigator" }, + { + "id": "api.page.dialogPage", + "name": "dialogPage" + }, { "id": "api.page.setNavigationBarColor", "name": "setNavigationBarColor" @@ -2355,6 +2478,10 @@ { "id": "api.ad.createRewardedVideoAd", "name": "createRewardedVideoAd" + }, + { + "id": "api.ad.createInterstitialAd", + "name": "createInterstitialAd" } ] }, diff --git a/pages/API/animation-frame/animation-frame.uvue b/pages/API/animation-frame/animation-frame.uvue index 2dbe25e976068a22a7b3a1731c8b392ff064cf82..8c3d67c08729912fc87c4df01479a1afa6b0c36d 100644 --- a/pages/API/animation-frame/animation-frame.uvue +++ b/pages/API/animation-frame/animation-frame.uvue @@ -3,8 +3,8 @@ - FPS: {{FPSString}} - FrameCount: {{testFrameCount}} + FPS: {{FPSString}} + FrameCount: {{testFrameCount}} 提示: 在当前测试例子中,每增加一次调用 requestAnimationFrame 帧率翻倍,cancelAnimationFrame 后恢复 @@ -14,7 +14,7 @@ data() { return { title: 'AnimationFrame', - taskId: 0, + taskId: 0, FPSString: '- / -ms', lastTime: 0, frameCount: 0, @@ -29,25 +29,25 @@ methods: { startRequestAnimationFrame() { this.taskId = requestAnimationFrame((timestamp : number) => { - this.updateFPS(timestamp) + this.updateFPS(timestamp) this.testFrameCount++ this.startRequestAnimationFrame() }) }, stopRequestAnimationFrame() { - cancelAnimationFrame(this.taskId) - this.lastTime = 0 - this.frameCount = 0 + cancelAnimationFrame(this.taskId) + this.lastTime = 0 + this.frameCount = 0 this.FPSString = '- / -ms' - }, - updateFPS(timestamp : number) { - this.frameCount++ - if (timestamp - this.lastTime >= 1000) { - const timeOfFrame = (1000 / this.frameCount) - this.FPSString = `${this.frameCount} / ${timeOfFrame.toFixed(3)}ms` - this.frameCount = 0 - this.lastTime = timestamp - } + }, + updateFPS(timestamp : number) { + this.frameCount++ + if (timestamp - this.lastTime >= 1000) { + const timeOfFrame = (1000 / this.frameCount) + this.FPSString = `${this.frameCount} / ${timeOfFrame.toFixed(3)}ms` + this.frameCount = 0 + this.lastTime = timestamp + } } } } @@ -60,11 +60,11 @@ .frame-count { margin-top: 15px; - } - - .tips { - font-size: 12px; - margin-top: 30px; - opacity: 0.7; } - + + .tips { + font-size: 12px; + margin-top: 30px; + opacity: 0.7; + } + diff --git a/pages/API/choose-image/choose-image.uvue b/pages/API/choose-image/choose-image.uvue index 0b208b1ea2d64053bc056ca770c987516b0c99d5..44ef1439db21fbe593a743706d507722da3b8fd6 100644 --- a/pages/API/choose-image/choose-image.uvue +++ b/pages/API/choose-image/choose-image.uvue @@ -1,294 +1,296 @@ - - - - - diff --git a/pages/API/choose-location/choose-location.uvue b/pages/API/choose-location/choose-location.uvue index abe629534e0518034f3724a775ce9a2e626fbd0b..ed983109f1e5dfdc038c07c8fb0a19ec44133956 100644 --- a/pages/API/choose-location/choose-location.uvue +++ b/pages/API/choose-location/choose-location.uvue @@ -26,7 +26,7 @@ - - - - diff --git a/pages/API/cloud-storage/cloud-storage.uvue b/pages/API/cloud-storage/cloud-storage.uvue index d6a3218713ed138c8c7c25fa9d8beb7ea060888b..2d813847fa8532df660b4cab767008831b4036bc 100644 --- a/pages/API/cloud-storage/cloud-storage.uvue +++ b/pages/API/cloud-storage/cloud-storage.uvue @@ -1,92 +1,92 @@ - - - - diff --git a/pages/API/compass/compass.uvue b/pages/API/compass/compass.uvue index 351c90d18cef3dc1806d2d175f9151d882947d11..048c2d0774c5463bf6baa3fac7e299425db86f86 100644 --- a/pages/API/compass/compass.uvue +++ b/pages/API/compass/compass.uvue @@ -1,86 +1,87 @@ - - - - diff --git a/pages/API/compress-image/compress-image.uvue b/pages/API/compress-image/compress-image.uvue index 07cf8278f101b74da3aecc083074b25eb82f5c53..cf1394ebf90d9e32a27754baa30f3f04f26e8cbe 100644 --- a/pages/API/compress-image/compress-image.uvue +++ b/pages/API/compress-image/compress-image.uvue @@ -50,8 +50,6 @@ quality: 80, compressedWidth: null as number | null, compressedHeight: null as number | null, - width: "auto", - height: "auto", rotate: 0, // 自动化测试 imageInfoForTest: null, @@ -75,8 +73,6 @@ quality: this.quality, compressedWidth: this.compressedWidth, compressedHeight: this.compressedHeight, - width: this.width, - height: this.height, rotate: this.rotate, success: (res) => { console.log("compressImage success", JSON.stringify(res)); @@ -137,12 +133,6 @@ onCompressedHeightConfirm(value : string) { this.compressedHeight = parseInt(value); }, - onWidthConfirm(value : string) { - this.width = value; - }, - onHeightConfirm(value : string) { - this.height = value; - }, onRotateConfirm(value : number) { this.rotate = value; }, diff --git a/pages/API/create-inner-audio-context/create-inner-audio-context.test.js b/pages/API/create-inner-audio-context/create-inner-audio-context.test.js index 81faabde91b08bc1789e4c652860d686590c0190..a5d737dad48a9646f00be46e488ca39359e6ead1 100644 --- a/pages/API/create-inner-audio-context/create-inner-audio-context.test.js +++ b/pages/API/create-inner-audio-context/create-inner-audio-context.test.js @@ -10,45 +10,42 @@ describe('inner-audio', () => { await page.waitFor('view'); }); - function getData(key = '') { - return new Promise(async (resolve, reject) => { - const data = await page.data() - resolve(key ? data[key] : data) - }) - } - it('onCanplay',async()=>{ await page.waitFor(1000) await page.waitFor(async()=>{ - return await getData('isCanplay') + return await page.data('isCanplay') }) - expect(await getData('buffered')).toBeGreaterThan(0) + expect(await page.data('buffered')).toBeGreaterThan(0) }) it('play-onPlay-onTimeUpdate', async () => { await page.callMethod('play') - await page.waitFor(3000); - expect(await getData('isPlaying')).toBeTruthy() - console.log("duration:",await getData('duration'),"currentTime:",await getData('currentTime')) - expect(await getData('duration')).toBeCloseTo(175.109, 0); - // console.log("isPaused",await getData('isPaused')) - // expect(await getData('currentTime')).toBeGreaterThan(0); - // expect(await getData('isPaused')).toBeFalsy(); + const waitTime = process.env.uniTestPlatformInfo.includes('chrome') ? 5000:3000 + await page.waitFor(waitTime) + expect(await page.data('isPlaying')).toBeTruthy() + console.log("duration:",await page.data('duration'),"currentTime:",await page.data('currentTime')) + expect(await page.data('duration')).toBeCloseTo(175.109, 0); + // console.log("isPaused",await page.data('isPaused')) + // expect(await page.data('currentTime')).toBeGreaterThan(0); + // expect(await page.data('isPaused')).toBeFalsy(); }); it('seek-onSeeking-onSeeked', async () => { await page.callMethod('onchange',20) - await page.waitFor(500); - expect(await getData('onSeekingTest')).toBeTruthy(); - // expect(await getData('onWaitingTest')).toBeTruthy(); - expect(await getData('onSeekedTest')).toBeTruthy(); + const waitTime = process.env.uniTestPlatformInfo.includes('chrome') ? 1500:500 + await page.waitFor(waitTime) + console.log("seek-onSeeking-onSeeked:",await page.data()) + expect(await page.data('onSeekingTest')).toBeTruthy(); + // expect(await page.data('onWaitingTest')).toBeTruthy(); + // expect(await page.data('onSeekedTest')).toBeTruthy(); + expect(await program.screenshot()).toSaveImageSnapshot(); }); it('pause-onPause', async () => { await page.callMethod('pause') await page.waitFor(500); - expect(await getData('isPlaying')).toBeFalsy() - // expect(await getData('isPaused')).toBeTruthy(); + expect(await page.data('isPlaying')).toBeFalsy() + // expect(await page.data('isPaused')).toBeTruthy(); }); it('stop-onStop', async () => { @@ -58,8 +55,8 @@ describe('inner-audio', () => { await page.callMethod('stop') await page.callMethod('stop') await page.waitFor(1000); - expect(await getData('isPlaying')).toBeFalsy() - // expect(await getData('isPaused')).toBeTruthy(); + expect(await page.data('isPlaying')).toBeFalsy() + // expect(await page.data('isPaused')).toBeTruthy(); }); it('onEnded', async () => { @@ -67,7 +64,7 @@ describe('inner-audio', () => { await page.waitFor(500); await page.callMethod('play') await page.waitFor(3000); - // expect(await getData('isPlayEnd')).toBeTruthy(); + // expect(await page.data('isPlayEnd')).toBeTruthy(); }); }); diff --git a/pages/API/create-inner-audio-context/create-inner-audio-context.uvue b/pages/API/create-inner-audio-context/create-inner-audio-context.uvue index 0a3c73a968cc1ffb2663ec2d86ecc104481b19ec..1217da8d69828bba218babb6b1130b6002a8efa2 100644 --- a/pages/API/create-inner-audio-context/create-inner-audio-context.uvue +++ b/pages/API/create-inner-audio-context/create-inner-audio-context.uvue @@ -58,9 +58,9 @@ _isChanging: false, _audioContext: null as InnerAudioContext | null, // 自动化测试 - onSeekingTest:false, - onSeekedTest:false, - onWaitingTest:false + onSeekingTest: false, + onSeekedTest: false, + onWaitingTest: false } }, computed: { @@ -129,7 +129,7 @@ } this._audioContext!.onPlay(() => { this.isPaused = false; - console.log('开始播放',this.isPaused); + console.log('开始播放', this.isPaused); }); this.onTimeUpdate() this.onWaiting() @@ -159,6 +159,7 @@ // console.log('onTimeUpdate:音频播放进度更新事件,currentTime',this._audioContext!.currentTime); if (this._isChanging === true) { return; } this.currentTime = this._audioContext!.currentTime || 0; + console.log('currentTime', this.currentTime); if (this.currentTime > this.buffered) { console.log('缓冲不足'); } @@ -208,7 +209,7 @@ console.log('音频停止事件'); }); this.isPlaying = false; - console.log('stop',this.isPaused); + console.log('stop', this.isPaused); } } } diff --git a/pages/API/create-inner-audio-context/inner-audio-format.uvue b/pages/API/create-inner-audio-context/inner-audio-format.uvue index 9eec12ab2d87765e5714e46acebbf83d37cd6014..85f1bd7845ff5e4c326f725511cfca53f00b3794 100644 --- a/pages/API/create-inner-audio-context/inner-audio-format.uvue +++ b/pages/API/create-inner-audio-context/inner-audio-format.uvue @@ -1,134 +1,137 @@ - - - - - diff --git a/pages/API/create-inner-audio-context/inner-audio-path.uvue b/pages/API/create-inner-audio-context/inner-audio-path.uvue index 3b9ad2ae460f1ed9f5aa75e8b974a8d932bba0a1..db4e20511a086485a2ba8efbcbe46fcb0a6ffb85 100644 --- a/pages/API/create-inner-audio-context/inner-audio-path.uvue +++ b/pages/API/create-inner-audio-context/inner-audio-path.uvue @@ -1,99 +1,101 @@ - - - - - diff --git a/pages/API/create-interstitial-ad/create-interstitial-ad.uvue b/pages/API/create-interstitial-ad/create-interstitial-ad.uvue new file mode 100644 index 0000000000000000000000000000000000000000..e0e1cbd7c999b44ba8e5e41d5c89ebac6e31a877 --- /dev/null +++ b/pages/API/create-interstitial-ad/create-interstitial-ad.uvue @@ -0,0 +1,62 @@ + + + + + diff --git a/pages/API/create-request-permission-listener/create-request-permission-listener.uvue b/pages/API/create-request-permission-listener/create-request-permission-listener.uvue index f192ff2cecd880a8674d52011951309179bb44dc..6afc9a2a8e8ce6ec5d58133bd3011e3383031c07 100644 --- a/pages/API/create-request-permission-listener/create-request-permission-listener.uvue +++ b/pages/API/create-request-permission-listener/create-request-permission-listener.uvue @@ -1,89 +1,90 @@ - - - - - diff --git a/pages/API/create-rewarded-video-ad/create-rewarded-video-ad.uvue b/pages/API/create-rewarded-video-ad/create-rewarded-video-ad.uvue index 120267f2d806daba6d4907e22f10d5e71b274615..0f768592da16f870a165b33bc9cff8b8d568eb93 100644 --- a/pages/API/create-rewarded-video-ad/create-rewarded-video-ad.uvue +++ b/pages/API/create-rewarded-video-ad/create-rewarded-video-ad.uvue @@ -1,67 +1,67 @@ - - - - - diff --git a/pages/API/create-selector-query/create-selector-query.uvue b/pages/API/create-selector-query/create-selector-query.uvue index 31c635206517f9840a0192255c0c0aa97d66bf9f..c0c2115fbbc7b76cf727917a4b8c84730e0b05c5 100644 --- a/pages/API/create-selector-query/create-selector-query.uvue +++ b/pages/API/create-selector-query/create-selector-query.uvue @@ -2,57 +2,57 @@ - - - - - - - - - - - - left: - {{nodeInfo.left}} - - - top: - {{nodeInfo.top}} - - - right: - {{nodeInfo.right}} - - - bottom: - {{nodeInfo.bottom}} - - - width: - {{nodeInfo.width}} - - - height: - {{nodeInfo.height}} + + + + + + + + + + + + left: + {{nodeInfo.left}} + + + top: + {{nodeInfo.top}} + + + right: + {{nodeInfo.right}} + + + bottom: + {{nodeInfo.bottom}} + + + width: + {{nodeInfo.width}} + + + height: + {{nodeInfo.height}} + + + 子组件多根节点 + + 子组件多根节点(仅测试,用于验证查询是否超出范围) + + + 测试.fields + {{fieldsResultContainNode}} + + + 测试.node + {{nodeResultContainNode}} + + - - 子组件多根节点 - - 子组件多根节点(仅测试,用于验证查询是否超出范围) - - - 测试.fields - {{fieldsResultContainNode}} - - - 测试.node - {{nodeResultContainNode}} - - - @@ -160,10 +160,10 @@ // test .fields testFields() { uni.createSelectorQuery().select('.rect1').fields({ - node: true + node: true } as NodeField, (ret) => { const isElement = (ret as NodeInfo).node instanceof UniElement - if(isElement){ + if (isElement) { this.fieldsResultContainNode = true } else { this.fieldsResultContainNode = false @@ -175,11 +175,11 @@ uni.createSelectorQuery().select('#canvas1').node((ret) => { const isElement = (ret as NodeInfo).node instanceof UniElement const isCanvasElement = ((ret as NodeInfo).node as UniCanvasElement).tagName == 'CANVAS' - if(isElement && isCanvasElement){ - this.nodeResultContainNode = true - } else { - this.nodeResultContainNode = false - } + if (isElement && isCanvasElement) { + this.nodeResultContainNode = true + } else { + this.nodeResultContainNode = false + } }).exec() }, } diff --git a/pages/API/create-selector-query/nodes-info-child.uvue b/pages/API/create-selector-query/nodes-info-child.uvue index fad48b47bd3b2de2f9bca03dc680486a4a552926..ebd7a4c12340ef8df05165987f8f134f50204b50 100755 --- a/pages/API/create-selector-query/nodes-info-child.uvue +++ b/pages/API/create-selector-query/nodes-info-child.uvue @@ -12,18 +12,18 @@ } }, mounted() { - uni.createSelectorQuery().in(this).select('.selector-query-child-view').boundingClientRect().exec((ret) => { - if (ret.length == 1) { - const nodeInfo = ret[0] as NodeInfo; - this.top = nodeInfo.top! + uni.createSelectorQuery().in(this).select('.selector-query-child-view').boundingClientRect().exec((ret) => { + if (ret.length == 1) { + const nodeInfo = ret[0] as NodeInfo; + this.top = nodeInfo.top! } }) } } - diff --git a/pages/API/create-selector-query/selector-query-child-multi.uvue b/pages/API/create-selector-query/selector-query-child-multi.uvue index f11b1e1d320bde91547ac766316c5506bfe32806..d618b55bc629fe6d10d95554340ba6b55f6f69be 100644 --- a/pages/API/create-selector-query/selector-query-child-multi.uvue +++ b/pages/API/create-selector-query/selector-query-child-multi.uvue @@ -17,25 +17,25 @@ return { text1: "", text2: "", - text3: "test-text-node", - viewCount: 0, - selectCount: 0, + text3: "test-text-node", + viewCount: 0, + selectCount: 0, selectAllCount: 0, show: false } }, mounted() { uni.createSelectorQuery().in(this).select('.selector-query-view').boundingClientRect().exec((ret) => { - this.text1 = JSON.stringify(ret, null, 2) - if (ret.length == 1) { - this.selectCount = ret.length + this.text1 = JSON.stringify(ret, null, 2) + if (ret.length == 1) { + this.selectCount = ret.length + } + }) + uni.createSelectorQuery().in(this).selectAll('.selector-query-view').boundingClientRect().exec((ret) => { + this.text2 = JSON.stringify(ret, null, 2) + if (ret.length == 1) { + this.selectAllCount = (ret[0] as NodeInfo[]).length } - }) - uni.createSelectorQuery().in(this).selectAll('.selector-query-view').boundingClientRect().exec((ret) => { - this.text2 = JSON.stringify(ret, null, 2) - if (ret.length == 1) { - this.selectAllCount = (ret[0] as NodeInfo[]).length - } }) } } diff --git a/pages/API/dialog-page/dialog-1.uvue b/pages/API/dialog-page/dialog-1.uvue new file mode 100644 index 0000000000000000000000000000000000000000..8f7dccee7551039d03093fc8cf69c3dbd1e676cd --- /dev/null +++ b/pages/API/dialog-page/dialog-1.uvue @@ -0,0 +1,166 @@ + + + + + diff --git a/pages/API/dialog-page/dialog-2.uvue b/pages/API/dialog-page/dialog-2.uvue new file mode 100644 index 0000000000000000000000000000000000000000..bf12ae542be32dc573c71df34b1b1e2f8626bc45 --- /dev/null +++ b/pages/API/dialog-page/dialog-2.uvue @@ -0,0 +1,141 @@ + + + + + diff --git a/pages/API/dialog-page/dialog-page.test.js b/pages/API/dialog-page/dialog-page.test.js new file mode 100644 index 0000000000000000000000000000000000000000..7f8935d6bdce6f1e2d0ea8143d4b2b257699acb2 --- /dev/null +++ b/pages/API/dialog-page/dialog-page.test.js @@ -0,0 +1,288 @@ +jest.setTimeout(20000) + +const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase() +const isWeb = platformInfo.startsWith('web') +const FIRST_PAGE_PATH = '/pages/API/dialog-page/dialog-page' +const NEXT_PAGE_PATH = '/pages/API/dialog-page/next-page' + +describe('dialog page', () => { + if (process.env.UNI_AUTOMATOR_APP_WEBVIEW == 'true') { + it('skip app-webview', () => { + expect(1).toBe(1) + }) + return + } + + let page; + let initLifeCycleNum; + let lifecycleNum; + beforeAll(async () => { + page = await program.reLaunch(FIRST_PAGE_PATH) + await page.waitFor('view'); + initLifeCycleNum = await page.callMethod('getLifeCycleNum'); + await page.callMethod('setLifeCycleNum', 0) + lifecycleNum = await page.callMethod('getLifeCycleNum') + expect(lifecycleNum).toBe(0) + }); + + it('open dialog1', async () => { + await page.callMethod('openDialog1'); + // 无法通过获取 dom 元素来判断是否打开了 dialogPage + await page.waitFor(1000) + if (isWeb) { + await page.waitFor(2000) + } + const image = await program.screenshot({ + deviceShot: true, + area: { + x: 0, + y: 200, + } + }); + expect(image).toSaveImageSnapshot(); + lifecycleNum = await page.callMethod('getLifeCycleNum') + // 不应触发父页面的生命周期,应该触发: + // 1. openDialogPage success & complete callback + // 2. dialog page 生命周期 + expect(lifecycleNum).toBe(7) + await page.callMethod('setLifeCycleNum', 0) + }); + + it('closeDialogPage', async () => { + await page.callMethod('closeDialog'); + const image = await program.screenshot({ + deviceShot: true, + area: { + x: 0, + y: 200, + } + }); + expect(image).toSaveImageSnapshot(); + // closeDialogPage success & complete callback 应被触发 + // dialogPage onUnload 应被触发 + lifecycleNum = await page.callMethod('getLifeCycleNum') + expect(lifecycleNum).toBe(-3) + await page.callMethod('setLifeCycleNum', 0) + }) + + it('openDialog with wrong path', async () => { + await page.callMethod('openDialog1WrongPath') + lifecycleNum = await page.callMethod('getLifeCycleNum') + expect(lifecycleNum).toBe(-3) + await page.callMethod('setLifeCycleNum', 0) + }) + + it('navigateTo nextPage & open Dialog', async () => { + await page.callMethod('goNextPageOpenDialog1') + await page.waitFor(2000) + if (isWeb) { + await page.waitFor(3000) + } + page = await program.currentPage() + expect(page.path).toBe(NEXT_PAGE_PATH.substring(1)) + await page.waitFor(1000) + if (isWeb) { + await page.waitFor(2000) + } + const image = await program.screenshot({ + deviceShot: true, + area: { + x: 0, + y: 200, + } + }); + expect(image).toSaveImageSnapshot(); + lifecycleNum = await page.callMethod('getLifeCycleNum') + expect(lifecycleNum).toBe(-4) + await page.callMethod('setLifeCycleNum', 0) + }) + + it('dialog1 navigateBack', async () => { + await program.navigateBack() + page = await program.currentPage() + // dialogPage onBackPress 返回 true, 应可以拦截 navigateBack + expect(page.path).toBe(NEXT_PAGE_PATH.substring(1)) + const image = await program.screenshot({ + deviceShot: true, + area: { + x: 0, + y: 200, + } + }); + expect(image).toSaveImageSnapshot(); + lifecycleNum = await page.callMethod('getLifeCycleNum') + // onBackPress 生命周期应该被触发 + expect(lifecycleNum).toBe(1) + await page.callMethod('setLifeCycleNum', 0) + }) + + it('open dialog2', async () => { + await page.callMethod('openDialog2') + await page.waitFor(1000) + if (isWeb) { + await page.waitFor(2000) + } + lifecycleNum = await page.callMethod('getLifeCycleNum') + // 应触发前一个 dialogPage 的 onHide + expect(lifecycleNum).toBe(4) + await page.callMethod('setLifeCycleNum', 0) + }) + + it('closeDialogPage', async () => { + await page.callMethod('closeDialog') + lifecycleNum = await page.callMethod('getLifeCycleNum') + // 应触发 success & complete 回调 + // 应触发 dialogPage 的 unload,下层的 dialogPage 会先 show 再 unload + expect(lifecycleNum).toBe(-7) + + const image = await program.screenshot({ + deviceShot: true, + area: { + x: 0, + y: 200, + } + }); + expect(image).toSaveImageSnapshot(); + await page.callMethod('setLifeCycleNum', 0) + }) + + it('open multiple dialog page', async () => { + await page.callMethod('openDialog1') + await page.waitFor(1000) + if (isWeb) { + await page.waitFor(2000) + } + const image1 = await program.screenshot({ + deviceShot: true, + area: { + x: 0, + y: 200, + } + }); + expect(image1).toSaveImageSnapshot(); + lifecycleNum = await page.callMethod('getLifeCycleNum') + expect(lifecycleNum).toBe(4) + + await page.callMethod('openDialog2') + await page.waitFor(1000) + if (isWeb) { + await page.waitFor(2000) + } + const image2 = await program.screenshot({ + deviceShot: true, + area: { + x: 0, + y: 200, + } + }); + expect(image2).toSaveImageSnapshot(); + lifecycleNum = await page.callMethod('getLifeCycleNum') + expect(lifecycleNum).toBe(8) + await page.callMethod('setLifeCycleNum', 0) + }) + + it('openDialogPage to home page', async () => { + await page.callMethod('openDialogPage1ToHomePage') + await page.waitFor(1000) + if (isWeb) { + await page.waitFor(2000) + } + lifecycleNum = await page.callMethod('getLifeCycleNum') + expect(lifecycleNum).toBe(4) + await page.callMethod('setLifeCycleNum', 0) + }) + + it('dialog2 navigateBack', async () => { + await program.navigateBack() + page = await program.currentPage() + // dialogPage onBackPress 返回 true, 应可以拦截 navigateBack + expect(page.path).toBe(FIRST_PAGE_PATH.substring(1)) + const image = await program.screenshot({ + deviceShot: true, + area: { + x: 0, + y: 200, + } + }); + expect(image).toSaveImageSnapshot(); + lifecycleNum = await page.callMethod('getLifeCycleNum') + // onBackPress 生命周期应该被触发 + expect(lifecycleNum).toBe(2) + await page.callMethod('setLifeCycleNum', 0) + }) + + it('close specified dialogPage', async () => { + await page.callMethod('openDialog2') + await page.waitFor(1000) + if (isWeb) { + await page.waitFor(2000) + } + const image1 = await program.screenshot({ + deviceShot: true, + area: { + x: 0, + y: 200, + } + }); + expect(image1).toSaveImageSnapshot(); + lifecycleNum = await page.callMethod('getLifeCycleNum') + expect(lifecycleNum).toBe(4) + + await page.callMethod('openDialog1') + await page.waitFor(1000) + if (isWeb) { + await page.waitFor(2000) + } + const image2 = await program.screenshot({ + deviceShot: true, + area: { + x: 0, + y: 200, + } + }); + expect(image2).toSaveImageSnapshot(); + lifecycleNum = await page.callMethod('getLifeCycleNum') + expect(lifecycleNum).toBe(10) + + await page.callMethod('closeSpecifiedDialog', 0) + const image3 = await program.screenshot({ + deviceShot: true, + area: { + x: 0, + y: 200, + } + }); + expect(image3).toSaveImageSnapshot(); + lifecycleNum = await page.callMethod('getLifeCycleNum') + expect(lifecycleNum).toBe(7) + + await page.callMethod('closeSpecifiedDialog', 1) + const image4 = await program.screenshot({ + deviceShot: true, + area: { + x: 0, + y: 200, + } + }); + expect(image4).toSaveImageSnapshot(); + lifecycleNum = await page.callMethod('getLifeCycleNum') + expect(lifecycleNum).toBe(5) + + await page.callMethod('closeSpecifiedDialog', 0) + const image5 = await program.screenshot({ + deviceShot: true, + area: { + x: 0, + y: 200, + } + }); + expect(image5).toSaveImageSnapshot(); + lifecycleNum = await page.callMethod('getLifeCycleNum') + expect(lifecycleNum).toBe(2) + }) + + + afterAll(async () => { + await page.callMethod('setLifeCycleNum', initLifeCycleNum) + }); +}); diff --git a/pages/API/dialog-page/dialog-page.uvue b/pages/API/dialog-page/dialog-page.uvue new file mode 100644 index 0000000000000000000000000000000000000000..cd9768b71db33d6dda2d05ba853e8211b57f41af --- /dev/null +++ b/pages/API/dialog-page/dialog-page.uvue @@ -0,0 +1,176 @@ + + + diff --git a/pages/API/dialog-page/next-page.uvue b/pages/API/dialog-page/next-page.uvue new file mode 100644 index 0000000000000000000000000000000000000000..c3e7a955bea5f6f3a7c6c8b16a87d2c4dfce1933 --- /dev/null +++ b/pages/API/dialog-page/next-page.uvue @@ -0,0 +1,111 @@ + + + diff --git a/pages/API/download-file/download-file.uvue b/pages/API/download-file/download-file.uvue index 48d1d9f947640afa32abf9ae0973f39e4f4752b1..370522685f01a9d2206c37dda1b4024ede66f4ba 100644 --- a/pages/API/download-file/download-file.uvue +++ b/pages/API/download-file/download-file.uvue @@ -18,14 +18,13 @@ - - - diff --git a/pages/API/element-takesnapshot/element-takesnapshot.uvue b/pages/API/element-takesnapshot/element-takesnapshot.uvue index 4f4d19f0aca3d7abd2fe8ee61c06f401197194de..655854bf57f9789957b0597cd66f66b8f67e49fc 100644 --- a/pages/API/element-takesnapshot/element-takesnapshot.uvue +++ b/pages/API/element-takesnapshot/element-takesnapshot.uvue @@ -1,76 +1,77 @@ - - - diff --git a/pages/API/env/env.uvue b/pages/API/env/env.uvue index 5f57976fcf7ee914d74272fefdcd3bf34b99ba83..ba947128d0fa420442bb821c4bf9ec6bdc4f6de2 100644 --- a/pages/API/env/env.uvue +++ b/pages/API/env/env.uvue @@ -1,49 +1,51 @@ - - - - - diff --git a/pages/API/event-bus/event-bus.test.js b/pages/API/event-bus/event-bus.test.js index f3aa542d21176af817e96614f99e0698dfacf540..0e5d377414be46f0a68198aa8ea48992ede8b04f 100644 --- a/pages/API/event-bus/event-bus.test.js +++ b/pages/API/event-bus/event-bus.test.js @@ -77,4 +77,13 @@ describe('event-bus', () => { const l3 = (await page.data()).log.length expect(l3).toBe(0) }) + it('test return id', async () => { + await page.callMethod('clear') + expect((await page.data()).log.length).toBe(0) + await page.callMethod('testReturnId') + const logs = await page.data('log') + expect(logs.length).toBe(2) + expect(logs[0]).toBe('触发 test-return-id $on fn') + expect(logs[1]).toBe('触发 test-return-id $once fn') + }) }) diff --git a/pages/API/event-bus/event-bus.uvue b/pages/API/event-bus/event-bus.uvue index 274f7c1f54a297ed240409074453218add1962de..99395dd7a3f618467ac006048dbbd8c0123031c2 100644 --- a/pages/API/event-bus/event-bus.uvue +++ b/pages/API/event-bus/event-bus.uvue @@ -14,12 +14,13 @@ {{ item }} - - - - 接收到的 obj 参数: - {{JSON.stringify(objArg)}} - + + + + 接收到的 obj 参数: + {{JSON.stringify(objArg)}} + + @@ -49,7 +50,7 @@ uni.$on('test', this.fn2) }, onObj() { - uni.$on('test-obj', (res: UTSJSONObject) => { + uni.$on('test-obj', (res : UTSJSONObject) => { this.objArg = res }) }, @@ -71,6 +72,19 @@ clear() { this.log.length = 0 }, + testReturnId(){ + const id1 = uni.$on('test-return-id', this.fn) + uni.$emit('test-return-id', '触发 test-return-id $on fn') + uni.$off('test-return-id', id1) + uni.$emit('test-return-id', '触发 test-return-id $on fn') + + uni.$once('test-return-id', this.fn) + uni.$emit('test-return-id', '触发 test-return-id $once fn') + uni.$emit('test-return-id', '触发 test-return-id $once fn') + const id2 = uni.$once('test-id', this.fn) + uni.$off('test-return-id', id2) + uni.$emit('test-return-id', '触发 test-return-id $once fn') + } }, } diff --git a/pages/API/event-bus/uts-event-bus.test.js b/pages/API/event-bus/uts-event-bus.test.js new file mode 100644 index 0000000000000000000000000000000000000000..83bd671503f9987b31d110d1dba5dbccbd0c8c1b --- /dev/null +++ b/pages/API/event-bus/uts-event-bus.test.js @@ -0,0 +1,85 @@ +// uni-app自动化测试教程: https://uniapp.dcloud.net.cn/worktile/auto/hbuilderx-extension/ +const PAGE_PATH = '/pages/API/event-bus/uts-event-bus' + + +describe('event-bus', () => { + const platformInfo = process.env.uniTestPlatformInfo.toLowerCase() + if (!platformInfo.startsWith('ios')) { + it('pass', async () => { + expect(1).toBe(1); + }); + return; + } + + if ( + platformInfo.indexOf('14.5') != -1 || + platformInfo.indexOf('13.7') != -1 || + platformInfo.indexOf('12.4') != -1 + ) { + it('iOS 14.5 13.7 12.4 不支持依赖uts插件测试', () => { + expect(1).toBe(1) + }) + return + } + + + let page + beforeAll(async () => { + page = await program.reLaunch(PAGE_PATH) + await page.waitFor('view') + }) + + it('on', async () => { + await page.callMethod('clear') + await page.callMethod('JsOnUts') + await page.callMethod('emitFromUts') + const l1 = (await page.data()).log.length + expect(l1).toBeGreaterThan(0) + + + await page.callMethod('clear') + await page.callMethod('offUts') + await page.callMethod('emitFromUts') + const l2 = (await page.data()).log.length + expect(l2).toBe(0) + + await page.callMethod('clear') + await page.callMethod('UtsOnJS') + await page.callMethod('emitFormJS') + const l3 = (await page.data()).log.length + expect(l3).toBeGreaterThan(0) + + await page.callMethod('clear') + await page.callMethod('offJs') + await page.callMethod('emitFormJS') + const l4 = (await page.data()).log.length + console.log(l4) + expect(l4).toBe(0) + await page.callMethod('clear') + }) + + it('once', async () => { + await page.callMethod('clear') + await page.callMethod('JsOnUtsOnce') + await page.callMethod('emitFromUts') + const l1 = (await page.data()).log.length + expect(l1).toBeGreaterThan(0) + await page.callMethod('clear') + await page.callMethod('emitFromUts') + const l2 = (await page.data()).log.length + expect(l2).toBe(0) + + await page.callMethod('clear') + await page.callMethod('UtsOnJSOnce') + await page.callMethod('emitFormJS') + const l3 = (await page.data()).log.length + expect(l3).toBeGreaterThan(0) + await page.callMethod('clear') + await page.callMethod('emitFormJS') + const l4 = (await page.data()).log.length + expect(l4).toBe(0) + + await page.callMethod('clear') + }) + +}) diff --git a/pages/API/event-bus/uts-event-bus.uvue b/pages/API/event-bus/uts-event-bus.uvue new file mode 100644 index 0000000000000000000000000000000000000000..6e554582b5c2770e2c4c3b5e30e62f0e9ea515f8 --- /dev/null +++ b/pages/API/event-bus/uts-event-bus.uvue @@ -0,0 +1,104 @@ + + + + + diff --git a/pages/API/exit/exit.uvue b/pages/API/exit/exit.uvue index 9de09acdd6bfd4e033a551f7b6a7479ef5eb7609..4e614cec6c628230456a44f04958a93dc7d599d9 100644 --- a/pages/API/exit/exit.uvue +++ b/pages/API/exit/exit.uvue @@ -1,23 +1,23 @@ - - - - - \ No newline at end of file + + + + + diff --git a/pages/API/facial-recognition-meta-info/facial-recognition-meta-info.uvue b/pages/API/facial-recognition-meta-info/facial-recognition-meta-info.uvue index 70fa9f509d8a56245f45769de2afaed782c9213b..fe7cee256f1f323aef698b3df39a10047fdb855b 100644 --- a/pages/API/facial-recognition-meta-info/facial-recognition-meta-info.uvue +++ b/pages/API/facial-recognition-meta-info/facial-recognition-meta-info.uvue @@ -1,88 +1,86 @@ - - - - - diff --git a/pages/API/get-app-authorize-setting/get-app-authorize-setting.uvue b/pages/API/get-app-authorize-setting/get-app-authorize-setting.uvue index 0dd5349134f2954242ca05abebddf75164582461..4b9e3b71858d2aa6bac3b1cf5fa549e3ee38840a 100644 --- a/pages/API/get-app-authorize-setting/get-app-authorize-setting.uvue +++ b/pages/API/get-app-authorize-setting/get-app-authorize-setting.uvue @@ -1,23 +1,23 @@ + + + + + - + @@ -60,6 +77,7 @@ pages: [] as Page[], PageStyleArray: PageStyleArray as PageStyleItem[], currentPageStyle: {} as UTSJSONObject, + testing: false } }, computed: { @@ -67,7 +85,15 @@ return JSON.stringify(this.currentPageStyle) } }, - onLoad() { + onLoad(options : OnLoadOptions) { + // #ifndef APP-ANDROID + if (options instanceof UTSJSONObject) { + this.checked = true + } + // #endif + // #ifdef APP-ANDROID + this.checked = true + // #endif this.getPageStyle(); }, onPullDownRefresh() { @@ -83,7 +109,7 @@ this.pages.length = 0 const pages = getCurrentPages() this.pages.push(new Page(pages[0].route)) - if (this.pages[0].route.includes('/tabBar/')) { + if (this.checked && (this.pages[0].route.includes('/tabBar/') || this.pages[0].route == '/')) { this.checked = true } for (let i = 1; i < pages.length; i++) { @@ -112,25 +138,86 @@ getPageStyle() : UTSJSONObject { const pages = getCurrentPages(); const currentPage = pages[pages.length - 1]; - this.currentPageStyle = currentPage.$getPageStyle() + this.currentPageStyle = currentPage.getPageStyle() return this.currentPageStyle; }, setPageStyle(style : UTSJSONObject) { console.log('setPageStyle:', style); const pages = getCurrentPages(); const currentPage = pages[pages.length - 1]; - currentPage.$setPageStyle(style); + currentPage.setPageStyle(style); }, goSetDisablePullDownRefresh() { uni.navigateTo({ url: '/pages/API/get-current-pages/set-page-style-disable-pull-down-refresh' }); - } - // getCurrentPage(): Page { - // const pages = getCurrentPages(); - // const currentPage = pages[pages.length - 1]; - // return currentPage; - // } + }, + getCurrentPage() : UniPage { + const pages = getCurrentPages() + return pages[pages.length - 1] + }, + check$page() : boolean { + const page = this.getCurrentPage() + let res = this.$page === page + if (this.testing && res) { + res = page.options['test'] == '123' + if (res) { + // #ifdef WEB + res = page.route == '/pages/API/get-current-pages/get-current-pages' + // #endif + // #ifndef WEB + res = page.route == 'pages/API/get-current-pages/get-current-pages' + // #endif + } + } + console.log('check $page', res) + uni.showToast(res ? { title: 'check success' } : { title: 'check fail', icon: 'error' }) + return res + }, + checkGetParentPage() : boolean { + const page = this.getCurrentPage() + const parentPage = page.getParentPage() + const res = parentPage == null + console.log('check getParentPage', res) + uni.showToast(res ? { title: 'check success' } : { title: 'check fail', icon: 'error' }) + return res + }, + checkGetDialogPages() : boolean { + const page = this.getCurrentPage() + const dialogPages = page.getDialogPages() + const res = Array.isArray(dialogPages) && dialogPages.length == 0 + uni.showToast(res ? { title: 'check success' } : { title: 'check fail', icon: 'error' }) + console.log('check getDialogPages', res) + return res + }, + checkGetElementById() : boolean { + const page = this.getCurrentPage() + const element = page.getElementById('check-get-element-by-id-btn') + let res = element != null + // #ifndef APP-ANDROID + if (res) { + const elPage = element!.getPage() + console.log('elPage', elPage) + res = elPage === page + } + // #endif + console.log('check getElementById', res) + uni.showToast(res ? { title: 'check success' } : { title: 'check fail', icon: 'error' }) + return res + }, + checkGetAndroidView() : boolean { + const page = this.getCurrentPage() + const androidView = page.getAndroidView() + // #ifdef APP-ANDROID + const res = androidView != null + // #endif + // #ifndef APP-ANDROID + const res = androidView == null + // #endif + console.log('check getAndroidView', res) + uni.showToast(res ? { title: 'check success' } : { title: 'check fail', icon: 'error' }) + return res + }, }, } @@ -175,4 +262,4 @@ .radio-value { margin-left: 10px; } - + diff --git a/pages/API/get-current-pages/page-style.uts b/pages/API/get-current-pages/page-style.uts index 1c70d11773e2fc8a6c6aa7640ba590abab3d5dbf..62bf13a326f5fb8db598ebaa14c7765f63f41137 100644 --- a/pages/API/get-current-pages/page-style.uts +++ b/pages/API/get-current-pages/page-style.uts @@ -1,8 +1,8 @@ export type PageStyleItem = { key : string - type : string - value: Array + type : string + value : Array } export const PageStyleArray = [ @@ -70,4 +70,14 @@ export const PageStyleArray = [ key: "navigationBarAutoBackButton", type: "boolean", value: [true, false] + }, + { + key: "hideStatusBar", + type: "boolean", + value: [true, false] + }, + { + key: "hideBottomNavigationIndicator", + type: "boolean", + value: [true, false] }] as PageStyleItem[] diff --git a/pages/API/get-current-pages/set-page-style-disable-pull-down-refresh.uvue b/pages/API/get-current-pages/set-page-style-disable-pull-down-refresh.uvue index f190e74ef85553723e27a05d117d4c2d91e0ad91..2d8d995b9cbeab6683343f75116348af1e5c6267 100644 --- a/pages/API/get-current-pages/set-page-style-disable-pull-down-refresh.uvue +++ b/pages/API/get-current-pages/set-page-style-disable-pull-down-refresh.uvue @@ -44,13 +44,13 @@ getPageStyle() { const pages = getCurrentPages(); const currentPage = pages[pages.length - 1]; - this.currentPageStyle = currentPage.$getPageStyle(); + this.currentPageStyle = currentPage.getPageStyle(); }, setPageStyle(enable : boolean) { // 目前仅支持 enablePullDownRefresh const pages = getCurrentPages(); const currentPage = pages[pages.length - 1]; - currentPage.$setPageStyle({ + currentPage.setPageStyle({ enablePullDownRefresh: enable }); this.enablePullDownRefreshStatus = enable @@ -95,4 +95,4 @@ margin-top: 15px; opacity: .8; } - + diff --git a/pages/API/get-element-by-id/get-element-by-id-multiple-root-node.uvue b/pages/API/get-element-by-id/get-element-by-id-multiple-root-node.uvue index 6e868a0cf93ab2b4b8701c5de4371c60f3a2abce..b252eeaec2ee00740be7ab970eee1d1cb03d4e2c 100644 --- a/pages/API/get-element-by-id/get-element-by-id-multiple-root-node.uvue +++ b/pages/API/get-element-by-id/get-element-by-id-multiple-root-node.uvue @@ -1,5 +1,5 @@ @@ -44,4 +44,4 @@ } } } - + diff --git a/pages/API/get-element-by-id/get-element-by-id.uvue b/pages/API/get-element-by-id/get-element-by-id.uvue index 338471498a35b7a0dbcc25d9b4ad841c482dd475..dc6653c158c824f231edfceb941d358390b52c13 100644 --- a/pages/API/get-element-by-id/get-element-by-id.uvue +++ b/pages/API/get-element-by-id/get-element-by-id.uvue @@ -26,7 +26,7 @@ homePagePath: '/pages/tabBar/component', launchOptionsPath: '', } - }, + }, methods: { getElementByNotExistId() : Element | null { return uni.getElementById('not-exist-id') @@ -49,12 +49,12 @@ }, goMultipleRootNode() { uni.navigateTo({ url: '/pages/API/get-element-by-id/get-element-by-id-multiple-root-node' }) - }, - //自动化测试获取text元素的offsetLeft属性值 - getTextOffsetLeft(): number { - const text = uni.getElementById('text')! - return text.offsetLeft + }, + //自动化测试获取text元素的offsetLeft属性值 + getTextOffsetLeft() : number { + const text = uni.getElementById('text')! + return text.offsetLeft } } } - + diff --git a/pages/API/get-enter-options-sync/get-enter-options-sync.uvue b/pages/API/get-enter-options-sync/get-enter-options-sync.uvue index a53ca63138ffe97f35bf301d0dca5796fac0fbff..c2b5ca1f3d1d10fb093053c746f0805b761aaae6 100644 --- a/pages/API/get-enter-options-sync/get-enter-options-sync.uvue +++ b/pages/API/get-enter-options-sync/get-enter-options-sync.uvue @@ -11,16 +11,17 @@ diff --git a/pages/API/get-file-system-manager/get-file-system-manager.test.js b/pages/API/get-file-system-manager/get-file-system-manager.test.js index 1160298985dbcaafc9415db2aed48f4eacbb33f9..9b2ef897493f15e21a299af51d63a33aa2b22e7f 100644 --- a/pages/API/get-file-system-manager/get-file-system-manager.test.js +++ b/pages/API/get-file-system-manager/get-file-system-manager.test.js @@ -3,1406 +3,1484 @@ const PAGE_PATH = '/pages/API/get-file-system-manager/get-file-system-manager' describe('ExtApi-FileManagerTest', () => { - if (process.env.uniTestPlatformInfo.indexOf('web') > -1 || process.env.UNI_AUTOMATOR_APP_WEBVIEW == 'true') { - it('dummyTest', () => { - expect(1).toBe(1) - }) - return - } - let page; - let mBasePath; - let mGlobalTempPath; - let mGlobalRootPath - - - function getData(key = '') { - return new Promise(async (resolve, reject) => { - const data = await page.data() - resolve(key ? data[key] : data) - }) - } - - - beforeAll(async () => { - page = await program.reLaunch(PAGE_PATH) - await page.waitFor(600); - }); - - async function isDone() { - let isDone = await page.waitFor(async () => { - return await page.data('done') - }) - await page.setData({ - done: false - }) - return isDone - } - - it('USER_DATA_PATH test', async () => { - // 测试 USER_DATA_PATH - let globalUserDataPath = await getData('globalUserDataPath') - mBasePath = await getData('basePath') - mGlobalRootPath = await getData('globalRootPath') - mGlobalTempPath = await getData('globalTempPath') - - await page.setData({ - logAble: false, - recursiveVal: true, - copyToBasePath: globalUserDataPath, - basePath: globalUserDataPath, - rmDirFile: 'a', - readDir: 'a', - writeFile: 'a/1.txt', - readFile: 'a/1.txt', - unlinkFile: 'a/1.txt', - writeFileContent: '锄禾日当午,汗滴禾下土,谁知盘中餐,粒粒皆辛苦' - }) - - // 先清除文件,需要清除全部可能存在的历史测试文件,避免运行失败 - const btnUnLinkFileButton = await page.$('#btn-clear-file') - await btnUnLinkFileButton.tap() - await isDone() - - - // 清除文件夹 - const btnRmDirButton = await page.$('#btn-remove-dir') - await btnRmDirButton.tap() - await isDone() - // 重新创建测试目录 - const btnMkdDirButton = await page.$('#btn-mkdir') - await btnMkdDirButton.tap() - await isDone() - - const btnReadDirButton = await page.$('#btn-read-dir') - await btnReadDirButton.tap() - await isDone() - - - // 期望通过 recursive = true的 文件夹删除,得到一个空的 /a 目录 - let fileListComplete = await getData('fileListComplete') - expect(JSON.stringify(fileListComplete)).toEqual('[]') - let fileListSuccess = await getData('fileListSuccess') - expect(JSON.stringify(fileListSuccess)).toEqual('[]') - - // 先测试 recursive = false 文件夹创建,期望失败 - await page.setData({ - recursiveVal: false, - mkdirFile: 'a/b/c' - }) - - - await btnMkdDirButton.tap() - await isDone() - - - let lastFailError = await getData('lastFailError') - expect(lastFailError.errCode).toEqual(1300002) - expect(lastFailError.errMsg).toEqual('no such file or directory') - let lastCompleteError = await getData('lastCompleteError') - expect(lastCompleteError.errCode).toEqual(1300002) - expect(lastCompleteError.errMsg).toEqual('no such file or directory') - - - // 测试 recursive = true 期望文件夹创建成功 - await page.setData({ - recursiveVal: true - }) - await btnMkdDirButton.tap() - await isDone() - - await btnReadDirButton.tap() - await isDone() - - // 期望通过 recursive = true的 文件夹删除,得到一个空的 /a 目录 - fileListComplete = await getData('fileListComplete') - expect(JSON.stringify(fileListComplete)).toEqual("[\"b\"]") - fileListSuccess = await getData('fileListSuccess') - expect(JSON.stringify(fileListSuccess)).toEqual("[\"b\"]") - - // 测试写入文件 - const btnWriteFileButton = await page.$('#btn-write-file') - await btnWriteFileButton.tap() - await isDone() - // 检查目录列表数量 - await btnReadDirButton.tap() - await isDone() - fileListComplete = await getData('fileListComplete') - fileListComplete.sort() - expect(JSON.stringify(fileListComplete)).toEqual("[\"1.txt\",\"b\"]") - fileListSuccess = await getData('fileListSuccess') - fileListSuccess.sort() - expect(JSON.stringify(fileListSuccess)).toEqual("[\"1.txt\",\"b\"]") - // 获取和对比 文件内容 - const btnReadFileButton = await page.$('#btn-read-file') - await btnReadFileButton.tap() - await isDone() - let readFileRet = await getData('readFileRet') - expect(readFileRet).toEqual("锄禾日当午,汗滴禾下土,谁知盘中餐,粒粒皆辛苦") - - // 更换文件内容 获取和对比 文件md5和sha1 - await page.setData({ - writeFileContent: "If you were a teardrop;In my eye,For fear of losing you,I would never cry.And if the golden sun,Should cease to shine its light,Just one smile from you,Would make my whole world bright.", - getFileInfoAlgorithm: "md5" - }) - await btnWriteFileButton.tap() - await isDone() - - await btnReadFileButton.tap() - await isDone() - readFileRet = await getData('readFileRet') - expect(readFileRet).toEqual( - "If you were a teardrop;In my eye,For fear of losing you,I would never cry.And if the golden sun,Should cease to shine its light,Just one smile from you,Would make my whole world bright." - ) - - const btnGetFileInfoButton = await page.$('#btn-get-file-info') - await btnGetFileInfoButton.tap() - await isDone() - - let getFileInfoSize = await getData('getFileInfoSize') - expect(getFileInfoSize).toEqual(185) - let getFileInfoDigest = await getData('getFileInfoDigest') - expect(getFileInfoDigest).toEqual("29ddd02ed3c38ccebb98884eda082cb1") - // 切换为 sha1 - await page.setData({ - getFileInfoAlgorithm: "sha1" - }) - - await btnGetFileInfoButton.tap() - await isDone() - - getFileInfoSize = await getData('getFileInfoSize') - expect(getFileInfoSize).toEqual(185) - getFileInfoDigest = await getData('getFileInfoDigest') - expect(getFileInfoDigest).toEqual("ebef4e75783e0db499fc260d120e695005bead8a") - - // 测试 copyfile - await page.setData({ - - copyFromFile: "a/1.txt", - copyToFile: "a/2.txt" - }) - const btnCopyFileButton = await page.$('#btn-copy-file') - await btnCopyFileButton.tap() - await isDone() - - - await btnReadDirButton.tap() - await isDone() - - // 1.txt 2.txt 两个文件都存在 - fileListComplete = await getData('fileListComplete') - fileListComplete.sort() - expect(JSON.stringify(fileListComplete)).toEqual("[\"1.txt\",\"2.txt\",\"b\"]") - fileListSuccess = await getData('fileListSuccess') - fileListSuccess.sort() - expect(JSON.stringify(fileListSuccess)).toEqual("[\"1.txt\",\"2.txt\",\"b\"]") - - // 测试 rename - await page.setData({ - renameFromFile: "a/2.txt", - renameToFile: "a/3.txt" - }) - - const btnRenameFileButton = await page.$('#btn-rename-file') - await btnRenameFileButton.tap() - await isDone() - - await btnReadDirButton.tap() - await isDone() - - // 1.txt 3.txt 两个文件都存在 - fileListComplete = await getData('fileListComplete') - fileListComplete.sort() - expect(JSON.stringify(fileListComplete)).toEqual("[\"1.txt\",\"3.txt\",\"b\"]") - fileListSuccess = await getData('fileListSuccess') - fileListSuccess.sort() - expect(JSON.stringify(fileListSuccess)).toEqual("[\"1.txt\",\"3.txt\",\"b\"]") - }); - - it('TEMP_PATH test', async () => { - // 测试 TEMP_PATH - let globalTempPath = await getData('globalTempPath') - - let version = process.env.uniTestPlatformInfo - version = parseInt(version.split(" ")[1]) - let testDirName = "我们经历了一场兵慌马乱的战争.1@2#3$4%5^6&7*8(9)0+-qwertyuiopasdfghjklzxcvbnm;," - if (version < 6) { - // android 6 以下文件名不能包含特殊字符 - testDirName = "我们经历了一场兵慌马乱的战争" - } - - await page.setData({ - logAble: false, - recursiveVal: true, - basePath: globalTempPath, - copyToBasePath: globalTempPath, - rmDirFile: 'a', - mkdirFile: 'a', - unlinkFile: 'a/' + testDirName + '/中文路径/张三/name/中文文件.mock' - }) - - - // 先清除文件,需要清除全部可能存在的历史测试文件,避免运行失败 - const btnUnLinkFileButton = await page.$('#btn-unlink-file') - await btnUnLinkFileButton.tap() - await isDone() - - - // 清除文件夹 - const btnRmDirButton = await page.$('#btn-remove-dir') - await btnRmDirButton.tap() - await isDone() - - // 重新创建测试目录 - const btnMkdDirButton = await page.$('#btn-mkdir') - await btnMkdDirButton.tap() - await isDone() - - const btnReadDirButton = await page.$('#btn-read-dir') - await btnReadDirButton.tap() - await isDone() - - - // 期望通过 recursive = true的 文件夹删除,得到一个空的 /a 目录 - let fileListComplete = await getData('fileListComplete') - expect(JSON.stringify(fileListComplete)).toEqual("[]") - let fileListSuccess = await getData('fileListSuccess') - expect(JSON.stringify(fileListSuccess)).toEqual("[]") - - // 测试 创建多层级文件目录 - await page.setData({ - recursiveVal: true, - mkdirFile: 'a/b/c/d/e/f/g/h/i/g/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z/中文路径/张三/test', - }) - - await btnMkdDirButton.tap() - await isDone() - - await btnReadDirButton.tap() - await isDone() - - fileListComplete = await getData('fileListComplete') - expect(JSON.stringify(fileListComplete)).toEqual("[\"b\"]") - fileListSuccess = await getData('fileListSuccess') - expect(JSON.stringify(fileListSuccess)).toEqual("[\"b\"]") - - // 测试 创建包含中文特殊符号的目录 - await page.setData({ - recursiveVal: true, - mkdirFile: 'a/' + testDirName + '/中文路径/张三/name', - }) - await btnMkdDirButton.tap() - await isDone() - - await btnReadDirButton.tap() - await isDone() - - // 期望通过 recursive = true的 文件夹删除,得到一个空的 /a 目录 - fileListComplete = await getData('fileListComplete') - fileListComplete.sort() - expect(JSON.stringify(fileListComplete)).toEqual("[\"b\",\"" + testDirName + "\"]") - fileListSuccess = await getData('fileListSuccess') - fileListSuccess.sort() - expect(JSON.stringify(fileListSuccess)).toEqual("[\"b\",\"" + testDirName + "\"]") - - /** - * 从资源文件中读取图片为base64,测试写入较大文件场景 - * 'static/test-image/logo.ico' 注意,依赖这个资源文件,不能删除 - */ - await page.setData({ - basePath: "", - readFile: 'static/test-image/logo.ico', - readFileEncoding: 'base64' - }) - - - // 获取和对比 文件内容 - const btnReadFileButton = await page.$('#btn-read-file') - await btnReadFileButton.tap() - await isDone() - let readFileRet = await getData('readFileRet') - expect(readFileRet.length).toEqual(208544) - let endStr = readFileRet.substring(readFileRet.length - 10) - expect(endStr).toEqual("///////w==") - - await page.setData({ - basePath: globalTempPath, - writeFile: 'a/' + testDirName + '/中文路径/张三/name/中文文件.mock', - writeFileContent: readFileRet - }) - - - const btnWriteFileButton = await page.$('#btn-write-file') - await btnWriteFileButton.tap() - await isDone() - - // 获取文件列表,判断是否写入成功,同时置空base64内容 避免影响实时查看状态 - await page.setData({ - readDir: 'a/' + testDirName + '/中文路径/张三/name', - readFileRet: '', - writeFileContent: '' - }) - - // 检查目录列表数量 - await btnReadDirButton.tap() - await isDone() - fileListComplete = await getData('fileListComplete') - expect(JSON.stringify(fileListComplete)).toEqual("[\"中文文件.mock\"]") - fileListSuccess = await getData('fileListSuccess') - expect(JSON.stringify(fileListSuccess)).toEqual("[\"中文文件.mock\"]") - - - // 更换文件内容 获取和对比 文件md5和sha1 - await page.setData({ - getFileInfoFile: 'a/' + testDirName + '/中文路径/张三/name/中文文件.mock', - getFileInfoAlgorithm: "md5", - }) - - const btnGetFileInfoButton = await page.$('#btn-get-file-info') - await btnGetFileInfoButton.tap() - await isDone() - - let getFileInfoSize = await getData('getFileInfoSize') - expect(getFileInfoSize).toEqual(208544) - let getFileInfoDigest = await getData('getFileInfoDigest') - expect(getFileInfoDigest).toEqual("486f75ea76625f8c103cac4bc9c49511") - - // 切换为 sha1 - await page.setData({ - getFileInfoAlgorithm: "sha1" - }) - - await btnGetFileInfoButton.tap() - await isDone() - - getFileInfoSize = await getData('getFileInfoSize') - expect(getFileInfoSize).toEqual(208544) - getFileInfoDigest = await getData('getFileInfoDigest') - expect(getFileInfoDigest).toEqual("1830169a16e7c860beff4a3b0975ba0b6f775f9e") - - // 测试不支持的摘要算法,期望返回错误 - await page.setData({ - getFileInfoAlgorithm: "sha256" - }) - - await btnGetFileInfoButton.tap() - await isDone() - - let lastFailError = await getData('lastFailError') - expect(lastFailError.errCode).toEqual(1300022) - let lastCompleteError = await getData('lastCompleteError') - expect(lastCompleteError.errCode).toEqual(1300022) - - - // rename 到一个没有提前创建过的目录,期望返回错误 - await page.setData({ - renameFromFile: "a/" + testDirName + "/中文路径/张三/name/中文文件.mock", - renameToFile: "a/没有提前创建的目录/3.txt" - }) - - const btnRenameFileButton = await page.$('#btn-rename-file') - await btnRenameFileButton.tap() - await isDone() - - lastFailError = await getData('lastFailError') - expect(lastFailError.errCode).toEqual(1300002) - lastCompleteError = await getData('lastCompleteError') - expect(lastCompleteError.errCode).toEqual(1300002) - - // 非递归创建一级目录。期望成功 - await page.setData({ - recursiveVal: false, - mkdirFile: 'a/提前创建的目录', - }) - - await btnMkdDirButton.tap() - await isDone() - - await page.setData({ - readDir: 'a', - }) - - await btnReadDirButton.tap() - await isDone() - - fileListComplete = await getData('fileListComplete') - fileListComplete.sort() - expect(JSON.stringify(fileListComplete)).toEqual("[\"b\",\"" + testDirName + "\",\"提前创建的目录\"]") - fileListSuccess = await getData('fileListSuccess') - fileListSuccess.sort() - expect(JSON.stringify(fileListSuccess)).toEqual("[\"b\",\"" + testDirName + "\",\"提前创建的目录\"]") - - - await page.setData({ - copyFromFile: "a/" + testDirName + "/中文路径/张三/name/中文文件.mock", - copyToFile: "a/提前创建的目录/4.txt" - }) - - const btnCopyFileButton = await page.$('#btn-copy-file') - await btnCopyFileButton.tap() - await isDone() - - await page.setData({ - readDir: 'a/提前创建的目录', - }) - - await btnReadDirButton.tap() - await isDone() - - fileListComplete = await getData('fileListComplete') - expect(JSON.stringify(fileListComplete)).toEqual("[\"4.txt\"]") - fileListSuccess = await getData('fileListSuccess') - expect(JSON.stringify(fileListSuccess)).toEqual("[\"4.txt\"]") - - await page.setData({ - unlinkFile: 'a/提前创建的目录/4.txt', - rmDirFile: 'a/提前创建的目录' - }) - await btnUnLinkFileButton.tap() - await isDone() - - await btnReadDirButton.tap() - await isDone() - - fileListComplete = await getData('fileListComplete') - expect(JSON.stringify(fileListComplete)).toEqual("[]") - fileListSuccess = await getData('fileListSuccess') - expect(JSON.stringify(fileListSuccess)).toEqual("[]") - - }); - - - - it('CROSS DIR test', async () => { - /** - * 跨越用户目录和代码资源目录 - */ - let globalRootPath = await getData('globalRootPath') - await page.setData({ - recursiveVal: true, - logAble: false, - basePath: globalRootPath, - readDir: 'a', - rmDirFile: 'a', - mkdirFile: 'a', - accessFile: 'a/从代码目录拷贝的资源.png', - unlinkFile: 'a/从代码目录拷贝的资源.png' - }) - - - // 先清除文件,需要清除全部可能存在的历史测试文件,避免运行失败 - const btnClearFileButton = await page.$('#btn-clear-file') - await btnClearFileButton.tap() - await isDone() - - - // 清除文件夹 - const btnRmDirButton = await page.$('#btn-remove-dir') - await btnRmDirButton.tap() - await isDone() - - // 重新创建测试目录,期望通过 recursive = true的 文件夹删除,得到一个空的 /a 目录 - const btnMkdDirButton = await page.$('#btn-mkdir') - await btnMkdDirButton.tap() - await isDone() - - const btnReadDirButton = await page.$('#btn-read-dir') - await btnReadDirButton.tap() - await isDone() - - let fileListComplete = await getData('fileListComplete') - expect(JSON.stringify(fileListComplete)).toEqual('[]') - let fileListSuccess = await getData('fileListSuccess') - expect(JSON.stringify(fileListSuccess)).toEqual('[]') - - - // 检查资源文件,此时不存在 - const btnAccessFileButton = await page.$('#btn-access-file') - await btnAccessFileButton.tap() - await isDone() - - let accessFileRet = await getData("accessFileRet") - expect(accessFileRet).toEqual('') - - - // 准备从资源目录拷贝png - await page.setData({ - basePath: "", - unlinkFile: 'static/test-image/logo.ico', - accessFile: 'static/test-image/logo.ico', - }) - // 检查资源文件,期望存在 - await btnAccessFileButton.tap() - await isDone() - - accessFileRet = await getData("accessFileRet") - expect(accessFileRet).toEqual('access:ok') - - // 尝试删除资源,期望失败 - const btnUnLinkFileButton = await page.$('#btn-unlink-file') - await btnUnLinkFileButton.tap() - await isDone() - - await btnAccessFileButton.tap() - await isDone() - - accessFileRet = await getData("accessFileRet") - expect(accessFileRet).toEqual('access:ok') - // 复制资源到 root目录 - await page.setData({ - copyToBasePath: globalRootPath, - copyFromFile: "static/test-image/logo.ico", - copyToFile: "a/从代码目录拷贝的资源.png" - }) - const btnCopyFileButton = await page.$('#btn-copy-file') - await btnCopyFileButton.tap() - await isDone() - - // 检查期望 root 目录中图片文件存在 - await page.setData({ - basePath: globalRootPath, - unlinkFile: 'a/从代码目录拷贝的资源.png', - accessFile: 'a/从代码目录拷贝的资源.png', - rmDirFile: 'a', - }) - await btnAccessFileButton.tap() - await isDone() - - accessFileRet = await getData("accessFileRet") - expect(accessFileRet).toEqual('access:ok') - - await btnUnLinkFileButton.tap() - await isDone() - - await btnAccessFileButton.tap() - await isDone() - - accessFileRet = await getData("accessFileRet") - expect(accessFileRet).toEqual('') - - // 从页面的按钮触发一次文件复制 - const btnCopyStaticFileButton = await page.$('#btn-copyStatic-file') - await btnCopyStaticFileButton.tap() - await isDone() - - await btnReadDirButton.tap() - await isDone() - - fileListComplete = await getData('fileListComplete') - expect(JSON.stringify(fileListComplete)).toEqual("[\"mock.json\"]") - fileListSuccess = await getData('fileListSuccess') - expect(JSON.stringify(fileListSuccess)).toEqual("[\"mock.json\"]") - - // 从页面的按钮触发一次文件清空 - await btnClearFileButton.tap() - await isDone() - - await btnReadDirButton.tap() - await isDone() - - fileListComplete = await getData('fileListComplete') - expect(JSON.stringify(fileListComplete)).toEqual("[]") - fileListSuccess = await getData('fileListSuccess') - expect(JSON.stringify(fileListSuccess)).toEqual("[]") - - }); - - - it('write and read', async () => { - /** - * 测试writefile readfile 各个参数是否符合预期 - */ - let globalTempPath = await getData('globalTempPath') - await page.setData({ - recursiveVal: true, - logAble: false, - basePath: globalTempPath, - readDir: 'd', - rmDirFile: 'd', - mkdirFile: 'd', - writeFileContent: "我爱北京天安门,天安门前太阳升", - writeFileEncoding: "utf-8", - readFileEncoding: "utf-8", - unlinkFile: 'd/write.bing', - writeFile: 'd/write.bing', - readFile: 'd/write.bing', - getFileInfoFile: 'd/write.bing', - getFileInfoAlgorithm: "sha1" - }) - - // 先清除文件,需要清除全部可能存在的历史测试文件,避免运行失败 - const btnUnLinkFileButton = await page.$('#btn-unlink-file') - await btnUnLinkFileButton.tap() - await isDone() - - // 清除文件夹 - const btnRmDirButton = await page.$('#btn-remove-dir') - await btnRmDirButton.tap() - await isDone() - - // 重新创建测试目录,期望通过 recursive = true的 文件夹删除,得到一个空的 /a 目录 - const btnMkdDirButton = await page.$('#btn-mkdir') - await btnMkdDirButton.tap() - await isDone() - - const btnReadDirButton = await page.$('#btn-read-dir') - await btnReadDirButton.tap() - await isDone() - - let fileListComplete = await getData('fileListComplete') - expect(JSON.stringify(fileListComplete)).toEqual('[]') - let fileListSuccess = await getData('fileListSuccess') - expect(JSON.stringify(fileListSuccess)).toEqual('[]') - - // 先用utf-8 写入内容 - const btnWriteFileButton = await page.$('#btn-write-file') - await btnWriteFileButton.tap() - await isDone() - - const btnReadFileButton = await page.$('#btn-read-file') - await btnReadFileButton.tap() - await isDone() - let readFileRet = await getData('readFileRet') - expect(readFileRet).toEqual("我爱北京天安门,天安门前太阳升") - - const btnGetFileInfoButton = await page.$('#btn-get-file-info') - await btnGetFileInfoButton.tap() - await isDone() - - let getFileInfoSize = await getData('getFileInfoSize') - expect(getFileInfoSize).toEqual(45) - let getFileInfoDigest = await getData('getFileInfoDigest') - expect(getFileInfoDigest).toEqual("2ae9c7672ff6c1e7c7e6a0bb4e74a6f06b39350b") - - // 尝试读取base64 信息 - await page.setData({ - readFileEncoding: "base64", - }) - - await btnReadFileButton.tap() - await isDone() - readFileRet = await getData('readFileRet') - expect(readFileRet).toEqual("5oiR54ix5YyX5Lqs5aSp5a6J6Zeo77yM5aSp5a6J6Zeo5YmN5aSq6Ziz5Y2H") - // 测试ascii,需要特别测试 ascii 写入非法字符的情况,因为微信的常量字符编码和android原生有差异。 - - await page.setData({ - writeFileContent: "丙辰中秋,欢饮达旦,大醉,作此篇,兼怀子由。明月几时有?把酒问青天。不知天上宫阙,今夕是何年。我欲乘风归去,又恐琼楼玉宇,高处不胜寒。起舞弄清影,何似在人间", - writeFileEncoding: "ascii", - readFileEncoding: "base64", - }) - - await btnWriteFileButton.tap() - await isDone() - - await btnGetFileInfoButton.tap() - await isDone() - - getFileInfoSize = await getData('getFileInfoSize') - expect(getFileInfoSize).toEqual(78) - getFileInfoDigest = await getData('getFileInfoDigest') - expect(getFileInfoDigest).toEqual("4ac7a65055628818341c2ad86ddc4205d8503801") - - await btnReadFileButton.tap() - await isDone() - readFileRet = await getData('readFileRet') - expect(readFileRet).toEqual( - "GbAtywwibr7mDCeJDFxkxwx8AFAxAg4I4PYJH4pS7lIpAg3lKQqrGQzKFS9VdAIRMljOUrsMyFA8fImHDNgEDdzSAnceBAVxDFU8KLr0" - ) - - // 尝试写入合法ascii - await page.setData({ - writeFileContent: "hello jack.hello marry.", - writeFileEncoding: "ascii", - readFileEncoding: "ascii", - }) - - await btnWriteFileButton.tap() - await isDone() - - await btnReadFileButton.tap() - await isDone() - readFileRet = await getData('readFileRet') - expect(readFileRet).toEqual("hello jack.hello marry.") - - // 写入base64 获取 中文 - await page.setData({ - writeFileContent: "5LiZ6L6w5Lit56eL77yM5qyi6aWu6L6+5pem77yM5aSn6YaJ77yM5L2c5q2k56+H77yM5YW85oCA5a2Q55Sx44CC5piO5pyI5Yeg5pe25pyJ77yf5oqK6YWS6Zeu6Z2S5aSp44CC5LiN55+l5aSp5LiK5a6r6ZiZ77yM5LuK5aSV5piv5L2V5bm044CC5oiR5qyy5LmY6aOO5b2S5Y6777yM5Y+I5oGQ55C85qW8546J5a6H77yM6auY5aSE5LiN6IOc5a+S44CC6LW36Iie5byE5riF5b2x77yM5L2V5Ly85Zyo5Lq66Ze0", - writeFileEncoding: "base64", - readFileEncoding: "utf-8", - }) - - await btnWriteFileButton.tap() - await isDone() - - await btnReadFileButton.tap() - await isDone() - readFileRet = await getData('readFileRet') - expect(readFileRet).toEqual( - "丙辰中秋,欢饮达旦,大醉,作此篇,兼怀子由。明月几时有?把酒问青天。不知天上宫阙,今夕是何年。我欲乘风归去,又恐琼楼玉宇,高处不胜寒。起舞弄清影,何似在人间") - - await page.setData({ - readFileEncoding: "base64", - }) - - await btnReadFileButton.tap() - await isDone() - readFileRet = await getData('readFileRet') - expect(readFileRet).toEqual( - "5LiZ6L6w5Lit56eL77yM5qyi6aWu6L6+5pem77yM5aSn6YaJ77yM5L2c5q2k56+H77yM5YW85oCA5a2Q55Sx44CC5piO5pyI5Yeg5pe25pyJ77yf5oqK6YWS6Zeu6Z2S5aSp44CC5LiN55+l5aSp5LiK5a6r6ZiZ77yM5LuK5aSV5piv5L2V5bm044CC5oiR5qyy5LmY6aOO5b2S5Y6777yM5Y+I5oGQ55C85qW8546J5a6H77yM6auY5aSE5LiN6IOc5a+S44CC6LW36Iie5byE5riF5b2x77yM5L2V5Ly85Zyo5Lq66Ze0" - ) - - }); - - it('stat and asset test', async () => { - // 测试 USER_DATA_PATH //globalTempPath - let globalRootPath = await getData('globalRootPath') - - await page.setData({ - recursiveVal: true, - copyToBasePath: globalRootPath, - basePath: globalRootPath, - globalTempPath: globalRootPath, - rmDirFile: 'a', - mkdirFile: 'a', - unlinkFile: 'a/1.txt', - }) - - // 先清除文件,需要清除全部可能存在的历史测试文件,避免运行失败 - const btnUnLinkFileButton = await page.$('#btn-unlink-file') - await btnUnLinkFileButton.tap() - await isDone() - - await page.setData({ - unlinkFile: 'a/2.txt', - }) - await btnUnLinkFileButton.tap() - await isDone() - - await page.setData({ - unlinkFile: 'a/m/3.txt', - }) - await btnUnLinkFileButton.tap() - await isDone() - - // // 清除文件夹 - const btnRmDirButton = await page.$('#btn-remove-dir') - await btnRmDirButton.tap() - await isDone() - // // 重新创建测试目录 - const btnMkdDirButton = await page.$('#btn-mkdir') - await btnMkdDirButton.tap() - await isDone() - - const btnReadDirButton = await page.$('#btn-read-dir') - await btnReadDirButton.tap() - await isDone() - - - // 期望通过 recursive = true的 文件夹删除,得到一个空的 /a 目录 - let fileListComplete = await getData('fileListComplete') - expect(JSON.stringify(fileListComplete)).toEqual('[]') - let fileListSuccess = await getData('fileListSuccess') - expect(JSON.stringify(fileListSuccess)).toEqual('[]') - - // 写入一个文件 - await page.setData({ - writeFileContent: "锄禾日当午,汗滴禾下土,谁知盘中餐,粒粒皆辛苦", - writeFileEncoding: "utf-8", - writeFile: 'a/1.txt', - recursiveVal: false, - statFile: 'a/1.txt', - }) - - let lastFailError = await getData('lastFailError') - console.log(lastFailError) - - const btnWriteFileButton = await page.$('#btn-write-file') - await btnWriteFileButton.tap() - await isDone() - - let btnStatFileButton = await page.$('#btn-stat-file') - await btnStatFileButton.tap() - await isDone() - - // 读取单个文件信息 - let statsRet = await getData('statsRet') - expect(statsRet.length).toEqual(1) - expect(statsRet[0].path).toMatch(new RegExp('.*/a/1.txt$')) - expect(statsRet[0].stats.size).toEqual(69) - if (isAndroid()) { - // 写入一个文件 - await page.setData({ - statsRet: '' - }) - btnStatFileButton = await page.$('#btn-stat-file-sync') - await btnStatFileButton.tap() - await isDone() - - // 读取单个文件信息 - statsRet = await getData('statsRet') - expect(statsRet.length).toEqual(1) - expect(statsRet[0].path).toMatch(new RegExp('.*/a/1.txt$')) - expect(statsRet[0].stats.size).toEqual(69) - } - - /** - * 创建子目录和子目录文件,测试recursive参数 - */ - await page.setData({ - writeFileContent: "1234567890", - writeFileEncoding: "ascii", - writeFile: 'a/2.txt', - basePath: globalRootPath, - recursiveVal: false, - statFile: 'a', - mkdirFile: 'a/m', - }) - - - await btnWriteFileButton.tap() - await isDone() - - // 创建子目录 - await btnMkdDirButton.tap() - await isDone() - - // 复制一份文件到 /a/m/3.txt - await page.setData({ - // asset 只能正式版测试,这里只能模拟返回路径 - basePath: '', - copyFromFile: 'static/test-image/logo.ico', - copyToFile: 'a/m/3.txt', - }) - const btnCopyFileButton = await page.$('#btn-copy-file') - await btnCopyFileButton.tap() - await isDone() - - - await page.setData({ - basePath: globalRootPath, - recursiveVal: true, - statFile: 'a', - }) - - await btnStatFileButton.tap() - await isDone() - - // 读取全部文件信息 - statsRet = await getData('statsRet') - - statsRet.sort(function(a, b) { - if (a.path > b.path) { - return 1 - } else if (a.path < b.path) { - return -1 - } - return 0 - }) - console.log(statsRet) - expect(statsRet.length).toEqual(5) - expect(statsRet[0].path).toMatch(new RegExp('.*/a$')) - // expect(statsRet[0].stats.size).toEqual(0) - - expect(statsRet[2].path).toMatch(new RegExp('.*/a/2.txt$')) - expect(statsRet[2].stats.size).toEqual(10) - - expect(statsRet[4].path).toMatch(new RegExp('.*/a/m/3.txt$')) - expect(statsRet[4].stats.size).toEqual(156406) - - - // 清理文件,避免影响其他测试用例 - await page.setData({ - unlinkFile: 'a/1.txt', - }) - await btnUnLinkFileButton.tap() - await isDone() - - await page.setData({ - unlinkFile: 'a/2.txt', - }) - await btnUnLinkFileButton.tap() - await isDone() - - await page.setData({ - unlinkFile: 'a/m/3.txt', - rmDirFile: 'a', - readDir: 'a', - recursiveVal: true, - }) - await btnUnLinkFileButton.tap() - await isDone() - - await btnRmDirButton.tap() - await isDone() - - await btnReadDirButton.tap() - await isDone() - - // 期望通过 recursive = true的 文件夹删除,得到一个空的 /a 目录 - fileListComplete = await getData('fileListComplete') - expect(JSON.stringify(fileListComplete)).toEqual('[]') - fileListSuccess = await getData('fileListSuccess') - expect(JSON.stringify(fileListSuccess)).toEqual('[]') - - }); - it('appendFileTest', async () => { - if (!isAndroid()) { - return - } - - - let basePath = await getData('basePath') - - await page.setData({ - basePath: mBasePath, - recursiveVal: true, - logAble: false, - rmDirFile: 'appendfile', - mkdirFile: 'appendfile', - writeFileContent: "我爱北京天安门,天安门前太阳升", - appendFileContent: "再说一遍", - writeFileEncoding: "utf-8", - readFileEncoding: "utf-8", - readFile: 'appendfile/appendfile.txt', - unlinkFile: 'appendfile/appendfile.txt', - writeFile: 'appendfile/appendfile.txt', - }) - - // 先清除文件,需要清除全部可能存在的历史测试文件,避免运行失败 - const btnUnLinkFileButton = await page.$('#btn-unlink-file') - await btnUnLinkFileButton.tap() - await isDone() - - // 清除文件夹 - const btnRmDirButton = await page.$('#btn-remove-dir') - await btnRmDirButton.tap() - await isDone() - - // 重新创建测试目录,期望通过 recursive = true的 文件夹删除,得到一个空的 /a 目录 - const btnMkdDirButton = await page.$('#btn-mkdir') - await btnMkdDirButton.tap() - await isDone() - - // 先用utf-8 写入内容 - const btnWriteFileButton = await page.$('#btn-write-file') - - await btnWriteFileButton.tap() - await isDone() - - - //追加内容 - const btnAppendFileButton = await page.$('#btn-append-file') - await btnAppendFileButton.tap() - await isDone() - - const btnReadFileButton = await page.$('#btn-read-file') - await btnReadFileButton.tap() - await isDone() - let readFileRet = await getData('readFileRet') - expect(readFileRet).toEqual("我爱北京天安门,天安门前太阳升再说一遍") - }); - //nlinkSyncTest mkdirSyncTest appendFileTest writeFileSyncTest readFileSyncTest rmdirSyncTest readDirSyncTest accessFileSyncTest - //renameFileSync copyFileSyncTest appendFileSyncTest truncateFileTest truncateFileSyncTest - it('sync test', - async () => { - if (!isAndroid()) { - return - } - - - await page.setData({ - basePath: mBasePath, - recursiveVal: false, - logAble: false, - rmDirFile: 'sync', - mkdirFile: 'sync', - writeFileContent: "我爱北京天安门,天安门前太阳升", - appendFileContent: "再说一遍", - writeFileEncoding: "utf-8", - readFileEncoding: "utf-8", - readDir: 'sync', - rmDirFile: 'sync', - unlinkFile: 'sync/sync.txt', - readFile: 'sync/sync.txt', - writeFile: 'sync/sync.txt', - accessFile: 'sync/sync.txt', - renameToFile: 'sync/sync.txt', - renameFromFile: 'sync/sync.txt', - }) - await clearDir('sync') - // 重新创建测试目录,期望通过 recursive = true的 文件夹删除,得到一个空的 目录 - const btnMkdDirButton = await page.$('#btn-mkdir-sync') - await btnMkdDirButton.tap() - await isDone() - - const btnReadDirButton = await page.$('#btn-read-dir-sync') - await btnReadDirButton.tap() - await isDone() - const fileListSuccess = await getData('fileListSuccess') - expect(JSON.stringify(fileListSuccess)).toEqual('[]') - - // 先用utf-8 写入内容 - const btnWriteFileButton = await page.$('#btn-write-file-sync') - await btnWriteFileButton.tap() - await isDone() - - let btnAccessFileButton = await page.$('#btn-access-file-sync') - await btnAccessFileButton.tap() - await isDone() - let accessFileRet = await getData("accessFileRet") - expect(accessFileRet).toEqual('access:ok') - - //重新命名文件 - const btnRenameFileButton = await page.$('#btn-rename-file-sync') - await btnRenameFileButton.tap() - await isDone() - let renameFileRet = await getData("renameFileRet") - expect(renameFileRet).toEqual("rename:ok") - - - //追加内容 - let btnAppendFileButton = await page.$('#btn-append-file') - await btnAppendFileButton.tap() - await isDone() - - btnAppendFileButton = await page.$('#btn-append-file-sync') - await btnAppendFileButton.tap() - - - let btnReadFileButton = await page.$('#btn-read-file-sync') - await btnReadFileButton.tap() - await isDone() - let readFileRet = await getData('readFileRet') - expect(readFileRet).toEqual("我爱北京天安门,天安门前太阳升再说一遍再说一遍") - - //truncateFileTest - let btnTruncateFile = await page.$('#btn-truncate-file') - await btnTruncateFile.tap() - await isDone() - btnReadFileButton = await page.$('#btn-read-file-sync') - await btnReadFileButton.tap() - await isDone() - readFileRet = await getData('readFileRet') - expect(readFileRet).toEqual("我爱北京天安门") - - btnTruncateFile = await page.$('#btn-truncate-file-sync') - await btnTruncateFile.tap() - await isDone() - btnReadFileButton = await page.$('#btn-read-file-sync') - await btnReadFileButton.tap() - await isDone() - readFileRet = await getData('readFileRet') - expect(readFileRet).toEqual("我爱北京") - - - // 测试 copyfile - await page.setData({ - basePath: mBasePath, - copyToBasePath: mBasePath, - copyFromFile: "sync/sync.txt", - copyToFile: "sync/syncto.txt", - accessFile: "sync/syncto.txt" - }) - const btnCopyFileButton = await page.$('#btn-copy-file-sync') - await btnCopyFileButton.tap() - await isDone() - btnAccessFileButton = await page.$('#btn-access-file-sync') - await btnAccessFileButton.tap() - await isDone() - accessFileRet = await getData("accessFileRet") - expect(accessFileRet).toEqual('access:ok') - - await clearDir('sync') - }); - - async function createFile() { - // 重新创建测试目录,期望通过 recursive = true的 文件夹删除,得到一个空的 目录 - const btnMkdDirButton = await page.$('#btn-mkdir-sync') - await btnMkdDirButton.tap() - await isDone() - - // 先用utf-8 写入内容 - const btnWriteFileButton = await page.$('#btn-write-file-sync') - await btnWriteFileButton.tap() - await isDone() - } - - async function clearDir(dir) { - // 最后需要清楚所有文件避免测试失败 - await page.setData({ - rmDirFile: dir, - }) - const btnUnLinkFileButton = await page.$('#btn-clear-file') - await btnUnLinkFileButton.tap() - await isDone() - - const btnClear = await page.$('#btn-remove-dir') - await btnClear.tap() - await isDone() - } - - function isAndroid() { - if (process.env.uniTestPlatformInfo.indexOf('web') > -1 || process.env.UNI_AUTOMATOR_APP_WEBVIEW === 'true') { - expect(1).toBe(1) - return false - } - if (process.env.uniTestPlatformInfo.toLocaleLowerCase().startsWith('ios')) { - expect(1).toBe(1) - return false - } - return true - } - - it('getSavedFileListTest', - async () => { - if (!isAndroid()) { - return - } - // await page.setData({ - // logAble: false, - // basePath: mBasePath - // }) - // console.log('getSavedFileListTest', 'start') - // await clearDir('') - // console.log('getSavedFileListTest', 'end') - await page.setData({ - logAble: false, - basePath: mGlobalTempPath, - temFile: 'save3/2.txt', - mkdirFile: 'save3', - writeFile: 'save3/2.txt', - accessFile: '2.txt' - }) - await createFile() - await page.setData({ - basePath: mBasePath, - writeFile: 'save/2.txt', - }) - btnSaveFile = await page.$('#btn-save-file-sync') - await btnSaveFile.tap() - await isDone() - let btnSavedFileList = await page.$('#btn-getsaved-filelist') - await btnSavedFileList.tap() - await isDone() - let getSavedFileListRet = await getData("getSavedFileListRet") - console.log('getSavedFileListTest->' + getSavedFileListRet) - expect(getSavedFileListRet).toEqual('getSavedFileList:ok') - }); - - it('removeSavedFileTest', - async () => { - if (!isAndroid()) { - return - } - await page.setData({ - logAble: false, - basePath: mBasePath - }) - await clearDir('save4') - await page.setData({ - logAble: false, - basePath: mGlobalTempPath, - temFile: 'save4/saveSync.txt', - mkdirFile: 'save4', - writeFile: 'save4/saveSync.txt', - accessFile: 'saveSync.txt' - }) - await createFile() - let btnRemoveSavedFileRet = await page.$('#btn-remove-saved-file') - await btnRemoveSavedFileRet.tap() - await isDone() - let removeSavedFileRet = await getData("removeSavedFileRet") - expect(removeSavedFileRet).toEqual('removeSavedFile:ok') - - }); - - //openFiletest openFileSynctest closeTest closeTestSync writeTest writeSyncTest - it('openFiletest', async () => { - if (!isAndroid()) { - return - } - - await page.setData({ - basePath: mBasePath, - logAble: false, - mkdirFile: 'fd', - writeFile: 'fd/1.txt', - readFile: 'fd/1.txt' - }) - await clearDir('fd') - await createFile() - console.log('openFiletest', '2') - //openFiletest - let btnOpenFile = await page.$('#btn-open-file') - await btnOpenFile.tap() - await isDone() - let fd = await getData("fd") - expect(fd).not.toBe(''); - await page.setData({ - fd: '', - }) - console.log('openFiletest', '3') - //openFileSynctest - btnOpenFile = await page.$('#btn-open-file-sync') - await btnOpenFile.tap() - await isDone() - fd = await getData("fd") - expect(fd).not.toBe(''); - console.log('openFiletest', '4') - }); - // closeTest closeTestSync - it('closeTest', async () => { - if (!isAndroid()) { - return - } - - - - await page.setData({ - basePath: mBasePath, - logAble: false, - mkdirFile: 'fd', - writeFile: 'fd/1.txt', - readFile: 'fd/1.txt' - }) - await clearDir('fd') - await createFile() - //closeTest - let btnCloseFile = await page.$('#btn-close-file') - await btnCloseFile.tap() - await isDone() - let closeFileRet = await getData("closeFileRet") - expect(closeFileRet).toEqual('close:ok') - await page.setData({ - closeFileRet: '', - }) - //closeTestSync - btnCloseFile = await page.$('#btn-close-file-sync') - await btnCloseFile.tap() - await isDone() - closeFileRet = await getData("closeFileRet") - expect(closeFileRet).toEqual('close:ok') - - }); - //writeTest writeSyncTest - it('writeTest', async () => { - if (!isAndroid()) { - return - } - console.log('writeTest', 'start') - - await page.setData({ - basePath: mBasePath, - logAble: false, - mkdirFile: 'fd', - writeFile: 'fd/1.txt', - readFile: 'fd/1.txt', - writeData: '我是一只小小鸟' - }) - await clearDir('fd') - await createFile() - console.log('writeTest', '1') - let btnWrite = await page.$('#btn-write') - await btnWrite.tap() - await isDone() - let bytesWritten = await getData("bytesWritten") - let lastFailError = await getData("lastFailError") - if(bytesWritten != 7){ - let writeData = await getData("writeData") - console.log('writeTest',lastFailError.errCode,lastFailError.errMsg,bytesWritten,writeData) - } - - expect(bytesWritten).toEqual(7) - console.log('writeTest', '2') - //writeSyncTest - await page.setData({ - writeFile: 'fd/1.txt', - readFile: 'fd/1.txt', - writeData: '我是' - }) - - btnWrite = await page.$('#btn-write-sync') - await btnWrite.tap() - await isDone() - bytesWritten = await getData("bytesWritten") - expect(bytesWritten).toEqual(2) - console.log('writeTest', '3') - //fstatTest - let btnFstat = await page.$('#btn-fstat-file') - await btnFstat.tap() - await isDone() - let fstat = await getData("fstat") - expect(fstat.size > 0).toBe(true) - console.log('writeTest', '4') - - //fstatSyncTest - btnFstat = await page.$('#btn-fstat-file-sync') - await btnFstat.tap() - await isDone() - fstat = await getData("fstat") - expect(fstat.size > 0).toBe(true) - console.log('writeTest', '5') - - //ftruncateFileTest - let btnFTruncateFile = await page.$('#btn-ftruncate-file') - await btnFTruncateFile.tap() - await isDone() - let ftruncateRet = await getData("ftruncateRet") - expect(fstat).not.toEqual('ftruncate:ok') - await page.setData({ - ftruncate: '', - }) - console.log('writeTest', '6') - - //ftruncateFileSyncTest - btnFTruncateFile = await page.$('#btn-ftruncate-file-sync') - await btnFTruncateFile.tap() - await isDone() - ftruncateRet = await getData("ftruncateRet") - expect(fstat).not.toEqual('ftruncate:ok') - console.log('writeTest', '7') - }); - //writeTest writeSyncTest - it('ftruncateFileTest', async () => { - if (!isAndroid()) { - return - } - console.log('ftruncateFileTest', 'start') - - await page.setData({ - basePath: mBasePath, - logAble: false, - mkdirFile: 'fd', - writeFile: 'fd/1.txt', - readFile: 'fd/1.txt', - writeData: '我是一只小小鸟我是' - }) - await clearDir('fd') - await createFile() - console.log('ftruncateFileTest', '1') - btnWrite = await page.$('#btn-write-sync') - await btnWrite.tap() - await isDone() - bytesWritten = await getData("bytesWritten") - expect(bytesWritten).toEqual(9) - console.log('ftruncateFileTest', '3') - //ftruncateFileTest - let btnFTruncateFile = await page.$('#btn-ftruncate-file') - await btnFTruncateFile.tap() - await isDone() - let ftruncateRet = await getData("ftruncateRet") - expect(ftruncateRet).toEqual('ftruncate:ok') - await page.setData({ - ftruncate: '', - }) - console.log('ftruncateFileTest', '6') - - //ftruncateFileSyncTest - btnFTruncateFile = await page.$('#btn-ftruncate-file-sync') - await btnFTruncateFile.tap() - await isDone() - ftruncateRet = await getData("ftruncateRet") - expect(ftruncateRet).toEqual('ftruncate:ok') - console.log('ftruncateFileTest', '7') - }); + if (process.env.uniTestPlatformInfo.indexOf('web') > -1 || process.env.UNI_AUTOMATOR_APP_WEBVIEW == + 'true') { + it('dummyTest', () => { + expect(1).toBe(1) + }) + return + } + let page; + let mBasePath; + let mGlobalTempPath; + let mGlobalRootPath + + + function getData(key = '') { + return new Promise(async (resolve, reject) => { + const data = await page.data() + resolve(key ? data[key] : data) + }) + } + + + beforeAll(async () => { + page = await program.reLaunch(PAGE_PATH) + await page.waitFor(600); + }); + + async function isDone() { + let isDone = await page.waitFor(async () => { + return await page.data('done') + }) + await page.setData({ + done: false + }) + return isDone + } + + it('USER_DATA_PATH test', async () => { + // 测试 USER_DATA_PATH + let globalUserDataPath = await getData('globalUserDataPath') + mBasePath = await getData('basePath') + mGlobalRootPath = await getData('globalRootPath') + mGlobalTempPath = await getData('globalTempPath') + + await page.setData({ + logAble: false, + recursiveVal: true, + copyToBasePath: globalUserDataPath, + basePath: globalUserDataPath, + rmDirFile: 'a', + readDir: 'a', + writeFile: 'a/1.txt', + readFile: 'a/1.txt', + unlinkFile: 'a/1.txt', + writeFileContent: '锄禾日当午,汗滴禾下土,谁知盘中餐,粒粒皆辛苦' + }) + + // 先清除文件,需要清除全部可能存在的历史测试文件,避免运行失败 + const btnUnLinkFileButton = await page.$('#btn-clear-file') + await btnUnLinkFileButton.tap() + await isDone() + + + // 清除文件夹 + const btnRmDirButton = await page.$('#btn-remove-dir') + await btnRmDirButton.tap() + await isDone() + // 重新创建测试目录 + const btnMkdDirButton = await page.$('#btn-mkdir') + await btnMkdDirButton.tap() + await isDone() + + const btnReadDirButton = await page.$('#btn-read-dir') + await btnReadDirButton.tap() + await isDone() + + + // 期望通过 recursive = true的 文件夹删除,得到一个空的 /a 目录 + let fileListComplete = await getData('fileListComplete') + expect(JSON.stringify(fileListComplete)).toEqual('[]') + let fileListSuccess = await getData('fileListSuccess') + expect(JSON.stringify(fileListSuccess)).toEqual('[]') + + // 先测试 recursive = false 文件夹创建,期望失败 + await page.setData({ + recursiveVal: false, + mkdirFile: 'a/b/c' + }) + + + await btnMkdDirButton.tap() + await isDone() + + + let lastFailError = await getData('lastFailError') + expect(lastFailError.errCode).toEqual(1300002) + expect(lastFailError.errMsg).toEqual('no such file or directory') + let lastCompleteError = await getData('lastCompleteError') + expect(lastCompleteError.errCode).toEqual(1300002) + expect(lastCompleteError.errMsg).toEqual('no such file or directory') + + + // 测试 recursive = true 期望文件夹创建成功 + await page.setData({ + recursiveVal: true + }) + await btnMkdDirButton.tap() + await isDone() + + await btnReadDirButton.tap() + await isDone() + + // 期望通过 recursive = true的 文件夹删除,得到一个空的 /a 目录 + fileListComplete = await getData('fileListComplete') + expect(JSON.stringify(fileListComplete)).toEqual("[\"b\"]") + fileListSuccess = await getData('fileListSuccess') + expect(JSON.stringify(fileListSuccess)).toEqual("[\"b\"]") + + // 测试写入文件 + const btnWriteFileButton = await page.$('#btn-write-file') + await btnWriteFileButton.tap() + await isDone() + // 检查目录列表数量 + await btnReadDirButton.tap() + await isDone() + fileListComplete = await getData('fileListComplete') + fileListComplete.sort() + expect(JSON.stringify(fileListComplete)).toEqual("[\"1.txt\",\"b\"]") + fileListSuccess = await getData('fileListSuccess') + fileListSuccess.sort() + expect(JSON.stringify(fileListSuccess)).toEqual("[\"1.txt\",\"b\"]") + // 获取和对比 文件内容 + const btnReadFileButton = await page.$('#btn-read-file') + await btnReadFileButton.tap() + await isDone() + let readFileRet = await getData('readFileRet') + expect(readFileRet).toEqual("锄禾日当午,汗滴禾下土,谁知盘中餐,粒粒皆辛苦") + + // 更换文件内容 获取和对比 文件md5和sha1 + await page.setData({ + writeFileContent: "If you were a teardrop;In my eye,For fear of losing you,I would never cry.And if the golden sun,Should cease to shine its light,Just one smile from you,Would make my whole world bright.", + getFileInfoAlgorithm: "md5" + }) + await btnWriteFileButton.tap() + await isDone() + + await btnReadFileButton.tap() + await isDone() + readFileRet = await getData('readFileRet') + expect(readFileRet).toEqual( + "If you were a teardrop;In my eye,For fear of losing you,I would never cry.And if the golden sun,Should cease to shine its light,Just one smile from you,Would make my whole world bright." + ) + + const btnGetFileInfoButton = await page.$('#btn-get-file-info') + await btnGetFileInfoButton.tap() + await isDone() + + let getFileInfoSize = await getData('getFileInfoSize') + expect(getFileInfoSize).toEqual(185) + let getFileInfoDigest = await getData('getFileInfoDigest') + expect(getFileInfoDigest).toEqual("29ddd02ed3c38ccebb98884eda082cb1") + // 切换为 sha1 + await page.setData({ + getFileInfoAlgorithm: "sha1" + }) + + await btnGetFileInfoButton.tap() + await isDone() + + getFileInfoSize = await getData('getFileInfoSize') + expect(getFileInfoSize).toEqual(185) + getFileInfoDigest = await getData('getFileInfoDigest') + expect(getFileInfoDigest).toEqual("ebef4e75783e0db499fc260d120e695005bead8a") + + // 测试 copyfile + await page.setData({ + + copyFromFile: "a/1.txt", + copyToFile: "a/2.txt" + }) + const btnCopyFileButton = await page.$('#btn-copy-file') + await btnCopyFileButton.tap() + await isDone() + + + await btnReadDirButton.tap() + await isDone() + + // 1.txt 2.txt 两个文件都存在 + fileListComplete = await getData('fileListComplete') + fileListComplete.sort() + expect(JSON.stringify(fileListComplete)).toEqual("[\"1.txt\",\"2.txt\",\"b\"]") + fileListSuccess = await getData('fileListSuccess') + fileListSuccess.sort() + expect(JSON.stringify(fileListSuccess)).toEqual("[\"1.txt\",\"2.txt\",\"b\"]") + + // 测试 rename + await page.setData({ + renameFromFile: "a/2.txt", + renameToFile: "a/3.txt" + }) + + const btnRenameFileButton = await page.$('#btn-rename-file') + await btnRenameFileButton.tap() + await isDone() + + await btnReadDirButton.tap() + await isDone() + + // 1.txt 3.txt 两个文件都存在 + fileListComplete = await getData('fileListComplete') + fileListComplete.sort() + expect(JSON.stringify(fileListComplete)).toEqual("[\"1.txt\",\"3.txt\",\"b\"]") + fileListSuccess = await getData('fileListSuccess') + fileListSuccess.sort() + expect(JSON.stringify(fileListSuccess)).toEqual("[\"1.txt\",\"3.txt\",\"b\"]") + }); + + it('TEMP_PATH test', async () => { + // 测试 TEMP_PATH + let globalTempPath = await getData('globalTempPath') + + let version = process.env.uniTestPlatformInfo + version = parseInt(version.split(" ")[1]) + let testDirName = "我们经历了一场兵慌马乱的战争.1@2#3$4%5^6&7*8(9)0+-qwertyuiopasdfghjklzxcvbnm;," + if (version < 6) { + // android 6 以下文件名不能包含特殊字符 + testDirName = "我们经历了一场兵慌马乱的战争" + } + + await page.setData({ + logAble: false, + recursiveVal: true, + basePath: globalTempPath, + copyToBasePath: globalTempPath, + rmDirFile: 'a', + mkdirFile: 'a', + unlinkFile: 'a/' + testDirName + '/中文路径/张三/name/中文文件.mock' + }) + + + // 先清除文件,需要清除全部可能存在的历史测试文件,避免运行失败 + const btnUnLinkFileButton = await page.$('#btn-unlink-file') + await btnUnLinkFileButton.tap() + await isDone() + + + // 清除文件夹 + const btnRmDirButton = await page.$('#btn-remove-dir') + await btnRmDirButton.tap() + await isDone() + + // 重新创建测试目录 + const btnMkdDirButton = await page.$('#btn-mkdir') + await btnMkdDirButton.tap() + await isDone() + + const btnReadDirButton = await page.$('#btn-read-dir') + await btnReadDirButton.tap() + await isDone() + + + // 期望通过 recursive = true的 文件夹删除,得到一个空的 /a 目录 + let fileListComplete = await getData('fileListComplete') + expect(JSON.stringify(fileListComplete)).toEqual("[]") + let fileListSuccess = await getData('fileListSuccess') + expect(JSON.stringify(fileListSuccess)).toEqual("[]") + + // 测试 创建多层级文件目录 + await page.setData({ + recursiveVal: true, + mkdirFile: 'a/b/c/d/e/f/g/h/i/g/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z/中文路径/张三/test', + }) + + await btnMkdDirButton.tap() + await isDone() + + await btnReadDirButton.tap() + await isDone() + + fileListComplete = await getData('fileListComplete') + expect(JSON.stringify(fileListComplete)).toEqual("[\"b\"]") + fileListSuccess = await getData('fileListSuccess') + expect(JSON.stringify(fileListSuccess)).toEqual("[\"b\"]") + + // 测试 创建包含中文特殊符号的目录 + await page.setData({ + recursiveVal: true, + mkdirFile: 'a/' + testDirName + '/中文路径/张三/name', + }) + await btnMkdDirButton.tap() + await isDone() + + await btnReadDirButton.tap() + await isDone() + + // 期望通过 recursive = true的 文件夹删除,得到一个空的 /a 目录 + fileListComplete = await getData('fileListComplete') + fileListComplete.sort() + expect(JSON.stringify(fileListComplete)).toEqual("[\"b\",\"" + testDirName + "\"]") + fileListSuccess = await getData('fileListSuccess') + fileListSuccess.sort() + expect(JSON.stringify(fileListSuccess)).toEqual("[\"b\",\"" + testDirName + "\"]") + + /** + * 从资源文件中读取图片为base64,测试写入较大文件场景 + * 'static/test-image/logo.ico' 注意,依赖这个资源文件,不能删除 + */ + await page.setData({ + basePath: "", + readFile: 'static/test-image/logo.ico', + readFileEncoding: 'base64' + }) + + + // 获取和对比 文件内容 + const btnReadFileButton = await page.$('#btn-read-file') + await btnReadFileButton.tap() + await isDone() + let readFileRet = await getData('readFileRet') + expect(readFileRet.length).toEqual(208544) + let endStr = readFileRet.substring(readFileRet.length - 10) + expect(endStr).toEqual("///////w==") + + await page.setData({ + basePath: globalTempPath, + writeFile: 'a/' + testDirName + '/中文路径/张三/name/中文文件.mock', + writeFileContent: readFileRet + }) + + + const btnWriteFileButton = await page.$('#btn-write-file') + await btnWriteFileButton.tap() + await isDone() + + // 获取文件列表,判断是否写入成功,同时置空base64内容 避免影响实时查看状态 + await page.setData({ + readDir: 'a/' + testDirName + '/中文路径/张三/name', + readFileRet: '', + writeFileContent: '' + }) + + // 检查目录列表数量 + await btnReadDirButton.tap() + await isDone() + fileListComplete = await getData('fileListComplete') + expect(JSON.stringify(fileListComplete)).toEqual("[\"中文文件.mock\"]") + fileListSuccess = await getData('fileListSuccess') + expect(JSON.stringify(fileListSuccess)).toEqual("[\"中文文件.mock\"]") + + + // 更换文件内容 获取和对比 文件md5和sha1 + await page.setData({ + getFileInfoFile: 'a/' + testDirName + '/中文路径/张三/name/中文文件.mock', + getFileInfoAlgorithm: "md5", + }) + + const btnGetFileInfoButton = await page.$('#btn-get-file-info') + await btnGetFileInfoButton.tap() + await isDone() + + let getFileInfoSize = await getData('getFileInfoSize') + expect(getFileInfoSize).toEqual(208544) + let getFileInfoDigest = await getData('getFileInfoDigest') + expect(getFileInfoDigest).toEqual("486f75ea76625f8c103cac4bc9c49511") + + // 切换为 sha1 + await page.setData({ + getFileInfoAlgorithm: "sha1" + }) + + await btnGetFileInfoButton.tap() + await isDone() + + getFileInfoSize = await getData('getFileInfoSize') + expect(getFileInfoSize).toEqual(208544) + getFileInfoDigest = await getData('getFileInfoDigest') + expect(getFileInfoDigest).toEqual("1830169a16e7c860beff4a3b0975ba0b6f775f9e") + + // 测试不支持的摘要算法,期望返回错误 + await page.setData({ + getFileInfoAlgorithm: "sha256" + }) + + await btnGetFileInfoButton.tap() + await isDone() + + let lastFailError = await getData('lastFailError') + expect(lastFailError.errCode).toEqual(1300022) + let lastCompleteError = await getData('lastCompleteError') + expect(lastCompleteError.errCode).toEqual(1300022) + + + // rename 到一个没有提前创建过的目录,期望返回错误 + await page.setData({ + renameFromFile: "a/" + testDirName + "/中文路径/张三/name/中文文件.mock", + renameToFile: "a/没有提前创建的目录/3.txt" + }) + + const btnRenameFileButton = await page.$('#btn-rename-file') + await btnRenameFileButton.tap() + await isDone() + + lastFailError = await getData('lastFailError') + expect(lastFailError.errCode).toEqual(1300002) + lastCompleteError = await getData('lastCompleteError') + expect(lastCompleteError.errCode).toEqual(1300002) + + // 非递归创建一级目录。期望成功 + await page.setData({ + recursiveVal: false, + mkdirFile: 'a/提前创建的目录', + }) + + await btnMkdDirButton.tap() + await isDone() + + await page.setData({ + readDir: 'a', + }) + + await btnReadDirButton.tap() + await isDone() + + fileListComplete = await getData('fileListComplete') + fileListComplete.sort() + expect(JSON.stringify(fileListComplete)).toEqual("[\"b\",\"" + testDirName + + "\",\"提前创建的目录\"]") + fileListSuccess = await getData('fileListSuccess') + fileListSuccess.sort() + expect(JSON.stringify(fileListSuccess)).toEqual("[\"b\",\"" + testDirName + + "\",\"提前创建的目录\"]") + + + await page.setData({ + copyFromFile: "a/" + testDirName + "/中文路径/张三/name/中文文件.mock", + copyToFile: "a/提前创建的目录/4.txt" + }) + + const btnCopyFileButton = await page.$('#btn-copy-file') + await btnCopyFileButton.tap() + await isDone() + + await page.setData({ + readDir: 'a/提前创建的目录', + }) + + await btnReadDirButton.tap() + await isDone() + + fileListComplete = await getData('fileListComplete') + expect(JSON.stringify(fileListComplete)).toEqual("[\"4.txt\"]") + fileListSuccess = await getData('fileListSuccess') + expect(JSON.stringify(fileListSuccess)).toEqual("[\"4.txt\"]") + + await page.setData({ + unlinkFile: 'a/提前创建的目录/4.txt', + rmDirFile: 'a/提前创建的目录' + }) + await btnUnLinkFileButton.tap() + await isDone() + + await btnReadDirButton.tap() + await isDone() + + fileListComplete = await getData('fileListComplete') + expect(JSON.stringify(fileListComplete)).toEqual("[]") + fileListSuccess = await getData('fileListSuccess') + expect(JSON.stringify(fileListSuccess)).toEqual("[]") + + }); + + + + it('CROSS DIR test', async () => { + /** + * 跨越用户目录和代码资源目录 + */ + let globalRootPath = await getData('globalRootPath') + await page.setData({ + recursiveVal: true, + logAble: false, + basePath: globalRootPath, + readDir: 'a', + rmDirFile: 'a', + mkdirFile: 'a', + accessFile: 'a/从代码目录拷贝的资源.png', + unlinkFile: 'a/从代码目录拷贝的资源.png' + }) + + + // 先清除文件,需要清除全部可能存在的历史测试文件,避免运行失败 + const btnClearFileButton = await page.$('#btn-clear-file') + await btnClearFileButton.tap() + await isDone() + + + // 清除文件夹 + const btnRmDirButton = await page.$('#btn-remove-dir') + await btnRmDirButton.tap() + await isDone() + + // 重新创建测试目录,期望通过 recursive = true的 文件夹删除,得到一个空的 /a 目录 + const btnMkdDirButton = await page.$('#btn-mkdir') + await btnMkdDirButton.tap() + await isDone() + + const btnReadDirButton = await page.$('#btn-read-dir') + await btnReadDirButton.tap() + await isDone() + + let fileListComplete = await getData('fileListComplete') + expect(JSON.stringify(fileListComplete)).toEqual('[]') + let fileListSuccess = await getData('fileListSuccess') + expect(JSON.stringify(fileListSuccess)).toEqual('[]') + + + // 检查资源文件,此时不存在 + const btnAccessFileButton = await page.$('#btn-access-file') + await btnAccessFileButton.tap() + await isDone() + + let accessFileRet = await getData("accessFileRet") + expect(accessFileRet).toEqual('') + + + // 准备从资源目录拷贝png + await page.setData({ + basePath: "", + unlinkFile: 'static/test-image/logo.ico', + accessFile: 'static/test-image/logo.ico', + }) + // 检查资源文件,期望存在 + await btnAccessFileButton.tap() + await isDone() + + accessFileRet = await getData("accessFileRet") + expect(accessFileRet).toEqual('access:ok') + + // 尝试删除资源,期望失败 + const btnUnLinkFileButton = await page.$('#btn-unlink-file') + await btnUnLinkFileButton.tap() + await isDone() + + await btnAccessFileButton.tap() + await isDone() + + accessFileRet = await getData("accessFileRet") + expect(accessFileRet).toEqual('access:ok') + // 复制资源到 root目录 + await page.setData({ + copyToBasePath: globalRootPath, + copyFromFile: "static/test-image/logo.ico", + copyToFile: "a/从代码目录拷贝的资源.png" + }) + const btnCopyFileButton = await page.$('#btn-copy-file') + await btnCopyFileButton.tap() + await isDone() + + // 检查期望 root 目录中图片文件存在 + await page.setData({ + basePath: globalRootPath, + unlinkFile: 'a/从代码目录拷贝的资源.png', + accessFile: 'a/从代码目录拷贝的资源.png', + rmDirFile: 'a', + }) + await btnAccessFileButton.tap() + await isDone() + + accessFileRet = await getData("accessFileRet") + expect(accessFileRet).toEqual('access:ok') + + await btnUnLinkFileButton.tap() + await isDone() + + await btnAccessFileButton.tap() + await isDone() + + accessFileRet = await getData("accessFileRet") + expect(accessFileRet).toEqual('') + + // 从页面的按钮触发一次文件复制 + const btnCopyStaticFileButton = await page.$('#btn-copyStatic-file') + await btnCopyStaticFileButton.tap() + await isDone() + + await btnReadDirButton.tap() + await isDone() + + fileListComplete = await getData('fileListComplete') + expect(JSON.stringify(fileListComplete)).toEqual("[\"mock.json\"]") + fileListSuccess = await getData('fileListSuccess') + expect(JSON.stringify(fileListSuccess)).toEqual("[\"mock.json\"]") + + // 从页面的按钮触发一次文件清空 + await btnClearFileButton.tap() + await isDone() + + await btnReadDirButton.tap() + await isDone() + + fileListComplete = await getData('fileListComplete') + expect(JSON.stringify(fileListComplete)).toEqual("[]") + fileListSuccess = await getData('fileListSuccess') + expect(JSON.stringify(fileListSuccess)).toEqual("[]") + + }); + + + it('write and read', async () => { + /** + * 测试writefile readfile 各个参数是否符合预期 + */ + let globalTempPath = await getData('globalTempPath') + await page.setData({ + recursiveVal: true, + logAble: false, + basePath: globalTempPath, + readDir: 'd', + rmDirFile: 'd', + mkdirFile: 'd', + writeFileContent: "我爱北京天安门,天安门前太阳升", + writeFileEncoding: "utf-8", + readFileEncoding: "utf-8", + unlinkFile: 'd/write.bing', + writeFile: 'd/write.bing', + readFile: 'd/write.bing', + getFileInfoFile: 'd/write.bing', + getFileInfoAlgorithm: "sha1" + }) + + // 先清除文件,需要清除全部可能存在的历史测试文件,避免运行失败 + const btnUnLinkFileButton = await page.$('#btn-unlink-file') + await btnUnLinkFileButton.tap() + await isDone() + + // 清除文件夹 + const btnRmDirButton = await page.$('#btn-remove-dir') + await btnRmDirButton.tap() + await isDone() + + // 重新创建测试目录,期望通过 recursive = true的 文件夹删除,得到一个空的 /a 目录 + const btnMkdDirButton = await page.$('#btn-mkdir') + await btnMkdDirButton.tap() + await isDone() + + const btnReadDirButton = await page.$('#btn-read-dir') + await btnReadDirButton.tap() + await isDone() + + let fileListComplete = await getData('fileListComplete') + expect(JSON.stringify(fileListComplete)).toEqual('[]') + let fileListSuccess = await getData('fileListSuccess') + expect(JSON.stringify(fileListSuccess)).toEqual('[]') + + // 先用utf-8 写入内容 + const btnWriteFileButton = await page.$('#btn-write-file') + await btnWriteFileButton.tap() + await isDone() + + const btnReadFileButton = await page.$('#btn-read-file') + await btnReadFileButton.tap() + await isDone() + let readFileRet = await getData('readFileRet') + expect(readFileRet).toEqual("我爱北京天安门,天安门前太阳升") + + const btnGetFileInfoButton = await page.$('#btn-get-file-info') + await btnGetFileInfoButton.tap() + await isDone() + + let getFileInfoSize = await getData('getFileInfoSize') + expect(getFileInfoSize).toEqual(45) + let getFileInfoDigest = await getData('getFileInfoDigest') + expect(getFileInfoDigest).toEqual("2ae9c7672ff6c1e7c7e6a0bb4e74a6f06b39350b") + + // 尝试读取base64 信息 + await page.setData({ + readFileEncoding: "base64", + }) + + await btnReadFileButton.tap() + await isDone() + readFileRet = await getData('readFileRet') + expect(readFileRet).toEqual("5oiR54ix5YyX5Lqs5aSp5a6J6Zeo77yM5aSp5a6J6Zeo5YmN5aSq6Ziz5Y2H") + // 测试ascii,需要特别测试 ascii 写入非法字符的情况,因为微信的常量字符编码和android原生有差异。 + + await page.setData({ + writeFileContent: "丙辰中秋,欢饮达旦,大醉,作此篇,兼怀子由。明月几时有?把酒问青天。不知天上宫阙,今夕是何年。我欲乘风归去,又恐琼楼玉宇,高处不胜寒。起舞弄清影,何似在人间", + writeFileEncoding: "ascii", + readFileEncoding: "base64", + }) + + await btnWriteFileButton.tap() + await isDone() + + await btnGetFileInfoButton.tap() + await isDone() + + getFileInfoSize = await getData('getFileInfoSize') + expect(getFileInfoSize).toEqual(78) + getFileInfoDigest = await getData('getFileInfoDigest') + expect(getFileInfoDigest).toEqual("4ac7a65055628818341c2ad86ddc4205d8503801") + + await btnReadFileButton.tap() + await isDone() + readFileRet = await getData('readFileRet') + expect(readFileRet).toEqual( + "GbAtywwibr7mDCeJDFxkxwx8AFAxAg4I4PYJH4pS7lIpAg3lKQqrGQzKFS9VdAIRMljOUrsMyFA8fImHDNgEDdzSAnceBAVxDFU8KLr0" + ) + + // 尝试写入合法ascii + await page.setData({ + writeFileContent: "hello jack.hello marry.", + writeFileEncoding: "ascii", + readFileEncoding: "ascii", + }) + + await btnWriteFileButton.tap() + await isDone() + + await btnReadFileButton.tap() + await isDone() + readFileRet = await getData('readFileRet') + expect(readFileRet).toEqual("hello jack.hello marry.") + + // 写入base64 获取 中文 + await page.setData({ + writeFileContent: "5LiZ6L6w5Lit56eL77yM5qyi6aWu6L6+5pem77yM5aSn6YaJ77yM5L2c5q2k56+H77yM5YW85oCA5a2Q55Sx44CC5piO5pyI5Yeg5pe25pyJ77yf5oqK6YWS6Zeu6Z2S5aSp44CC5LiN55+l5aSp5LiK5a6r6ZiZ77yM5LuK5aSV5piv5L2V5bm044CC5oiR5qyy5LmY6aOO5b2S5Y6777yM5Y+I5oGQ55C85qW8546J5a6H77yM6auY5aSE5LiN6IOc5a+S44CC6LW36Iie5byE5riF5b2x77yM5L2V5Ly85Zyo5Lq66Ze0", + writeFileEncoding: "base64", + readFileEncoding: "utf-8", + }) + + await btnWriteFileButton.tap() + await isDone() + + await btnReadFileButton.tap() + await isDone() + readFileRet = await getData('readFileRet') + expect(readFileRet).toEqual( + "丙辰中秋,欢饮达旦,大醉,作此篇,兼怀子由。明月几时有?把酒问青天。不知天上宫阙,今夕是何年。我欲乘风归去,又恐琼楼玉宇,高处不胜寒。起舞弄清影,何似在人间") + + await page.setData({ + readFileEncoding: "base64", + }) + + await btnReadFileButton.tap() + await isDone() + readFileRet = await getData('readFileRet') + expect(readFileRet).toEqual( + "5LiZ6L6w5Lit56eL77yM5qyi6aWu6L6+5pem77yM5aSn6YaJ77yM5L2c5q2k56+H77yM5YW85oCA5a2Q55Sx44CC5piO5pyI5Yeg5pe25pyJ77yf5oqK6YWS6Zeu6Z2S5aSp44CC5LiN55+l5aSp5LiK5a6r6ZiZ77yM5LuK5aSV5piv5L2V5bm044CC5oiR5qyy5LmY6aOO5b2S5Y6777yM5Y+I5oGQ55C85qW8546J5a6H77yM6auY5aSE5LiN6IOc5a+S44CC6LW36Iie5byE5riF5b2x77yM5L2V5Ly85Zyo5Lq66Ze0" + ) + + }); + + it('stat and asset test', async () => { + // 测试 USER_DATA_PATH //globalTempPath + let globalRootPath = await getData('globalRootPath') + + await page.setData({ + recursiveVal: true, + copyToBasePath: globalRootPath, + basePath: globalRootPath, + globalTempPath: globalRootPath, + rmDirFile: 'a', + mkdirFile: 'a', + unlinkFile: 'a/1.txt', + }) + + // 先清除文件,需要清除全部可能存在的历史测试文件,避免运行失败 + const btnUnLinkFileButton = await page.$('#btn-unlink-file') + await btnUnLinkFileButton.tap() + await isDone() + + await page.setData({ + unlinkFile: 'a/2.txt', + }) + await btnUnLinkFileButton.tap() + await isDone() + + await page.setData({ + unlinkFile: 'a/m/3.txt', + }) + await btnUnLinkFileButton.tap() + await isDone() + + // // 清除文件夹 + const btnRmDirButton = await page.$('#btn-remove-dir') + await btnRmDirButton.tap() + await isDone() + // // 重新创建测试目录 + const btnMkdDirButton = await page.$('#btn-mkdir') + await btnMkdDirButton.tap() + await isDone() + + const btnReadDirButton = await page.$('#btn-read-dir') + await btnReadDirButton.tap() + await isDone() + + + // 期望通过 recursive = true的 文件夹删除,得到一个空的 /a 目录 + let fileListComplete = await getData('fileListComplete') + expect(JSON.stringify(fileListComplete)).toEqual('[]') + let fileListSuccess = await getData('fileListSuccess') + expect(JSON.stringify(fileListSuccess)).toEqual('[]') + + // 写入一个文件 + await page.setData({ + writeFileContent: "锄禾日当午,汗滴禾下土,谁知盘中餐,粒粒皆辛苦", + writeFileEncoding: "utf-8", + writeFile: 'a/1.txt', + recursiveVal: false, + statFile: 'a/1.txt', + }) + + let lastFailError = await getData('lastFailError') + console.log(lastFailError) + + const btnWriteFileButton = await page.$('#btn-write-file') + await btnWriteFileButton.tap() + await isDone() + + let btnStatFileButton = await page.$('#btn-stat-file') + await btnStatFileButton.tap() + await isDone() + + // 读取单个文件信息 + let statsRet = await getData('statsRet') + expect(statsRet.length).toEqual(1) + expect(statsRet[0].path).toMatch(new RegExp('.*/a/1.txt$')) + expect(statsRet[0].stats.size).toEqual(69) + if (isAndroid()) { + // 写入一个文件 + await page.setData({ + statsRet: '' + }) + btnStatFileButton = await page.$('#btn-stat-file-sync') + await btnStatFileButton.tap() + await isDone() + + // 读取单个文件信息 + statsRet = await getData('statsRet') + expect(statsRet.length).toEqual(1) + expect(statsRet[0].path).toMatch(new RegExp('.*/a/1.txt$')) + expect(statsRet[0].stats.size).toEqual(69) + } + + /** + * 创建子目录和子目录文件,测试recursive参数 + */ + await page.setData({ + writeFileContent: "1234567890", + writeFileEncoding: "ascii", + writeFile: 'a/2.txt', + basePath: globalRootPath, + recursiveVal: false, + statFile: 'a', + mkdirFile: 'a/m', + }) + + + await btnWriteFileButton.tap() + await isDone() + + // 创建子目录 + await btnMkdDirButton.tap() + await isDone() + + // 复制一份文件到 /a/m/3.txt + await page.setData({ + // asset 只能正式版测试,这里只能模拟返回路径 + basePath: '', + copyFromFile: 'static/test-image/logo.ico', + copyToFile: 'a/m/3.txt', + }) + const btnCopyFileButton = await page.$('#btn-copy-file') + await btnCopyFileButton.tap() + await isDone() + + + await page.setData({ + basePath: globalRootPath, + recursiveVal: true, + statFile: 'a', + }) + + await btnStatFileButton.tap() + await isDone() + + // 读取全部文件信息 + statsRet = await getData('statsRet') + + statsRet.sort(function(a, b) { + if (a.path > b.path) { + return 1 + } else if (a.path < b.path) { + return -1 + } + return 0 + }) + console.log(statsRet) + expect(statsRet.length).toEqual(5) + expect(statsRet[0].path).toMatch(new RegExp('.*/a$')) + // expect(statsRet[0].stats.size).toEqual(0) + + expect(statsRet[2].path).toMatch(new RegExp('.*/a/2.txt$')) + expect(statsRet[2].stats.size).toEqual(10) + + expect(statsRet[4].path).toMatch(new RegExp('.*/a/m/3.txt$')) + expect(statsRet[4].stats.size).toEqual(156406) + + + // 清理文件,避免影响其他测试用例 + await page.setData({ + unlinkFile: 'a/1.txt', + }) + await btnUnLinkFileButton.tap() + await isDone() + + await page.setData({ + unlinkFile: 'a/2.txt', + }) + await btnUnLinkFileButton.tap() + await isDone() + + await page.setData({ + unlinkFile: 'a/m/3.txt', + rmDirFile: 'a', + readDir: 'a', + recursiveVal: true, + }) + await btnUnLinkFileButton.tap() + await isDone() + + await btnRmDirButton.tap() + await isDone() + + await btnReadDirButton.tap() + await isDone() + + // 期望通过 recursive = true的 文件夹删除,得到一个空的 /a 目录 + fileListComplete = await getData('fileListComplete') + expect(JSON.stringify(fileListComplete)).toEqual('[]') + fileListSuccess = await getData('fileListSuccess') + expect(JSON.stringify(fileListSuccess)).toEqual('[]') + + }); + it('appendFileTest', async () => { + if (!isAndroid()) { + return + } + + + let basePath = await getData('basePath') + + await page.setData({ + basePath: mBasePath, + recursiveVal: true, + logAble: false, + rmDirFile: 'appendfile', + mkdirFile: 'appendfile', + writeFileContent: "我爱北京天安门,天安门前太阳升", + appendFileContent: "再说一遍", + writeFileEncoding: "utf-8", + readFileEncoding: "utf-8", + readFile: 'appendfile/appendfile.txt', + unlinkFile: 'appendfile/appendfile.txt', + writeFile: 'appendfile/appendfile.txt', + }) + + // 先清除文件,需要清除全部可能存在的历史测试文件,避免运行失败 + const btnUnLinkFileButton = await page.$('#btn-unlink-file') + await btnUnLinkFileButton.tap() + await isDone() + + // 清除文件夹 + const btnRmDirButton = await page.$('#btn-remove-dir') + await btnRmDirButton.tap() + await isDone() + + // 重新创建测试目录,期望通过 recursive = true的 文件夹删除,得到一个空的 /a 目录 + const btnMkdDirButton = await page.$('#btn-mkdir') + await btnMkdDirButton.tap() + await isDone() + + // 先用utf-8 写入内容 + const btnWriteFileButton = await page.$('#btn-write-file') + + await btnWriteFileButton.tap() + await isDone() + + + //追加内容 + const btnAppendFileButton = await page.$('#btn-append-file') + await btnAppendFileButton.tap() + await isDone() + + const btnReadFileButton = await page.$('#btn-read-file') + await btnReadFileButton.tap() + await isDone() + let readFileRet = await getData('readFileRet') + expect(readFileRet).toEqual("我爱北京天安门,天安门前太阳升再说一遍") + }); + //nlinkSyncTest mkdirSyncTest appendFileTest writeFileSyncTest readFileSyncTest rmdirSyncTest readDirSyncTest accessFileSyncTest + //renameFileSync copyFileSyncTest appendFileSyncTest truncateFileTest truncateFileSyncTest + it('sync test', + async () => { + if (!isAndroid()) { + return + } + + + await page.setData({ + basePath: mBasePath, + recursiveVal: false, + logAble: false, + rmDirFile: 'sync', + mkdirFile: 'sync', + writeFileContent: "我爱北京天安门,天安门前太阳升", + appendFileContent: "再说一遍", + writeFileEncoding: "utf-8", + readFileEncoding: "utf-8", + readDir: 'sync', + rmDirFile: 'sync', + unlinkFile: 'sync/sync.txt', + readFile: 'sync/sync.txt', + writeFile: 'sync/sync.txt', + accessFile: 'sync/sync.txt', + renameToFile: 'sync/sync.txt', + renameFromFile: 'sync/sync.txt', + }) + await clearDir('sync') + // 重新创建测试目录,期望通过 recursive = true的 文件夹删除,得到一个空的 目录 + const btnMkdDirButton = await page.$('#btn-mkdir-sync') + await btnMkdDirButton.tap() + await isDone() + + const btnReadDirButton = await page.$('#btn-read-dir-sync') + await btnReadDirButton.tap() + await isDone() + const fileListSuccess = await getData('fileListSuccess') + expect(JSON.stringify(fileListSuccess)).toEqual('[]') + + // 先用utf-8 写入内容 + const btnWriteFileButton = await page.$('#btn-write-file-sync') + await btnWriteFileButton.tap() + await isDone() + + let btnAccessFileButton = await page.$('#btn-access-file-sync') + await btnAccessFileButton.tap() + await isDone() + let accessFileRet = await getData("accessFileRet") + expect(accessFileRet).toEqual('access:ok') + + //重新命名文件 + const btnRenameFileButton = await page.$('#btn-rename-file-sync') + await btnRenameFileButton.tap() + await isDone() + let renameFileRet = await getData("renameFileRet") + expect(renameFileRet).toEqual("rename:ok") + + + //追加内容 + let btnAppendFileButton = await page.$('#btn-append-file') + await btnAppendFileButton.tap() + await isDone() + + btnAppendFileButton = await page.$('#btn-append-file-sync') + await btnAppendFileButton.tap() + + + let btnReadFileButton = await page.$('#btn-read-file-sync') + await btnReadFileButton.tap() + await isDone() + let readFileRet = await getData('readFileRet') + expect(readFileRet).toEqual("我爱北京天安门,天安门前太阳升再说一遍再说一遍") + + //truncateFileTest + let btnTruncateFile = await page.$('#btn-truncate-file') + await btnTruncateFile.tap() + await isDone() + btnReadFileButton = await page.$('#btn-read-file-sync') + await btnReadFileButton.tap() + await isDone() + readFileRet = await getData('readFileRet') + expect(readFileRet).toEqual("我爱北京天安门") + + btnTruncateFile = await page.$('#btn-truncate-file-sync') + await btnTruncateFile.tap() + await isDone() + btnReadFileButton = await page.$('#btn-read-file-sync') + await btnReadFileButton.tap() + await isDone() + readFileRet = await getData('readFileRet') + expect(readFileRet).toEqual("我爱北京") + + + // 测试 copyfile + await page.setData({ + basePath: mBasePath, + copyToBasePath: mBasePath, + copyFromFile: "sync/sync.txt", + copyToFile: "sync/syncto.txt", + accessFile: "sync/syncto.txt" + }) + const btnCopyFileButton = await page.$('#btn-copy-file-sync') + await btnCopyFileButton.tap() + await isDone() + btnAccessFileButton = await page.$('#btn-access-file-sync') + await btnAccessFileButton.tap() + await isDone() + accessFileRet = await getData("accessFileRet") + expect(accessFileRet).toEqual('access:ok') + + await clearDir('sync') + }); + + async function createFile() { + // 重新创建测试目录,期望通过 recursive = true的 文件夹删除,得到一个空的 目录 + const btnMkdDirButton = await page.$('#btn-mkdir-sync') + await btnMkdDirButton.tap() + await isDone() + + // 先用utf-8 写入内容 + const btnWriteFileButton = await page.$('#btn-write-file-sync') + await btnWriteFileButton.tap() + await isDone() + } + + async function clearDir(dir) { + // 最后需要清楚所有文件避免测试失败 + await page.setData({ + rmDirFile: dir, + }) + const btnUnLinkFileButton = await page.$('#btn-clear-file') + await btnUnLinkFileButton.tap() + await isDone() + + const btnClear = await page.$('#btn-remove-dir') + await btnClear.tap() + await isDone() + } + + function isAndroid() { + if (process.env.uniTestPlatformInfo.indexOf('web') > -1 || process.env.UNI_AUTOMATOR_APP_WEBVIEW === + 'true') { + expect(1).toBe(1) + return false + } + if (process.env.uniTestPlatformInfo.toLocaleLowerCase().startsWith('ios')) { + expect(1).toBe(1) + return false + } + return true + } + + it('getSavedFileListTest', + async () => { + if (!isAndroid()) { + return + } + // await page.setData({ + // logAble: false, + // basePath: mBasePath + // }) + // console.log('getSavedFileListTest', 'start') + // await clearDir('') + // console.log('getSavedFileListTest', 'end') + await page.setData({ + logAble: false, + basePath: mGlobalTempPath, + temFile: 'save3/2.txt', + mkdirFile: 'save3', + writeFile: 'save3/2.txt', + accessFile: '2.txt' + }) + await createFile() + await page.setData({ + basePath: mBasePath, + writeFile: 'save/2.txt', + }) + btnSaveFile = await page.$('#btn-save-file-sync') + await btnSaveFile.tap() + await isDone() + let btnSavedFileList = await page.$('#btn-getsaved-filelist') + await btnSavedFileList.tap() + await isDone() + let getSavedFileListRet = await getData("getSavedFileListRet") + console.log('getSavedFileListTest->' + getSavedFileListRet) + expect(getSavedFileListRet).toEqual('getSavedFileList:ok') + }); + + it('removeSavedFileTest', + async () => { + if (!isAndroid()) { + return + } + await page.setData({ + logAble: false, + basePath: mBasePath + }) + await clearDir('save4') + await page.setData({ + logAble: false, + basePath: mGlobalTempPath, + temFile: 'save4/saveSync.txt', + mkdirFile: 'save4', + writeFile: 'save4/saveSync.txt', + accessFile: 'saveSync.txt' + }) + await createFile() + let btnRemoveSavedFileRet = await page.$('#btn-remove-saved-file') + await btnRemoveSavedFileRet.tap() + await isDone() + let removeSavedFileRet = await getData("removeSavedFileRet") + expect(removeSavedFileRet).toEqual('removeSavedFile:ok') + + }); + + //openFiletest openFileSynctest closeTest closeTestSync writeTest writeSyncTest + it('openFiletest', async () => { + if (!isAndroid()) { + return + } + + await page.setData({ + basePath: mBasePath, + logAble: false, + mkdirFile: 'fd', + writeFile: 'fd/1.txt', + readFile: 'fd/1.txt' + }) + await clearDir('fd') + await createFile() + console.log('openFiletest', '2') + //openFiletest + let btnOpenFile = await page.$('#btn-open-file') + await btnOpenFile.tap() + await isDone() + let fd = await getData("fd") + expect(fd).not.toBe(''); + await page.setData({ + fd: '', + }) + console.log('openFiletest', '3') + //openFileSynctest + btnOpenFile = await page.$('#btn-open-file-sync') + await btnOpenFile.tap() + await isDone() + fd = await getData("fd") + expect(fd).not.toBe(''); + console.log('openFiletest', '4') + }); + // closeTest closeTestSync + it('closeTest', async () => { + if (!isAndroid()) { + return + } + + + + await page.setData({ + basePath: mBasePath, + logAble: false, + mkdirFile: 'fd', + writeFile: 'fd/1.txt', + readFile: 'fd/1.txt' + }) + await clearDir('fd') + await createFile() + //closeTest + let btnCloseFile = await page.$('#btn-close-file') + await btnCloseFile.tap() + await isDone() + let closeFileRet = await getData("closeFileRet") + expect(closeFileRet).toEqual('close:ok') + await page.setData({ + closeFileRet: '', + }) + //closeTestSync + btnCloseFile = await page.$('#btn-close-file-sync') + await btnCloseFile.tap() + await isDone() + closeFileRet = await getData("closeFileRet") + expect(closeFileRet).toEqual('close:ok') + + }); + //writeTest writeSyncTest + it('writeTest', async () => { + if (!isAndroid()) { + return + } + console.log('writeTest', 'start') + + await page.setData({ + basePath: mBasePath, + logAble: false, + mkdirFile: 'fd', + writeFile: 'fd/1.txt', + readFile: 'fd/1.txt', + writeData: '我是一只小小鸟' + }) + await clearDir('fd') + await createFile() + console.log('writeTest', '1') + let btnWrite = await page.$('#btn-write') + await btnWrite.tap() + await isDone() + let bytesWritten = await getData("bytesWritten") + let lastFailError = await getData("lastFailError") + if (bytesWritten != 7) { + let writeData = await getData("writeData") + console.log('writeTest', lastFailError.errCode, lastFailError.errMsg, bytesWritten, + writeData) + } + + expect(bytesWritten).toEqual(7) + console.log('writeTest', '2') + //writeSyncTest + await page.setData({ + writeFile: 'fd/1.txt', + readFile: 'fd/1.txt', + writeData: '我是' + }) + + btnWrite = await page.$('#btn-write-sync') + await btnWrite.tap() + await isDone() + bytesWritten = await getData("bytesWritten") + expect(bytesWritten).toEqual(2) + console.log('writeTest', '3') + //fstatTest + let btnFstat = await page.$('#btn-fstat-file') + await btnFstat.tap() + await isDone() + let fstat = await getData("fstat") + expect(fstat.size > 0).toBe(true) + console.log('writeTest', '4') + + //fstatSyncTest + btnFstat = await page.$('#btn-fstat-file-sync') + await btnFstat.tap() + await isDone() + fstat = await getData("fstat") + expect(fstat.size > 0).toBe(true) + console.log('writeTest', '5') + + //ftruncateFileTest + let btnFTruncateFile = await page.$('#btn-ftruncate-file') + await btnFTruncateFile.tap() + await isDone() + let ftruncateRet = await getData("ftruncateRet") + expect(fstat).not.toEqual('ftruncate:ok') + await page.setData({ + ftruncate: '', + }) + console.log('writeTest', '6') + + //ftruncateFileSyncTest + btnFTruncateFile = await page.$('#btn-ftruncate-file-sync') + await btnFTruncateFile.tap() + await isDone() + ftruncateRet = await getData("ftruncateRet") + expect(fstat).not.toEqual('ftruncate:ok') + console.log('writeTest', '7') + }); + //writeTest writeSyncTest + it('ftruncateFileTest', async () => { + if (!isAndroid()) { + return + } + console.log('ftruncateFileTest', 'start') + + await page.setData({ + basePath: mBasePath, + logAble: false, + mkdirFile: 'fd', + writeFile: 'fd/1.txt', + readFile: 'fd/1.txt', + writeData: '我是一只小小鸟我是' + }) + await clearDir('fd') + await createFile() + console.log('ftruncateFileTest', '1') + btnWrite = await page.$('#btn-write-sync') + await btnWrite.tap() + await isDone() + bytesWritten = await getData("bytesWritten") + expect(bytesWritten).toEqual(9) + console.log('ftruncateFileTest', '3') + //ftruncateFileTest + let btnFTruncateFile = await page.$('#btn-ftruncate-file') + await btnFTruncateFile.tap() + await isDone() + let ftruncateRet = await getData("ftruncateRet") + expect(ftruncateRet).toEqual('ftruncate:ok') + await page.setData({ + ftruncate: '', + }) + console.log('ftruncateFileTest', '6') + + //ftruncateFileSyncTest + btnFTruncateFile = await page.$('#btn-ftruncate-file-sync') + await btnFTruncateFile.tap() + await isDone() + ftruncateRet = await getData("ftruncateRet") + expect(ftruncateRet).toEqual('ftruncate:ok') + console.log('ftruncateFileTest', '7') + }); + + //testAppendFileBuffer + it('testAppendFileBuffer', async () => { + if (!isAndroid()) { + return + } + + var btnWrite = await page.$('#btn-appendfile-buffer') + await btnWrite.tap() + await isDone() + let arrayBufferRes = await getData("arrayBufferRes") + expect(arrayBufferRes).toEqual(21) + }); + + it('testAppendFileBufferSync', async () => { + if (!isAndroid()) { + return + } + + var btnWrite = await page.$('#btn-appendfilesync-buffer') + await btnWrite.tap() + await isDone() + let arrayBufferRes = await getData("arrayBufferRes") + expect(arrayBufferRes).toEqual(20) + }); + + it('testWriteReadSyncBuffer', async () => { + if (!isAndroid()) { + return + } + + var btnWrite = await page.$('#btn-writereadsync-buffer') + await btnWrite.tap() + await isDone() + let arrayBufferRes = await getData("arrayBufferRes") + expect(arrayBufferRes).toEqual(1.11) + }); + + it('testWriteReadBuffer', async () => { + if (!isAndroid()) { + return + } + + var btnWrite = await page.$('#btn-writeread-buffer') + await btnWrite.tap() + await isDone() + let arrayBufferRes = await getData("arrayBufferRes") + expect(arrayBufferRes).toEqual(1.24) + }); + + it('testWriteReadFileSyncBuffer', async () => { + if (!isAndroid()) { + return + } + + var btnWrite = await page.$('#btn-writereadfilesync-buffer') + await btnWrite.tap() + await isDone() + let arrayBufferRes = await getData("arrayBufferRes") + expect(arrayBufferRes).toEqual(1.333) + }); + + it('testReadFileBuffer', async () => { + if (!isAndroid()) { + return + } + + var btnWrite = await page.$('#btn-writereadfile-buffer') + await btnWrite.tap() + await isDone() + let arrayBufferRes = await getData("arrayBufferRes") + expect(arrayBufferRes).toEqual(1.2222222) + }); }); diff --git a/pages/API/get-file-system-manager/get-file-system-manager.uvue b/pages/API/get-file-system-manager/get-file-system-manager.uvue index 72bce6ddb2545c877febb6ca9b59aafd7f34aa2f..efdd3fcbe3f42a06fab45a71707ef3433d56a36e 100644 --- a/pages/API/get-file-system-manager/get-file-system-manager.uvue +++ b/pages/API/get-file-system-manager/get-file-system-manager.uvue @@ -1,1281 +1,1668 @@ - - - - - + + + + + diff --git a/pages/API/get-image-info/get-image-info.uvue b/pages/API/get-image-info/get-image-info.uvue index 449c69ee628c4503f621e4c00f5b7ca5b246eb58..82f93e912d6be120d5f4953ddd45b55615b66527 100644 --- a/pages/API/get-image-info/get-image-info.uvue +++ b/pages/API/get-image-info/get-image-info.uvue @@ -1,119 +1,119 @@ - - - - - diff --git a/pages/API/get-launch-options-sync/get-launch-options-sync.uvue b/pages/API/get-launch-options-sync/get-launch-options-sync.uvue index 3e589d4b7ec08e56473144ff9e024b2b6abe624d..3ec91ef8f1995fe294ed48986ba9ce160c242727 100644 --- a/pages/API/get-launch-options-sync/get-launch-options-sync.uvue +++ b/pages/API/get-launch-options-sync/get-launch-options-sync.uvue @@ -14,7 +14,6 @@ + diff --git a/pages/API/get-native-view/element-getnativeview.uvue b/pages/API/get-native-view/element-getnativeview.uvue index 041b9ff8ca543d25e35ac9d32967d8ad7104723a..c2e2b39e8c8a182753a6c0c5c677e51164504786 100644 --- a/pages/API/get-native-view/element-getnativeview.uvue +++ b/pages/API/get-native-view/element-getnativeview.uvue @@ -2,7 +2,7 @@ - - - - - - - - - diff --git a/pages/component/global-events/global-events.test.js b/pages/component/global-events/global-events.test.js index 51a333c0567887a0367896a569fe373e4933bbea..22e7d40663a317bac30c63beb602df4cd4f22e50 100644 --- a/pages/component/global-events/global-events.test.js +++ b/pages/component/global-events/global-events.test.js @@ -7,7 +7,6 @@ describe('event trigger', () => { }) return } - const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase() const isAndroid = platformInfo.startsWith('android') const isIos = platformInfo.startsWith('ios') @@ -228,38 +227,18 @@ describe('event trigger', () => { expect(await longPressChangedTouchScreenY.text()).toBe(longPressTouchTargetValue) if (isAndroid || isIos) { - if (isAndroid) { - if (platformInfo.indexOf('6') != -1 && platformInfo.indexOf('x86') == -1) { - await program.tap({ - x: 200, - y: 700, - duration: 1000 - }) - } else if (platformInfo.indexOf('12') != -1) { - await program.tap({ - x: 300, - y: 1100, - duration: 1000 - }) - } else { - await program.tap({ - x: 200, - y: 1000, - duration: 1000 - }) - } - } else if (isIos) { + if (isIos) { // 规避系统授权弹框 await program.tap({ x: 100, y: 500, }) - await program.tap({ - x: 200, - y: 400, - duration: 1000 - }) } + await program.tap({ + x: 200, + y: 400, + duration: 1000 + }) const longPressTouchIdentifierText = await longPressTouchIdentifier.text() expect(longPressTouchIdentifierText).not.toBe(longPressTouchTargetIdentifier) expect(longPressTouchIdentifierText).toBeTruthy() @@ -305,4 +284,39 @@ describe('event trigger', () => { } } }) + + it('mock tap event', async () => { + + // ios only 坐标换算准确 + if (isIos) { + + page = await program.reLaunch(PAGE_PATH) + await page.waitFor('view') + + const [ + x, + y + ] = await page.callMethod('jest_getRect') + + expect(x > 0).toBe(true) + expect(y > 0).toBe(true) + + await program.tap({ + x: x, + y: y + }) + await page.waitFor(200) + + const clickEventX = await page.$('#click-event-x') + const StringX = await clickEventX.text() + + expect(Number(StringX)).toBeGreaterThan(0) + const clickEventY = await page.$('#click-event-y') + const StringY = await clickEventY.text() + expect(Number(StringY)).toBeGreaterThan(0) + } else { + expect(1).toBe(1) + } + }) }) + diff --git a/pages/component/global-events/global-events.uvue b/pages/component/global-events/global-events.uvue index 13cfe3ad0a29955ca72480b07b812c0d500ef8e0..ffb2a22881101f7964827add72c9d6ab55ecd509 100644 --- a/pages/component/global-events/global-events.uvue +++ b/pages/component/global-events/global-events.uvue @@ -6,8 +6,7 @@ - - + touchStart Event: touches: @@ -30,36 +30,36 @@ return { title: 'image', imageSrc: "/static/test-image/logo.png" as string.ImageURIString, - loadError: false, - // 自动化测试 - autoTest: false, - setCookieImage: "", - verifyCookieImage: "", - eventLoad: null as UTSJSONObject | null, + loadError: false, + // 自动化测试 + autoTest: false, + setCookieImage: "", + verifyCookieImage: "", + eventLoad: null as UTSJSONObject | null, eventError: null as UTSJSONObject | null } }, methods: { error(event : ImageErrorEvent) { this.loadError = true - console.log(event.type, event.detail); - if (this.autoTest) { - this.eventError = { - "tagName": event.target?.tagName, - "type": event.type, - // "errMsg": event.detail.errMsg - }; + console.log(event.type, event.detail); + if (this.autoTest) { + this.eventError = { + "tagName": event.target?.tagName, + "type": event.type, + // "errMsg": event.detail.errMsg + }; } }, load(event : ImageLoadEvent) { - console.log(event.type, event.detail); - if (this.autoTest) { - this.eventLoad = { - "tagName": event.target?.tagName, - "type": event.type, - "width": event.detail.width, - "height": event.detail.height - }; + console.log(event.type, event.detail); + if (this.autoTest) { + this.eventLoad = { + "tagName": event.target?.tagName, + "type": event.type, + "width": event.detail.width, + "height": event.detail.height + }; } }, imageFormat() { diff --git a/pages/component/label/label.uvue b/pages/component/label/label.uvue index d236ba0a6a19c2bf0de5e6efe494ccc9ddd8f620..efbc8322bdafe05c723414686b1e6a86d8a2ab58 100644 --- a/pages/component/label/label.uvue +++ b/pages/component/label/label.uvue @@ -1,117 +1,122 @@ - - - - diff --git a/pages/component/list-view/ListViewWrapper.uvue b/pages/component/list-view/ListViewWrapper.uvue index dcf407db32cf68da82dc8ff8087793638396991e..a5ce9811c808c7a46a4c424c6be781ca7a0d0743 100644 --- a/pages/component/list-view/ListViewWrapper.uvue +++ b/pages/component/list-view/ListViewWrapper.uvue @@ -1,9 +1,9 @@ diff --git a/pages/component/list-view/issue-2199-item.uvue b/pages/component/list-view/issue-2199-item.uvue index 75e3207942b7d5a2b8bd1b20c1f78615987eee9f..3c1a4ad75cefd73958916e567fc6de583794ba40 100644 --- a/pages/component/list-view/issue-2199-item.uvue +++ b/pages/component/list-view/issue-2199-item.uvue @@ -5,7 +5,7 @@ - - diff --git a/pages/component/list-view/list-view-multiplex-video.uvue b/pages/component/list-view/list-view-multiplex-video.uvue index 34d4fc40a22de14e70514b38d58ceea4a9bb8b4d..3f7c46348e123d1b1a9a6dfe1a46387f82438e15 100644 --- a/pages/component/list-view/list-view-multiplex-video.uvue +++ b/pages/component/list-view/list-view-multiplex-video.uvue @@ -1,39 +1,39 @@ - - - - - diff --git a/pages/component/list-view/list-view-multiplex.uvue b/pages/component/list-view/list-view-multiplex.uvue index 28af9b2dd0ff25598cff8dcc6dda1b2512120ca9..e81e1d9c5494b29caaf249fae40aab9090220887 100644 --- a/pages/component/list-view/list-view-multiplex.uvue +++ b/pages/component/list-view/list-view-multiplex.uvue @@ -1,69 +1,90 @@ - - - - - diff --git a/pages/component/list-view/list-view-refresh.uvue b/pages/component/list-view/list-view-refresh.uvue index fb4195e305b42c4f55b94397101958b7070acecf..b37b3fe3f4dc181c18cae3407e864d7ed99dc316 100644 --- a/pages/component/list-view/list-view-refresh.uvue +++ b/pages/component/list-view/list-view-refresh.uvue @@ -1,103 +1,104 @@ - diff --git a/pages/component/list-view/list-view.test.js b/pages/component/list-view/list-view.test.js index cd66a83783cdb60e9b037bf058af25c8f5e17e83..7e0f62612d08b6bc44714b274e90d24d07b6b2bb 100644 --- a/pages/component/list-view/list-view.test.js +++ b/pages/component/list-view/list-view.test.js @@ -1,9 +1,9 @@ -describe('component-native-list-view', () => { - let page +describe('component-native-list-view', () => { + let page beforeAll(async () => { - //打开list-view测试页 - page = await program.reLaunch('/pages/component/list-view/list-view') - await page.waitFor(600) + //打开list-view测试页 + page = await program.reLaunch('/pages/component/list-view/list-view') + await page.waitFor(600) }) //检测竖向scrolltop属性赋值 @@ -46,7 +46,8 @@ describe('component-native-list-view', () => { expect(scrollDetail.scrollHeight).toBeGreaterThan(0) expect(scrollDetail.scrollWidth).toBeGreaterThan(0) expect(scrollDetail.deltaX).toBe(0) - expect([300, 299.8095]).toContain(scrollDetail.deltaY); + //此处可判断安卓issues:9121的问题 + expect([300.1905, 300, 299.8095]).toContain(scrollDetail.deltaY); expect(await page.data('isScrollTest')).toBe('scroll:Success') }) @@ -160,5 +161,5 @@ describe('component-native-list-view', () => { console.log("check_scroll_into_view_left--"+scrollLeft) await page.callMethod('item_change_size_enum', 0) expect(scrollLeft-1080).toBeGreaterThanOrEqual(0) - }) + }) }) diff --git a/pages/component/list-view/list-view.uvue b/pages/component/list-view/list-view.uvue index 09b563b6ffe74c45e050752fe5ee99ced6cd2ce7..3b01ebb1a81c51e1a8f5717f60866254e97d7085 100644 --- a/pages/component/list-view/list-view.uvue +++ b/pages/component/list-view/list-view.uvue @@ -1,9 +1,9 @@ - - diff --git a/pages/component/native-view/native-view.test.js b/pages/component/native-view/native-view.test.js new file mode 100644 index 0000000000000000000000000000000000000000..7b1e5f0744c012051d881eb615656f2bd3520ff4 --- /dev/null +++ b/pages/component/native-view/native-view.test.js @@ -0,0 +1,33 @@ +describe('native-view.uvue', () => { + if (process.env.uniTestPlatformInfo.indexOf('web') > -1 || process.env.UNI_AUTOMATOR_APP_WEBVIEW == 'true') { + it('object', () => { + expect(1).toBe(1) + }) + return + } + + if(process.env.uniTestPlatformInfo.toLowerCase().startsWith('ios')) { + const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase() + if( + platformInfo.indexOf('14.5') != -1 || + platformInfo.indexOf('13.7') != -1 || + platformInfo.indexOf('12.4') != -1 + ){ + // TODO: 排查 ios 不兼容版本 测试异常原因 + it('14.5 13.7 12.4 测试异常', () => { + expect(1).toBe(1) + }) + return + } + } + + beforeAll(async () => { + page = await program.reLaunch('/pages/component/native-view/native-view') + }); + + it('native-view检测init函数是否响应', async () => { + await page.waitFor(600) + const value = await page.data('isLoad') + expect(value).toBe(true) + }) +}) diff --git a/pages/component/native-view/native-view.uvue b/pages/component/native-view/native-view.uvue new file mode 100644 index 0000000000000000000000000000000000000000..b4f58c0876cc935da97792d293028ae190d82328 --- /dev/null +++ b/pages/component/native-view/native-view.uvue @@ -0,0 +1,64 @@ + + + + + diff --git a/pages/component/navigator/navigate.uvue b/pages/component/navigator/navigate.uvue index 602a04546e05dc21035227a1096c62cdece7eafa..998b14c454f91ea8d7b0d23b8e7be4ab9c2d7a71 100644 --- a/pages/component/navigator/navigate.uvue +++ b/pages/component/navigator/navigate.uvue @@ -1,13 +1,13 @@ - - - diff --git a/pages/component/navigator/navigator.uvue b/pages/component/navigator/navigator.uvue index 2099b1b1cfef07c16334d19ace14ee7f70ec3bf2..29d421fd31eb1c4981535f4ee85f1c58b9bda01b 100644 --- a/pages/component/navigator/navigator.uvue +++ b/pages/component/navigator/navigator.uvue @@ -1,49 +1,49 @@ - - - - - diff --git a/pages/component/navigator/redirect.uvue b/pages/component/navigator/redirect.uvue index a128ceaabb6caf9fc0384fa58d44e2dae2ace2b1..8c2bfe00ffd347a48d1bfe3277cca002f1d1d14b 100644 --- a/pages/component/navigator/redirect.uvue +++ b/pages/component/navigator/redirect.uvue @@ -1,13 +1,13 @@ - - - diff --git a/pages/component/nested-scroll-body/nested-scroll-body.uvue b/pages/component/nested-scroll-body/nested-scroll-body.uvue index 3e48402049ab9df361cfe830aab9feb65df0991f..413449cee19b373f5b544bbf73f34541b79e66cd 100644 --- a/pages/component/nested-scroll-body/nested-scroll-body.uvue +++ b/pages/component/nested-scroll-body/nested-scroll-body.uvue @@ -1,113 +1,115 @@ - - - - - diff --git a/pages/component/nested-scroll-header/nested-scroll-header.uvue b/pages/component/nested-scroll-header/nested-scroll-header.uvue index e0d3b7df7b1d006d42c6ac20913791b8e1a1a7d7..f7b516ce7996fb6c18840a1e89d59e211354a3b2 100644 --- a/pages/component/nested-scroll-header/nested-scroll-header.uvue +++ b/pages/component/nested-scroll-header/nested-scroll-header.uvue @@ -1,82 +1,81 @@ - - - - - diff --git a/pages/component/picker-view/picker-view.test.js b/pages/component/picker-view/picker-view.test.js index bfac467775707a190914cddc2a42fcdc607ead91..feba2b4d407f5e8144792e2971c3369e5713579c 100644 --- a/pages/component/picker-view/picker-view.test.js +++ b/pages/component/picker-view/picker-view.test.js @@ -85,43 +85,45 @@ describe('PickerView.uvue', () => { return } + if (process.env.UNI_AUTOMATOR_APP_WEBVIEW !== 'true') { + it('mask-top-bottom-style', async () => { + // App端动态设置mask-top-style、mask-bottom-style无效 + const linearToTop = "background-image: linear-gradient(to bottom, #f4ff73, rgba(216, 229, 255, 0));" + const linearToBottom = "background-image: linear-gradient(to top, #f4ff73, rgba(216, 229, 255, 0));" + await page.setData({ + maskTopStyle: linearToTop, + maskBottomStyle: linearToBottom, + }) + await page.waitFor(500) + expect(await pickerViewEl.attribute('mask-top-style')).toBe(linearToTop) + expect(await pickerViewEl.attribute('mask-bottom-style')).toBe(linearToBottom) + await page.waitFor(2000) + await toScreenshot('picker-view-app-mask-top-bottom-style') + }) - it('mask-top-bottom-style', async () => { - // App端动态设置mask-top-style、mask-bottom-style无效 - const linearToTop = "background-image: linear-gradient(to bottom, #f4ff73, rgba(216, 229, 255, 0));" - const linearToBottom = "background-image: linear-gradient(to top, #f4ff73, rgba(216, 229, 255, 0));" - await page.setData({ - maskTopStyle: linearToTop, - maskBottomStyle: linearToBottom, + it('reopen-picker-view-page', async () => { + page = await program.switchTab('/pages/tabBar/component') + await page.waitFor(500) + page = await program.navigateTo(PAGE_PATH) + await page.waitFor(500) + const date = new Date() + const { + year, + month, + day + } = await page.data() + expect(year).toEqual(date.getFullYear()) + expect(month).toEqual(date.getMonth() + 1) + expect(day).toEqual(date.getDate()) }) - await page.waitFor(500) - expect(await pickerViewEl.attribute('mask-top-style')).toBe(linearToTop) - expect(await pickerViewEl.attribute('mask-bottom-style')).toBe(linearToBottom) - await page.waitFor(2000) - await toScreenshot('picker-view-app-mask-top-bottom-style') - }) - it('reopen-picker-view-page', async () => { - page = await program.switchTab('/pages/tabBar/component') - await page.waitFor(500) - page = await program.navigateTo(PAGE_PATH) - await page.waitFor(500) - const date = new Date() - const { - year, - month, - day - } = await page.data() - expect(year).toEqual(date.getFullYear()) - expect(month).toEqual(date.getMonth() + 1) - expect(day).toEqual(date.getDate()) - }) + it('trigger UniPickerViewChangeEvent', async () => { + await page.callMethod('setValue') + await page.waitFor(1500) + const eventCallbackNum = await page.callMethod('getEventCallbackNum') + // 3 times 3*3 + expect(eventCallbackNum).toBe(9) + }) + } - it('trigger UniPickerViewChangeEvent', async () => { - await page.callMethod('setValue') - await page.waitFor(1500) - const eventCallbackNum = await page.callMethod('getEventCallbackNum') - // 3 times 3*3 - expect(eventCallbackNum).toBe(9) - }) }) diff --git a/pages/component/picker-view/picker-view.uvue b/pages/component/picker-view/picker-view.uvue index 291403e5817892b826350f8ed29cf2c471d88b9d..7e74d2f2763ea8fba4bb919a693e8ca0db28149e 100644 --- a/pages/component/picker-view/picker-view.uvue +++ b/pages/component/picker-view/picker-view.uvue @@ -6,12 +6,8 @@ 日期:{{year}}年{{month}}月{{day}}日 - {{item}}年 @@ -27,7 +23,7 @@ - - - diff --git a/pages/component/rich-text/rich-text-complex.uvue b/pages/component/rich-text/rich-text-complex.uvue index 2d802482315fb232e8cbb7f7f16daa9e65f8d2b4..f5cbfa792272cc987c8915ee955c3d243c5bdf03 100644 --- a/pages/component/rich-text/rich-text-complex.uvue +++ b/pages/component/rich-text/rich-text-complex.uvue @@ -1,14 +1,14 @@ @@ -34,15 +34,15 @@ clicktext = '点击了链接,href = ' + e.detail.href; } uni.showModal({ - content:clicktext, - showCancel:false + content: clicktext, + showCancel: false }); }, - fViewClick(e:string) { + fViewClick(e : string) { console.log(e) this.fViewClicked = true }, - selfClick(e:string) { + selfClick(e : string) { console.log(e) this.selfClicked = true } diff --git a/pages/component/rich-text/rich-text-tags.uvue b/pages/component/rich-text/rich-text-tags.uvue index 42b2480ce6f82e83dfc743b06ea4d971d390eb8c..885ea4681667a2d6abfa2de5223cf052f62670b6 100644 --- a/pages/component/rich-text/rich-text-tags.uvue +++ b/pages/component/rich-text/rich-text-tags.uvue @@ -1,327 +1,327 @@ - - - - - diff --git a/pages/component/rich-text/rich-text.test.js b/pages/component/rich-text/rich-text.test.js index 076d3221093fdb2e348b05e3a750f23a75d5259d..a68cb59814cf807ef69ae4ffa139e637528822c1 100644 --- a/pages/component/rich-text/rich-text.test.js +++ b/pages/component/rich-text/rich-text.test.js @@ -1,20 +1,20 @@ -const PAGE_PATH = '/pages/component/rich-text/rich-text' - +const PAGE_PATH = '/pages/component/rich-text/rich-text' + describe('rich-text-test', () => { // 先屏蔽 android 及 web 平台 - if (process.env.uniTestPlatformInfo.startsWith('android') || process.env.uniTestPlatformInfo.startsWith('web')) { + if (process.env.uniTestPlatformInfo.startsWith('web')) { it('other platform', () => { expect(1).toBe(1) }) return } - - let page - beforeAll(async () => { - page = await program.reLaunch(PAGE_PATH) - await page.waitFor(1500); - }) + + let page + beforeAll(async () => { + page = await program.reLaunch(PAGE_PATH) + await page.waitFor(1500); + }) it('richt-text-height', async () => { @@ -32,5 +32,27 @@ describe('rich-text-test', () => { console.log('afterValue:', afterValue) expect(beforeValue).toBe(afterValue) }) - -}) + + it('test selectable itemclick', async () => { + if (process.env.uniTestPlatformInfo.toLowerCase().startsWith('ios')) { + return; + } + await page.setData({ + autoTest: true, + isItemClickTrigger: false + }); + await page.waitFor(1000); + const info = await page.callMethod('getWindowInfoForTest'); + const rect = await page.callMethod('getBoundingClientRectForTest'); + await program.tap({ + x: (rect.right - rect.left) / 2, + y: info.statusBarHeight + 44 + (rect.bottom - rect.top) / 2 + }); + await page.waitFor(1000); + expect(await page.data('isItemClickTrigger')).toBe(true); + await page.setData({ + autoTest: false + }); + }); + +}) diff --git a/pages/component/rich-text/rich-text.uvue b/pages/component/rich-text/rich-text.uvue index 3339b5e90d61d5add487e33d53aab58579697b52..dbe8ddcd79183b658a527913c8749f00d5f26235 100644 --- a/pages/component/rich-text/rich-text.uvue +++ b/pages/component/rich-text/rich-text.uvue @@ -22,6 +22,7 @@ + diff --git a/pages/component/scroll-view/scroll-view-props.test.js b/pages/component/scroll-view/scroll-view-props.test.js index 7aebdf439e4629ec2232cd3cb19c04917c170be4..ce89f434b9b281c3a2219d6702a18f0b3e154e6a 100644 --- a/pages/component/scroll-view/scroll-view-props.test.js +++ b/pages/component/scroll-view/scroll-view-props.test.js @@ -96,5 +96,16 @@ describe('component-native-scroll-view-props', () => { const image = await program.screenshot({fullPage: true}); expect(image).toSaveImageSnapshot(); }) - + + + //截图末尾位置元素 + it('scroll-view-props-last-item-screenshot', async () => { + //滚动到末尾位置 + await page.setData({ + scrollLeft: 10000 + }) + await page.waitFor(300); + const image = await program.screenshot({fullPage: true}); + expect(image).toSaveImageSnapshot(); + }) }); diff --git a/pages/component/scroll-view/scroll-view-props.uvue b/pages/component/scroll-view/scroll-view-props.uvue index adf7943ee7a72756e9c0504b76f2f1ad7e2ec044..24a829037e103b0d4a7df425f70c0477cb7fbcf5 100644 --- a/pages/component/scroll-view/scroll-view-props.uvue +++ b/pages/component/scroll-view/scroll-view-props.uvue @@ -1,33 +1,34 @@