11<script setup lang="ts">
22import type { Task } from ' vitest'
3+ import { getProjectNameColor } from ' ~/utils/task' ;
4+ import { activeFileId } from ' ~/composables/params' ;
5+ import { isReport } from ' ~/constants' ;
36
47const props = defineProps <{
58 task: Task
9+ opened: boolean
10+ failedSnapshot: boolean
11+ }>()
12+
13+ const emit = defineEmits <{
14+ run: []
15+ preview: []
16+ fixSnapshot: [],
617}>()
718
819const duration = computed (() => {
920 const { result } = props .task
1021 return result && Math .round (result .duration || 0 )
1122})
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-
2723 </script >
2824
2925<template >
@@ -35,13 +31,20 @@ function getProjectNameColor(name: string | undefined) {
3531 border-rounded
3632 cursor-pointer
3733 hover =" bg-active"
34+ class =" item-wrapper"
35+ :aria-label =" task.name"
36+ :data-current =" activeFileId === task.id"
3837 >
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 >
3942 <StatusIcon :task =" task" mr-2 />
4043 <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 >
4245 <span text-sm truncate font-light >
4346 <!-- 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) }" >
4548 [{{ task.file.projectName }}]
4649 </span >
4750 {{ task.name }}
@@ -50,5 +53,42 @@ function getProjectNameColor(name: string | undefined) {
5053 {{ duration > 0 ? duration : '< 1' }}ms
5154 </span >
5255 </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 >
5382 </div >
5483</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