|
1 | | -import { KeyboardEvent, memo, useState } from "react"; |
| 1 | +import { KeyboardEvent, memo, useMemo, useState } from "react"; |
2 | 2 | import { |
3 | 3 | TestResultInterface, |
4 | 4 | TTestResultType, |
@@ -31,8 +31,18 @@ interface Props { |
31 | 31 | const TestResultItem = memo(({ result, level, isLast = false }: Props) => { |
32 | 32 | const [isOpen, setIsOpen] = useState<boolean>(false); |
33 | 33 |
|
| 34 | + const showDetails = useMemo( |
| 35 | + () => |
| 36 | + (result.type === "test" && Boolean(result.message)) || |
| 37 | + (result.type === "print" && Boolean(result.message)) || |
| 38 | + (result.type === "summary" && Boolean(result.summary)) || |
| 39 | + (result.type === "code" && Boolean(result.code)) || |
| 40 | + (result.type === "group" && Boolean(result.children)), |
| 41 | + [result], |
| 42 | + ); |
| 43 | + |
34 | 44 | const handleToggle = () => { |
35 | | - if (window.getSelection()?.toString()) return; |
| 45 | + if (window.getSelection()?.toString() || !showDetails) return; |
36 | 46 | setIsOpen(prev => !prev); |
37 | 47 | }; |
38 | 48 |
|
@@ -76,21 +86,23 @@ const TestResultItem = memo(({ result, level, isLast = false }: Props) => { |
76 | 86 | <h3 className="flex-1 font-medium text-foreground text-sm leading-tight"> |
77 | 87 | {result.name} |
78 | 88 | </h3> |
79 | | - <div |
80 | | - className={buttonVariants({ |
81 | | - variant: "ghost", |
82 | | - size: "iconXs", |
83 | | - })} |
84 | | - > |
85 | | - <ChevronDownIcon |
86 | | - className={cn("transition-transform duration-75", { |
87 | | - "rotate-180": isOpen, |
| 89 | + {showDetails && ( |
| 90 | + <div |
| 91 | + className={buttonVariants({ |
| 92 | + variant: "ghost", |
| 93 | + size: "iconXs", |
88 | 94 | })} |
89 | | - /> |
90 | | - </div> |
| 95 | + > |
| 96 | + <ChevronDownIcon |
| 97 | + className={cn("transition-transform duration-75", { |
| 98 | + "rotate-180": isOpen, |
| 99 | + })} |
| 100 | + /> |
| 101 | + </div> |
| 102 | + )} |
91 | 103 | </div> |
92 | 104 | <AnimatePresence> |
93 | | - {isOpen && ( |
| 105 | + {isOpen && showDetails && ( |
94 | 106 | <motion.div |
95 | 107 | onClick={e => e.stopPropagation()} |
96 | 108 | initial={{ |
|
0 commit comments