|
| 1 | +import { screen } from '@testing-library/react'; |
| 2 | + |
| 3 | +import type { HoveredAnnotation } from '@/components/charts/AnnotationHitLayer'; |
| 4 | +import { AnnotationTooltip } from '@/components/charts/AnnotationTooltip'; |
| 5 | + |
| 6 | +// A version expression that concatenates several resource attributes produces |
| 7 | +// one long unbroken value — the case that used to overflow the fixed-width |
| 8 | +// tooltip horizontally. |
| 9 | +const LONG_VERSION = |
| 10 | + 'v2.14.7-rc.3+build.20260216.a1b2c3d4e5f6-k8s-cluster-eu-west-1-canary'; |
| 11 | +const LONG_SERVICE = 'checkout-orchestration-service-eu-west-1-canary'; |
| 12 | + |
| 13 | +const hovered: HoveredAnnotation = { |
| 14 | + annotation: { |
| 15 | + time: 1_700_000_000_000, |
| 16 | + x: 1_700_000_000, |
| 17 | + label: LONG_VERSION, |
| 18 | + group: LONG_SERVICE, |
| 19 | + color: '#437eef', |
| 20 | + }, |
| 21 | + point: { x: 100, y: 100 }, |
| 22 | +}; |
| 23 | + |
| 24 | +describe('AnnotationTooltip', () => { |
| 25 | + it('wraps long release values instead of overflowing the tooltip width', () => { |
| 26 | + renderWithMantine(<AnnotationTooltip hovered={hovered} />); |
| 27 | + |
| 28 | + for (const value of [LONG_VERSION, LONG_SERVICE]) { |
| 29 | + const node = screen.getByText(value); |
| 30 | + expect(node).not.toHaveStyle({ whiteSpace: 'nowrap' }); |
| 31 | + // `anywhere`, not `break-word`: only `anywhere` shrinks the element's |
| 32 | + // min-content width, which is what a `wrap="nowrap"` flex row measures. |
| 33 | + expect(node).toHaveStyle({ overflowWrap: 'anywhere' }); |
| 34 | + } |
| 35 | + }); |
| 36 | + |
| 37 | + it('floors the service name width so a long version cannot squeeze it away', () => { |
| 38 | + renderWithMantine(<AnnotationTooltip hovered={hovered} />); |
| 39 | + |
| 40 | + expect(screen.getByText(LONG_SERVICE)).toHaveStyle({ minWidth: '80px' }); |
| 41 | + }); |
| 42 | + |
| 43 | + it('gives the release list more height than the shared series-tooltip cap', () => { |
| 44 | + renderWithMantine(<AnnotationTooltip hovered={hovered} />); |
| 45 | + |
| 46 | + expect(screen.getByText(LONG_VERSION).closest('.chartTooltipContent')) |
| 47 | + // Wrapped values are several lines tall, so the shared 200px cap clips a |
| 48 | + // cluster of releases almost immediately. |
| 49 | + .toHaveClass('annotationTooltipContent'); |
| 50 | + }); |
| 51 | +}); |
0 commit comments