From 884185001af3ae5e8c5c1e7421ad61514393d029 Mon Sep 17 00:00:00 2001 From: MomoPoppy <125256456+MomoPoppy@users.noreply.github.com> Date: Tue, 5 Dec 2023 17:11:38 +0800 Subject: [PATCH] test(tree-menu): [tree-menu] Optimizing e2e test cases for TreeMenu components (#1031) --- .../demos/pc/app/tree-menu/accordion.spec.ts | 4 +- .../pc/app/tree-menu/basic-usage.spec.ts | 6 +- .../current-node-composition-api.vue | 10 +- .../pc/app/tree-menu/current-node.spec.ts | 33 +++-- .../demos/pc/app/tree-menu/current-node.vue | 14 +- .../pc/app/tree-menu/custom-icon.spec.ts | 14 +- .../pc/app/tree-menu/data-resource.spec.ts | 54 +++++--- .../app/tree-menu/default-expand-all.spec.ts | 33 +++-- .../default-expanded-keys-highlight.spec.ts | 10 +- .../tree-menu/default-expanded-keys.spec.ts | 18 ++- .../demos/pc/app/tree-menu/draggable.spec.ts | 15 ++- .../demos/pc/app/tree-menu/empty-text.spec.ts | 2 +- .../tree-menu/event-allow-draggable.spec.ts | 5 +- .../demos/pc/app/tree-menu/events.spec.ts | 84 ++++++++---- .../tree-menu/expand-on-click-node.spec.ts | 35 ++++- .../app/tree-menu/filter-node-method.spec.ts | 15 ++- .../pc/app/tree-menu/filter-node-method.vue | 4 - .../demos/pc/app/tree-menu/indent.spec.ts | 13 +- .../demos/pc/app/tree-menu/lazy-load.spec.ts | 12 +- .../pc/app/tree-menu/menu-collapsible.spec.ts | 7 +- .../pc/app/tree-menu/show-checkbox.spec.ts | 120 ++++++++++++------ .../pc/app/tree-menu/text-ellipsis.spec.ts | 11 +- .../pc/app/tree-menu/tree-menu-slot.spec.ts | 7 +- 23 files changed, 354 insertions(+), 172 deletions(-) diff --git a/examples/sites/demos/pc/app/tree-menu/accordion.spec.ts b/examples/sites/demos/pc/app/tree-menu/accordion.spec.ts index 6b79006e8..953962f1f 100644 --- a/examples/sites/demos/pc/app/tree-menu/accordion.spec.ts +++ b/examples/sites/demos/pc/app/tree-menu/accordion.spec.ts @@ -4,7 +4,9 @@ test('手风琴', async ({ page }) => { page.on('pageerror', (exception) => expect(exception).toBeNull()) await page.goto('tree-menu#accordion') - const treeMenu = page.locator('#preview .tiny-tree-menu') + const wrap = page.locator('#accordion') + const treeMenu = wrap.locator('.tiny-tree-menu') + await treeMenu.getByTitle('指南').click() await expect(treeMenu.getByTitle('引入组件')).toBeVisible() await expect(treeMenu.getByTitle('构建部署')).toBeVisible() diff --git a/examples/sites/demos/pc/app/tree-menu/basic-usage.spec.ts b/examples/sites/demos/pc/app/tree-menu/basic-usage.spec.ts index 2f7243245..924f55dab 100644 --- a/examples/sites/demos/pc/app/tree-menu/basic-usage.spec.ts +++ b/examples/sites/demos/pc/app/tree-menu/basic-usage.spec.ts @@ -4,7 +4,9 @@ test('基本使用,无数据场景', async ({ page }) => { page.on('pageerror', (exception) => expect(exception).toBeNull()) await page.goto('tree-menu#basic-usage') - const treeMenu = page.locator('#preview .tiny-tree-menu') - await expect(treeMenu.getByPlaceholder('请输入内容进行筛选').locator('input')).toBeVisible() + const wrap = page.locator('#basic-usage') + const treeMenu = wrap.locator('.tiny-tree-menu') + + await expect(treeMenu.locator('.tiny-input__inner')).toBeVisible() await expect(treeMenu).toContainText('暂无数据') }) diff --git a/examples/sites/demos/pc/app/tree-menu/current-node-composition-api.vue b/examples/sites/demos/pc/app/tree-menu/current-node-composition-api.vue index 7d33c42a8..8927cba72 100644 --- a/examples/sites/demos/pc/app/tree-menu/current-node-composition-api.vue +++ b/examples/sites/demos/pc/app/tree-menu/current-node-composition-api.vue @@ -4,9 +4,13 @@ setCurrentKey

场景2:通过 setCurrentNode(node:ITreeNode) 设置当前节点

setCurrentNode -

场景3:通过 getCurrentKey() 获取当前节点的 key 为:{{ currentKey }}

+

+ 场景3:通过 getCurrentKey() 获取当前节点的 key 为:{{ currentKey }} +

getCurrentKey -

场景4:通过 getCurrentNode() 获取当前节点的数据为:{{ currentNode }}

+

+ 场景4:通过 getCurrentNode() 获取当前节点的数据为:{{ currentNode }} +

getCurrentNode import { ref, reactive } from 'vue' -import { TreeMenu as TinyTreeMenu, Button as TinyButton, Row as TinyRow, Col as TinyCol } from '@opentiny/vue' +import { TreeMenu as TinyTreeMenu, Button as TinyButton } from '@opentiny/vue' const treeMenu = ref(null) const treeData = reactive([ diff --git a/examples/sites/demos/pc/app/tree-menu/current-node.spec.ts b/examples/sites/demos/pc/app/tree-menu/current-node.spec.ts index 38adb3788..2766d0c14 100644 --- a/examples/sites/demos/pc/app/tree-menu/current-node.spec.ts +++ b/examples/sites/demos/pc/app/tree-menu/current-node.spec.ts @@ -4,22 +4,29 @@ test('设置当前节点', async ({ page }) => { page.on('pageerror', (exception) => expect(exception).toBeNull()) await page.goto('tree-menu#current-node') - const treeMenu = page.locator('#preview .tiny-tree-menu') + const wrap = page.locator('#current-node') + const treeMenu = wrap.locator('.tiny-tree-menu') + const treeNode = treeMenu.locator('.tiny-tree-node__wrapper > .tiny-tree-node') + const button = wrap.locator('.tiny-button') const currentCls = /is-current/ // 通过key设置当前节点 - await page.getByRole('button', { name: '设置当前选中的节点的 key' }).click() - await expect(treeMenu.locator('.tiny-tree-node').filter({ hasText: '按需引入' }).nth(2)).toHaveClass(currentCls) - await page.getByRole('button', { name: '获取当前被选中节点的 key' }).click() - await expect(page.locator('#current-node-key')).toHaveText('20101') - await page.getByRole('button', { name: '获取当前选中的节点' }).click() - await expect(page.locator('#current-node')).toHaveText('{ "id": 20101, "label": "按需引入" }') + await button.nth(0).click() + await expect(treeNode.filter({ hasText: /^按需引入$/ })).toHaveClass(currentCls) + // 获取当前被选中节点的 key + await button.nth(2).click() + await expect(wrap.locator('.current-node-key')).toHaveText('20101') + // 获取当前节点的数据 + await button.nth(3).click() + await expect(wrap.locator('.current-node')).toHaveText('{ "id": 20101, "label": "按需引入" }') // 通过node设置当前节点 - await page.getByRole('button', { name: '设置当前选中的节点' }).nth(1).click() - await expect(treeMenu.locator('.tiny-tree-node').filter({ hasText: '规范' })).toHaveClass(currentCls) - await page.getByRole('button', { name: '获取当前被选中节点的 key' }).click() - await expect(page.locator('#current-node-key')).toHaveText('500') - await page.getByRole('button', { name: '获取当前选中的节点' }).click() - await expect(page.locator('#current-node')).toHaveText('{ "id": 500, "label": "规范" }') + await button.nth(1).click() + await expect(treeNode.filter({ hasText: /^规范$/ })).toHaveClass(currentCls) + // 获取当前被选中节点的 key + await button.nth(2).click() + await expect(wrap.locator('.current-node-key')).toHaveText('500') + // 获取当前节点的数据 + await button.nth(3).click() + await expect(wrap.locator('.current-node')).toHaveText('{ "id": 500, "label": "规范" }') }) diff --git a/examples/sites/demos/pc/app/tree-menu/current-node.vue b/examples/sites/demos/pc/app/tree-menu/current-node.vue index adf8814de..3c929a1d6 100644 --- a/examples/sites/demos/pc/app/tree-menu/current-node.vue +++ b/examples/sites/demos/pc/app/tree-menu/current-node.vue @@ -4,9 +4,13 @@ setCurrentKey

场景2:通过 setCurrentNode(node:ITreeNode) 设置当前节点

setCurrentNode -

场景3:通过 getCurrentKey() 获取当前节点的 key 为:{{ currentKey }}

+

+ 场景3:通过 getCurrentKey() 获取当前节点的 key 为:{{ currentKey }} +

getCurrentKey -

场景4:通过 getCurrentNode() 获取当前节点的数据为:{{ currentNode }}

+

+ 场景4:通过 getCurrentNode() 获取当前节点的数据为:{{ currentNode }} +

getCurrentNode