Skip to content

Commit 7f96465

Browse files
committed
fixed light bulb showing up when it's not supposed to
1 parent a51ce19 commit 7f96465

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

packages/compass-components/src/components/signal-popover.spec.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,16 @@ describe('SignalPopover', function () {
4242
expect(screen.getByText('Unbounded array detected')).to.exist;
4343
userEvent.click(screen.getByTitle('Show next insight'));
4444
expect(screen.getByText('Possibly bloated documents')).to.exist;
45+
46+
it('and the badge should read 2 insights without the icon showing up', function () {
47+
expect(screen.getByText('2 insights')).to.exist;
48+
expect(screen.getByTestId('insight-badge-icon').style.opacity).to.equal(
49+
'0'
50+
);
51+
});
4552
});
4653

47-
it('should show insights badge text only if shouldExpandBadge is true', function () {
54+
it('should show insights badge text by default if shouldExpandBadge is true', function () {
4855
const { rerender } = render(
4956
<SignalPopover signals={signals[0]} shouldExpandBadge={false} />
5057
);

packages/compass-components/src/components/signal-popover.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -451,9 +451,11 @@ const SignalPopover: React.FunctionComponent<SignalPopoverProps> = ({
451451
const [hoverProps, isHovered, setHovered] = useHoverState();
452452
const [currentSignalIndex, setCurrentSignalIndex] = useState(0);
453453
const signals = Array.isArray(_signals) ? _signals : [_signals];
454+
454455
const currentSignal = signals[currentSignalIndex];
455456
const multiSignals = signals.length > 1;
456457
const isActive = isHovered || popoverOpen;
458+
const shouldShowFullBadge = isActive || shouldExpandBadge;
457459

458460
const triggerRef = useRef<HTMLButtonElement>(null);
459461

@@ -590,8 +592,7 @@ const SignalPopover: React.FunctionComponent<SignalPopoverProps> = ({
590592
className
591593
),
592594
style: {
593-
width:
594-
isActive || shouldExpandBadge ? activeBadgeWidth : 18,
595+
width: shouldShowFullBadge ? activeBadgeWidth : 18,
595596
},
596597
ref: triggerRef,
597598
},
@@ -609,7 +610,8 @@ const SignalPopover: React.FunctionComponent<SignalPopoverProps> = ({
609610
glyph="Bulb"
610611
size="small"
611612
className={cx(badgeIconStyles, badgeIconCollapsedStyles)}
612-
style={{ opacity: isActive ? 0 : 1 }}
613+
data-testid="insight-badge-icon"
614+
style={{ opacity: shouldShowFullBadge ? 0 : 1 }}
613615
></Icon>
614616
<strong
615617
className={cx(
@@ -619,7 +621,7 @@ const SignalPopover: React.FunctionComponent<SignalPopoverProps> = ({
619621
data-testid="insight-badge-text"
620622
style={{
621623
width: activeBadgeWidth,
622-
opacity: isActive || shouldExpandBadge ? 1 : 0,
624+
opacity: shouldShowFullBadge ? 1 : 0,
623625
}}
624626
>
625627
{badgeLabel}

0 commit comments

Comments
 (0)