Skip to content

Commit 840e02f

Browse files
authored
feat(ui): show all suites/tests when parent matches (#6106)
1 parent bd83f6c commit 840e02f

File tree

3 files changed

+63
-9
lines changed

3 files changed

+63
-9
lines changed

packages/ui/client/composables/explorer/filter.ts

Lines changed: 56 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,44 @@ export function* filterNode(
4848
) {
4949
const treeNodes = new Set<string>()
5050

51+
const parentsMap = new Map<string, boolean>()
5152
const list: FilterResult[] = []
5253

53-
for (const entry of visitNode(
54-
node,
55-
treeNodes,
56-
n => matcher(n, search, filter),
57-
)) {
58-
list.push(entry)
54+
let fileId: string | undefined
55+
56+
if (filter.onlyTests) {
57+
for (const [match, child] of visitNode(
58+
node,
59+
treeNodes,
60+
n => matcher(n, search, filter),
61+
)) {
62+
list.push([match, child])
63+
}
64+
}
65+
else {
66+
for (const [match, child] of visitNode(
67+
node,
68+
treeNodes,
69+
n => matcher(n, search, filter),
70+
)) {
71+
if (isParentNode(child)) {
72+
parentsMap.set(child.id, match)
73+
if (isFileNode(child)) {
74+
match && (fileId = child.id)
75+
list.push([match, child])
76+
}
77+
else {
78+
list.push([match || parentsMap.get(child.parentId) === true, child])
79+
}
80+
}
81+
else {
82+
list.push([match || parentsMap.get(child.parentId) === true, child])
83+
}
84+
}
85+
// when expanding a non-file node
86+
if (!fileId && !isFileNode(node) && 'fileId' in node) {
87+
fileId = node.fileId as string
88+
}
5989
}
6090

6191
const filesToShow = new Set<string>()
@@ -65,6 +95,7 @@ export function* filterNode(
6595
filter.onlyTests,
6696
treeNodes,
6797
filesToShow,
98+
fileId,
6899
)].reverse()
69100

70101
// We show only the files and parents whose parent is expanded.
@@ -129,10 +160,28 @@ function* filterParents(
129160
collapseParents: boolean,
130161
treeNodes: Set<string>,
131162
filesToShow: Set<string>,
163+
nodeId?: string,
132164
) {
133165
for (let i = list.length - 1; i >= 0; i--) {
134166
const [match, child] = list[i]
135-
if (isParentNode(child)) {
167+
const isParent = isParentNode(child)
168+
if (!collapseParents && nodeId && treeNodes.has(nodeId) && 'fileId' in child && child.fileId === nodeId) {
169+
if (isParent) {
170+
treeNodes.add(child.id)
171+
}
172+
let parent = explorerTree.nodes.get(child.parentId)
173+
while (parent) {
174+
treeNodes.add(parent.id)
175+
if (isFileNode(parent)) {
176+
filesToShow.add(parent.id)
177+
}
178+
parent = explorerTree.nodes.get(parent.parentId)
179+
}
180+
yield child
181+
continue
182+
}
183+
184+
if (isParent) {
136185
const node = expandCollapseNode(
137186
match,
138187
child,

packages/ui/client/composables/explorer/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,12 @@ export interface UITaskTreeNode extends TaskTreeNode {
3838
}
3939

4040
export interface TestTreeNode extends UITaskTreeNode {
41+
fileId: string
4142
type: 'test'
4243
}
4344

4445
export interface CustomTestTreeNode extends UITaskTreeNode {
46+
fileId: string
4547
type: 'custom'
4648
}
4749

@@ -51,6 +53,7 @@ export interface ParentTreeNode extends UITaskTreeNode {
5153
}
5254

5355
export interface SuiteTreeNode extends ParentTreeNode {
56+
fileId: string
5457
type: 'suite'
5558
typecheck?: boolean
5659
}

packages/ui/client/composables/explorer/utils.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export function createOrUpdateNodeTask(id: string) {
115115
}
116116

117117
const task = client.state.idMap.get(id)
118-
// if no children just return
118+
// if it is not a test just return
119119
if (!task || !isAtomTest(task)) {
120120
return
121121
}
@@ -149,6 +149,7 @@ export function createOrUpdateNode(
149149
if (isAtomTest(task)) {
150150
taskNode = {
151151
id: task.id,
152+
fileId: task.file.id,
152153
parentId,
153154
name: task.name,
154155
mode: task.mode,
@@ -158,11 +159,12 @@ export function createOrUpdateNode(
158159
indent: node.indent + 1,
159160
duration: task.result?.duration,
160161
state: task.result?.state,
161-
}
162+
} as TestTreeNode | CustomTestTreeNode
162163
}
163164
else {
164165
taskNode = {
165166
id: task.id,
167+
fileId: task.file.id,
166168
parentId,
167169
name: task.name,
168170
mode: task.mode,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy