1
1
<script setup lang="ts">
2
2
import type { Task } from ' vitest'
3
+ import { getProjectNameColor } from ' ~/utils/task' ;
4
+ import { activeFileId } from ' ~/composables/params' ;
5
+ import { isReport } from ' ~/constants' ;
3
6
4
7
const props = defineProps <{
5
8
task: Task
9
+ opened: boolean
10
+ failedSnapshot: boolean
11
+ }>()
12
+
13
+ const emit = defineEmits <{
14
+ run: []
15
+ preview: []
16
+ fixSnapshot: [],
6
17
}>()
7
18
8
19
const duration = computed (() => {
9
20
const { result } = props .task
10
21
return result && Math .round (result .duration || 0 )
11
22
})
12
-
13
- function getProjectNameColor(name : string | undefined ) {
14
- if (! name )
15
- return ' '
16
- const index = name .split (' ' ).reduce ((acc , v , idx ) => acc + v .charCodeAt (0 ) + idx , 0 )
17
- const colors = [
18
- ' blue' ,
19
- ' yellow' ,
20
- ' cyan' ,
21
- ' green' ,
22
- ' magenta' ,
23
- ]
24
- return colors [index % colors .length ]
25
- }
26
-
27
23
</script >
28
24
29
25
<template >
@@ -35,13 +31,20 @@ function getProjectNameColor(name: string | undefined) {
35
31
border-rounded
36
32
cursor-pointer
37
33
hover =" bg-active"
34
+ class =" item-wrapper"
35
+ :aria-label =" task.name"
36
+ :data-current =" activeFileId === task.id"
38
37
>
38
+ <div v-if =" task.type === 'suite'" pr-1 >
39
+ <div v-if =" opened" i-carbon-chevron-down op20 />
40
+ <div v-else i-carbon-chevron-right op20 />
41
+ </div >
39
42
<StatusIcon :task =" task" mr-2 />
40
43
<div v-if =" task.type === 'suite' && task.meta.typecheck" i-logos:typescript-icon flex-shrink-0 mr-2 />
41
- <div flex items-end gap-2 :text =" task?.result?.state === 'fail' ? 'red-500' : ''" >
44
+ <div flex items-end gap-2 :text =" task?.result?.state === 'fail' ? 'red-500' : ''" overflow-hidden >
42
45
<span text-sm truncate font-light >
43
46
<!-- only show [] in files view -->
44
- <span v-if =" task. filepath && task.file .projectName" :style =" { color: getProjectNameColor(task.file.projectName) }" >
47
+ <span v-if =" ' filepath' in task && task.projectName" :style =" { color: getProjectNameColor(task.file.projectName) }" >
45
48
[{{ task.file.projectName }}]
46
49
</span >
47
50
{{ task.name }}
@@ -50,5 +53,42 @@ function getProjectNameColor(name: string | undefined) {
50
53
{{ duration > 0 ? duration : '< 1' }}ms
51
54
</span >
52
55
</div >
56
+ <div v-if =" task.type === 'suite' && 'filepath' in task" gap-1 justify-end flex-grow-1 pl-1 class =" test-actions" >
57
+ <IconAction
58
+ v-if =" !isReport && failedSnapshot"
59
+ v-tooltip.bottom =" 'Fix failed snapshot(s)'"
60
+ data-testid =" btn-fix-snapshot"
61
+ title =" Fix failed snapshot(s)"
62
+ icon =" i-carbon-result-old"
63
+ @click.prevent.stop =" emit('fixSnapshot')"
64
+ />
65
+ <IconAction
66
+ v-tooltip.bottom =" 'Open test details'"
67
+ data-testid =" btn-open-details"
68
+ title =" Open test details"
69
+ icon =" i-carbon-intrusion-prevention"
70
+ @click.prevent.stop =" emit('preview')"
71
+ />
72
+ <IconAction
73
+ v-if =" !isReport"
74
+ v-tooltip.bottom =" 'Run current test'"
75
+ data-testid =" btn-run-test"
76
+ title =" Run current test"
77
+ icon =" i-carbon-play-filled-alt"
78
+ text =" green-500"
79
+ @click.prevent.stop =" emit('run')"
80
+ />
81
+ </div >
53
82
</div >
54
83
</template >
84
+
85
+ <style scoped>
86
+ .test-actions {
87
+ display : none ;
88
+ }
89
+
90
+ .item-wrapper :hover .test-actions ,
91
+ .item-wrapper [data-current = " true" ] .test-actions {
92
+ display : flex ;
93
+ }
94
+ </style >
0 commit comments