From d3ca3e750b44075475613cd88e334f003274303c Mon Sep 17 00:00:00 2001 From: DCloud__JSON Date: Fri, 30 Jun 2023 21:14:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=9A=84state=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E7=9A=84=E8=87=AA=E5=8A=A8=E5=8C=96=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jest.config.js | 2 +- manifest.json | 2 +- pages.json | 189 +++++++------ pages/index.uvue | 373 +++++++++++++------------- pages/state/computed/computed.test.js | 31 +++ pages/state/computed/computed.uvue | 42 +++ pages/state/data/data.test.js | 49 ++++ pages/state/data/data.uvue | 76 ++++++ pages/state/methods/methods.test.js | 48 ++++ pages/state/methods/methods.uvue | 41 +++ pages/state/props/my-component.uvue | 76 ++++++ pages/state/props/props.test.js | 31 +++ pages/state/props/props.uvue | 43 +++ pages/state/watch/watch.test.js | 56 ++++ pages/state/watch/watch.uvue | 63 +++++ 15 files changed, 858 insertions(+), 264 deletions(-) create mode 100644 pages/state/computed/computed.test.js create mode 100644 pages/state/computed/computed.uvue create mode 100644 pages/state/data/data.test.js create mode 100644 pages/state/data/data.uvue create mode 100644 pages/state/methods/methods.test.js create mode 100644 pages/state/methods/methods.uvue create mode 100644 pages/state/props/my-component.uvue create mode 100644 pages/state/props/props.test.js create mode 100644 pages/state/props/props.uvue create mode 100644 pages/state/watch/watch.test.js create mode 100644 pages/state/watch/watch.uvue diff --git a/jest.config.js b/jest.config.js index a54d98a..1351b8a 100644 --- a/jest.config.js +++ b/jest.config.js @@ -6,6 +6,6 @@ module.exports = { watchPathIgnorePatterns: ['/node_modules/', '/dist/', '/.git/'], moduleFileExtensions: ['js', 'json'], rootDir: __dirname, - testMatch: ["/pages/**/*test.[jt]s?(x)"], + testMatch: ["/pages/state/**/*.test.js"], testPathIgnorePatterns: ['/node_modules/'] } diff --git a/manifest.json b/manifest.json index df20794..4caff87 100644 --- a/manifest.json +++ b/manifest.json @@ -1,6 +1,6 @@ { "name" : "hello-uvue", - "appid" : "", + "appid" : "__UNI__CD1E05C", "description" : "", "versionName" : "1.0.0", "versionCode" : "100", diff --git a/pages.json b/pages.json index cc1fbb6..fa3f486 100644 --- a/pages.json +++ b/pages.json @@ -1,80 +1,111 @@ -{ - "pages": [{ - "path": "pages/index", - "style": { - "navigationBarTitleText": "hello uvue" - } - }, - { - "path": "pages/v-bind/v-bind", - "style": { - "navigationBarTitleText": "v-bind" - } - }, - { - "path": "pages/v-for/v-for", - "style": { - "navigationBarTitleText": "v-for" - } - }, - { - "path": "pages/v-if/v-if", - "style": { - "navigationBarTitleText": "v-if" - } - }, - { - "path": "pages/v-model/v-model", - "style": { - "navigationBarTitleText": "v-model" - } - }, - { - "path": "pages/v-on/v-on", - "style": { - "navigationBarTitleText": "v-on" - } - }, - { - "path": "pages/v-once/v-once", - "style": { - "navigationBarTitleText": "v-once" - } - }, - { - "path": "pages/v-show/v-show", - "style": { - "navigationBarTitleText": "v-show" - } - }, - { - "path": "pages/v-slot/v-slot", - "style": { - "navigationBarTitleText": "v-slot" - } - } - ], - "globalStyle": { - "pageOrientation": "portrait", - "navigationBarTitleText": "Hello UVUE", - "navigationBarTextStyle": "white", - "navigationBarBackgroundColor": "#007AFF", - "backgroundColor": "#F8F8F8", - "backgroundColorTop": "#F4F5F6", - "backgroundColorBottom": "#F4F5F6", - "h5": { - "maxWidth": 1190, - "navigationBarTextStyle": "black", - "navigationBarBackgroundColor": "#F1F1F1" - } - }, - "uniIdRouter": {}, - "condition": { //模式配置,仅开发期间生效 - "current": 0, //当前激活的模式(list 的索引项) - "list": [{ - "name": "", //模式名称 - "path": "", //启动页面,必选 - "query": "" //启动参数,在页面的onLoad函数里面得到 - }] - } +{ + "pages": [{ + "path": "pages/index", + "style": { + "navigationBarTitleText": "hello uvue" + } + }, { + "path": "pages/state/data/data", + "style": { + "navigationBarTitleText": "data", + "enablePullDownRefresh": false + } + }, + { + "path": "pages/v-bind/v-bind", + "style": { + "navigationBarTitleText": "v-bind" + } + }, + { + "path": "pages/v-for/v-for", + "style": { + "navigationBarTitleText": "v-for" + } + }, + { + "path": "pages/v-if/v-if", + "style": { + "navigationBarTitleText": "v-if" + } + }, + { + "path": "pages/v-model/v-model", + "style": { + "navigationBarTitleText": "v-model" + } + }, + { + "path": "pages/v-on/v-on", + "style": { + "navigationBarTitleText": "v-on" + } + }, + { + "path": "pages/v-once/v-once", + "style": { + "navigationBarTitleText": "v-once" + } + }, + { + "path": "pages/v-show/v-show", + "style": { + "navigationBarTitleText": "v-show" + } + }, + { + "path": "pages/v-slot/v-slot", + "style": { + "navigationBarTitleText": "v-slot" + } + }, + { + "path": "pages/state/methods/methods", + "style": { + "navigationBarTitleText": "", + "enablePullDownRefresh": false + } + }, { + "path": "pages/state/props/props", + "style": { + "navigationBarTitleText": "", + "enablePullDownRefresh": false + } + }, { + "path": "pages/state/computed/computed", + "style": { + "navigationBarTitleText": "", + "enablePullDownRefresh": false + } + }, { + "path": "pages/state/watch/watch", + "style": { + "navigationBarTitleText": "", + "enablePullDownRefresh": false + } + } + ], + "globalStyle": { + "pageOrientation": "portrait", + "navigationBarTitleText": "Hello UVUE", + "navigationBarTextStyle": "white", + "navigationBarBackgroundColor": "#007AFF", + "backgroundColor": "#F8F8F8", + "backgroundColorTop": "#F4F5F6", + "backgroundColorBottom": "#F4F5F6", + "h5": { + "maxWidth": 1190, + "navigationBarTextStyle": "black", + "navigationBarBackgroundColor": "#F1F1F1" + } + }, + "uniIdRouter": {}, + "condition": { //模式配置,仅开发期间生效 + // "current": 0, //当前激活的模式(list 的索引项) + // "list": [{ + // "name": "state-data", //模式名称 + // "path": "/pages/state/data/data", //启动页面,必选 + // "query": "" //启动参数,在页面的onLoad函数里面得到 + // }] + } } \ No newline at end of file diff --git a/pages/index.uvue b/pages/index.uvue index e04ec1c..f584c37 100644 --- a/pages/index.uvue +++ b/pages/index.uvue @@ -1,184 +1,191 @@ - - - - - \ No newline at end of file diff --git a/pages/state/computed/computed.test.js b/pages/state/computed/computed.test.js new file mode 100644 index 0000000..69d90c7 --- /dev/null +++ b/pages/state/computed/computed.test.js @@ -0,0 +1,31 @@ +// uni-app自动化测试教程: https://uniapp.dcloud.net.cn/worktile/auto/hbuilderx-extension/ +const PAGE_PATH = '/pages/state/computed/computed' +let page; +describe('/pages/state/computed/computed', () => { + beforeAll(async () => { + page = await program.reLaunch(PAGE_PATH) + page = await program.currentPage(); + console.log('page', page); + // await page.waitFor(3000); + }); + + + it('检查“计算属性”的数据是否渲染正确', async () => { + let num = 3 + let computedNum = await getText('#computedNum') + console.log('computedNum',computedNum); + expect(parseInt(computedNum)).toEqual(num); + + page.callMethod('addB') + num ++ + + computedNum = await getText('#computedNum') + expect(parseInt(computedNum)).toEqual(num); + + }); +}); + + +async function getText(param){ + return await (await page.$(param)).text(); +} \ No newline at end of file diff --git a/pages/state/computed/computed.uvue b/pages/state/computed/computed.uvue new file mode 100644 index 0000000..5408782 --- /dev/null +++ b/pages/state/computed/computed.uvue @@ -0,0 +1,42 @@ + + + + + \ No newline at end of file diff --git a/pages/state/data/data.test.js b/pages/state/data/data.test.js new file mode 100644 index 0000000..21a4a20 --- /dev/null +++ b/pages/state/data/data.test.js @@ -0,0 +1,49 @@ +// uni-app自动化测试教程: https://uniapp.dcloud.net.cn/worktile/auto/hbuilderx-extension/ +const PAGE_PATH = '/pages/state/data/data' +let page; +describe('/pages/state/state', () => { + beforeAll(async () => { + page = await program.reLaunch(PAGE_PATH) + page = await program.currentPage(); + console.log('page', page); + // await page.waitFor(3000); + }); + + const data = { + num: 2023, + str: '我是字符串', + obj: { + name: 'John', + age: 30 + }, + arr: [1, 2, 3, 4, 5, 6, 7] + } + + it('检查“data”是否渲染正确', async () => { + const num = await getText('#num') + expect(parseInt(num)).toEqual(data.num); + + const str = await getText('#str') + expect(str).toEqual(data.str); + + const obj_name = await getText('#obj_name') + expect(obj_name).toEqual(data.obj.name); + + const obj_age = await getText('#obj_age') + expect(parseInt(obj_age)).toEqual(data.obj.age); + + const arr = await getText('#arr') + expect(JSON.parse(arr)).toEqual(data.arr); + + for (var i = 0; i < data.arr.length; i++) { + let arr_item = await getText('#arr_'+i) + expect(parseInt(arr_item)).toEqual(data.arr[i]); + } + + }); +}); + + +async function getText(param){ + return await (await page.$(param)).text(); +} \ No newline at end of file diff --git a/pages/state/data/data.uvue b/pages/state/data/data.uvue new file mode 100644 index 0000000..70146ee --- /dev/null +++ b/pages/state/data/data.uvue @@ -0,0 +1,76 @@ + + + + + \ No newline at end of file diff --git a/pages/state/methods/methods.test.js b/pages/state/methods/methods.test.js new file mode 100644 index 0000000..b46ada4 --- /dev/null +++ b/pages/state/methods/methods.test.js @@ -0,0 +1,48 @@ +// uni-app自动化测试教程: https://uniapp.dcloud.net.cn/worktile/auto/hbuilderx-extension/ +const PAGE_PATH = '/pages/state/methods/methods' +let page; +describe('/pages/state/methods/methods', () => { + beforeAll(async () => { + page = await program.reLaunch(PAGE_PATH) + page = await program.currentPage(); + console.log('page', page); + // await page.waitFor(3000); + }); + + + it('检查“通过方法返回的数据”是否正确(从视图中拿)', async () => { + + page.callMethod('addNum') + page.callMethod('getMultiply100Num') + + //显示在界面上的 num乘于100的数 + let multiply100Num = await getText('#multiply100Num') + console.log('multiply100Num', multiply100Num); + let num = await getText('#num') + console.log('num', num); + console.log('multiply100Num', multiply100Num); + expect(num*100).toEqual(multiply100Num*1); + + + + page.callMethod('addNum') + page.callMethod('getMultiply100Num') + + //显示在界面上的 num乘于100的数 + multiply100Num = await getText('#multiply100Num') + console.log('multiply100Num', multiply100Num); + num = await getText('#num') + + console.log('num', num); + console.log('multiply100Num', multiply100Num); + + expect(num*100).toEqual(multiply100Num*1); + + + }); +}); + + +async function getText(param) { + return await (await page.$(param)).text(); +} \ No newline at end of file diff --git a/pages/state/methods/methods.uvue b/pages/state/methods/methods.uvue new file mode 100644 index 0000000..1fbd2a3 --- /dev/null +++ b/pages/state/methods/methods.uvue @@ -0,0 +1,41 @@ + + + + + diff --git a/pages/state/props/my-component.uvue b/pages/state/props/my-component.uvue new file mode 100644 index 0000000..1af3a68 --- /dev/null +++ b/pages/state/props/my-component.uvue @@ -0,0 +1,76 @@ + + + + + \ No newline at end of file diff --git a/pages/state/props/props.test.js b/pages/state/props/props.test.js new file mode 100644 index 0000000..347f77b --- /dev/null +++ b/pages/state/props/props.test.js @@ -0,0 +1,31 @@ +// uni-app自动化测试教程: https://uniapp.dcloud.net.cn/worktile/auto/hbuilderx-extension/ +const PAGE_PATH = '/pages/state/props/props' +let page; +describe('/pages/state/props/props', () => { + beforeAll(async () => { + page = await program.reLaunch(PAGE_PATH) + page = await program.currentPage(); + console.log('page', page); + await page.waitFor(1000); + }); + + it('检查往组件传递参数状态', async () => { + let str = await getMyComponentText("#str") + console.log('str-*--*-',str); + expect(str).toEqual("你好我是props.uvue组件传进的数据"); + + let num = await getMyComponentText("#num") + // console.log('num-*--*-',num); + expect(parseInt(num)).toEqual(1); + + page.callMethod('addNum') + num = await getMyComponentText("#num") + // console.log('num-*--*-',num); + expect(parseInt(num)).toEqual(2); + }); +}); + + +async function getMyComponentText(param){ + return await(await(await page.$('my-component')).$(param)).text(); +} \ No newline at end of file diff --git a/pages/state/props/props.uvue b/pages/state/props/props.uvue new file mode 100644 index 0000000..123ff07 --- /dev/null +++ b/pages/state/props/props.uvue @@ -0,0 +1,43 @@ + + + + + diff --git a/pages/state/watch/watch.test.js b/pages/state/watch/watch.test.js new file mode 100644 index 0000000..4242f3b --- /dev/null +++ b/pages/state/watch/watch.test.js @@ -0,0 +1,56 @@ +// uni-app自动化测试教程: https://uniapp.dcloud.net.cn/worktile/auto/hbuilderx-extension/ +const PAGE_PATH = '/pages/state/watch/watch' +let page; +describe('/pages/state/watch/watch', () => { + beforeAll(async () => { + page = await program.reLaunch(PAGE_PATH) + page = await program.currentPage(); + console.log('page', page); + // await page.waitFor(3000); + }); + + + it('检查数据是否渲染正确', async () => { + + /* + num + addNum + subNum + oldNum + changeIndex + */ + + + let num = await getText('#num') + expect(num/1).toEqual(0); + + let changeIndex = await getText('#changeIndex') + expect(changeIndex/1).toEqual(0); + + + page.callMethod('addNum') + num = await getText('#num') + expect(num/1).toEqual(1); + + let oldNum = await getText('#oldNum') + expect(oldNum/1).toEqual(0); + changeIndex = await getText('#changeIndex') + expect(changeIndex/1).toEqual(1); + + page.callMethod('addNum') + num = await getText('#num') + expect(num/1).toEqual(2); + + oldNum = await getText('#oldNum') + expect(oldNum/1).toEqual(1); + changeIndex = await getText('#changeIndex') + expect(changeIndex/1).toEqual(2); + + + }); +}); + + +async function getText(param) { + return await (await page.$(param)).text(); +} \ No newline at end of file diff --git a/pages/state/watch/watch.uvue b/pages/state/watch/watch.uvue new file mode 100644 index 0000000..5aa21a5 --- /dev/null +++ b/pages/state/watch/watch.uvue @@ -0,0 +1,63 @@ + + + + + -- GitLab