From 9991238442cbc2ff9259ebf3730fac804304d1f8 Mon Sep 17 00:00:00 2001 From: shutao Date: Tue, 26 Nov 2024 18:09:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0grid-view=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/component/grid-view/grid-view.test.js | 115 +++++++ pages/component/grid-view/grid-view.uvue | 341 ++++++++++++++++++++ pages/component/list-view/list-view.test.js | 4 +- pages/component/list-view/list-view.uvue | 2 + 4 files changed, 460 insertions(+), 2 deletions(-) create mode 100644 pages/component/grid-view/grid-view.test.js create mode 100644 pages/component/grid-view/grid-view.uvue diff --git a/pages/component/grid-view/grid-view.test.js b/pages/component/grid-view/grid-view.test.js new file mode 100644 index 00000000..deb6dae2 --- /dev/null +++ b/pages/component/grid-view/grid-view.test.js @@ -0,0 +1,115 @@ +const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase() +const isMP = platformInfo.startsWith('mp') + +describe('component-native-grid-view', () => { + if (isMP) { + it('skip mp', () => { + expect(1).toBe(1) + }) + return + } + + let page + beforeAll(async () => { + //打开grid-view测试页 + page = await program.reLaunch('/pages/component/grid-view/grid-view') + await page.waitFor(600) + }) + + //检测竖向scrolltop属性赋值 + it('check_scroll_top', async () => { + await page.callMethod('confirm_scroll_top_input', 600) + await page.waitFor(600) + const listElement = await page.$('#gridview') + const scrollTop = await listElement.attribute("scrollTop") + console.log("check_scroll_top---"+scrollTop) + expect(scrollTop-600).toBeGreaterThanOrEqual(0) + }) + + it('Event check_scroll', async () => { + await page.callMethod('confirm_scroll_top_input', 300) + await page.waitFor(600) + const scrollDetail = await page.data('scrollDetailTest') + // console.log('scrollDetailTest:', scrollDetail) + expect(scrollDetail.scrollLeft).toBe(0) + // scrollTop和deltaY 在安卓端差异 299.8095 + expect([300, 299.8095]).toContain(scrollDetail.scrollTop); + expect(scrollDetail.scrollHeight).toBeGreaterThan(0) + expect(scrollDetail.scrollWidth).toBeGreaterThan(0) + expect(scrollDetail.deltaX).toBe(0) + //此处可判断安卓issues:9121的问题 + expect([300.1905, 300, 299.8095]).toContain(scrollDetail.deltaY); + expect(await page.data('isScrollTest')).toBe('scroll:Success') + }) + + it('Event scrolltolower-滚动到底部/右边',async()=>{ + // 滚动到底部,是否触发scrolltolower事件 + await page.callMethod('confirm_scroll_top_input', 2500) + await page.waitFor(600) + expect(await page.data('isScrolltolowerTest')).toBe('scrolltolower:Success-bottom') + }) + + it('Event scrolltoupper-滚动到顶部/左边',async()=>{ + // 滚动到顶部50,是否触发scrolltoupper事件 + await page.callMethod('confirm_scroll_top_input', 50) + await page.waitFor(1000) + expect(await page.data('isScrolltoupperTest')).toBe('scrolltoupper:Success-top') + }) + + it('Event scrollend-滚动结束时触发',async()=>{ + // 仅App端支持,向上滑动页面 + await program.swipe({ + startPoint: { x: 100, y: 300 }, + endPoint: { x: 100, y: 100 }, + duration: 100 + }) + await page.waitFor(600) + const endDetail = await page.data('scrollEndDetailTest') + // console.log('scrollEndDetailTest:', endDetail) + expect(endDetail.deltaY).toBe(0) + expect(endDetail.deltaX).toBe(0) + expect(endDetail.scrollLeft).toBe(0) + expect(endDetail.scrollTop).toBeGreaterThan(0) + expect(endDetail.scrollHeight).toBeGreaterThan(0) + expect(endDetail.scrollWidth).toBeGreaterThan(0) + }) + + //检测竖向可滚动区域 + it('check_scroll_height', async () => { + await page.waitFor(600) + const value = await page.callMethod('check_scroll_height') + expect(value).toBe(true) + }) + + // //检测下拉刷新 备注:iOS本地测试结果正确,但是自动化测试结果错误 + it('check_refresher', async () => { + await page.callMethod('confirm_scroll_top_input', 0) + await page.setData({ + refresher_enabled_boolean: true, + refresher_triggered_boolean: true + }) + await page.waitFor(2000) + expect(await page.data('refresherrefresh')).toBe(true) + //延迟 等待下拉刷新执行结束 防止后续测试任务结果异常 + await page.waitFor(1000) + }) + + //检测竖向scroll_into_view属性赋值 备注:iOS本地测试结果正确,但是自动化测试结果错误 + it('check_scroll_into_view_top', async () => { + await page.callMethod('setScrollIntoView', 'item---3') + await page.waitFor(600) + const gridElement = await page.$('#gridview') + const scrollTop = await gridElement.attribute("scrollTop") + console.log("check_scroll_into_view_top--"+scrollTop) + await page.callMethod('setScrollIntoView', 'item---0') + expect(scrollTop-280).toBeGreaterThanOrEqual(0) + }) + + //检测grid-view属性变化 截图校验 + it('check_grid_view_props', async () => { + await page.callMethod('testModifyGridViewProps') + await page.waitFor(600) + const image = await program.screenshot({fullPage: false}); + expect(image).toSaveImageSnapshot(); + }) +}) diff --git a/pages/component/grid-view/grid-view.uvue b/pages/component/grid-view/grid-view.uvue new file mode 100644 index 00000000..f1007659 --- /dev/null +++ b/pages/component/grid-view/grid-view.uvue @@ -0,0 +1,341 @@ + + + + + diff --git a/pages/component/list-view/list-view.test.js b/pages/component/list-view/list-view.test.js index 16877ded..047b9fea 100644 --- a/pages/component/list-view/list-view.test.js +++ b/pages/component/list-view/list-view.test.js @@ -164,12 +164,12 @@ describe('component-native-list-view', () => { await page.callMethod('change_scroll_y_boolean', false) await page.waitFor(600) } - await page.callMethod('item_change_size_enum', 3) + await page.callMethod('setScrollIntoView', "item---3") await page.waitFor(600) const listElement = await page.$('#listview') const scrollLeft = await listElement.attribute("scrollLeft") console.log("check_scroll_into_view_left--"+scrollLeft) - await page.callMethod('item_change_size_enum', 0) + await page.callMethod('setScrollIntoView', "item---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 b2577c0b..0fe53649 100644 --- a/pages/component/list-view/list-view.uvue +++ b/pages/component/list-view/list-view.uvue @@ -151,6 +151,8 @@ confirm_scroll_left_input(value : number) { this.scroll_left_input = value }, confirm_refresher_background_input(value : string) { this.refresher_background_input = value }, item_change_size_enum(index : number) { this.scrollIntoView = "item---" + index }, + //自动化测试专用 + setScrollIntoView(id : string) { this.scrollIntoView = id }, // 自动化测试专用(由于事件event参数对象中存在循环引用,在ios端JSON.stringify报错,自动化测试无法page.data获取) checkEventTest(e : ScrollEventTest, eventName : String) { const isPass = e.type === eventName && e.target instanceof UniElement && e.currentTarget instanceof UniElement; -- GitLab