mirror of
https://github.com/SigNoz/signoz.git
synced 2026-11-24 17:21:06 +00:00
Compare commits
2 Commits
main
...
fix/trunca
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9e45107015 | ||
|
|
94016b4f35 |
@@ -1,5 +1,3 @@
|
||||
import { useState } from 'react';
|
||||
import { Tooltip } from '@signozhq/ui/tooltip';
|
||||
import { Typography } from '@signozhq/ui/typography';
|
||||
import { ChevronDown, ChevronRight, Undo2 } from '@signozhq/icons';
|
||||
|
||||
@@ -22,31 +20,6 @@ export function CheckboxFilterV2Header({
|
||||
onToggleOpen,
|
||||
onClear,
|
||||
}: CheckboxFilterHeaderProps): JSX.Element {
|
||||
const [isTitleTruncated, setIsTitleTruncated] = useState(false);
|
||||
|
||||
const measureTitle = (el: HTMLElement | null): void => {
|
||||
if (el) {
|
||||
setIsTitleTruncated(el.scrollWidth > el.clientWidth);
|
||||
}
|
||||
};
|
||||
|
||||
const titleText = (
|
||||
<Typography
|
||||
ref={measureTitle}
|
||||
variant="paragraph"
|
||||
size="base"
|
||||
weight="regular"
|
||||
color="secondary"
|
||||
as="span"
|
||||
display="inline-block"
|
||||
minWidth={0}
|
||||
textOverflow="ellipsis"
|
||||
textTransform="capitalize"
|
||||
>
|
||||
{title}
|
||||
</Typography>
|
||||
);
|
||||
|
||||
return (
|
||||
<section
|
||||
role="button"
|
||||
@@ -67,7 +40,19 @@ export function CheckboxFilterV2Header({
|
||||
) : (
|
||||
<ChevronRight size={13} cursor="pointer" />
|
||||
)}
|
||||
<Tooltip title={isTitleTruncated ? title : undefined}>{titleText}</Tooltip>
|
||||
<Typography
|
||||
variant="paragraph"
|
||||
size="base"
|
||||
weight="regular"
|
||||
color="secondary"
|
||||
as="span"
|
||||
display="inline-block"
|
||||
minWidth={0}
|
||||
textOverflow="ellipsis"
|
||||
textTransform="capitalize"
|
||||
>
|
||||
{title}
|
||||
</Typography>
|
||||
</section>
|
||||
{isOpen && canReset && (
|
||||
<section className={styles.rightAction}>
|
||||
|
||||
@@ -120,43 +120,4 @@ describe('CheckboxFilterV2Header', () => {
|
||||
expect(onToggleOpen).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('title tooltip', () => {
|
||||
// jsdom has no layout, so truncation is simulated at the prototype level
|
||||
// before mount (the component measures in a layout effect).
|
||||
function mockTitleWidths(scrollWidth: number, clientWidth: number): void {
|
||||
jest
|
||||
.spyOn(HTMLElement.prototype, 'scrollWidth', 'get')
|
||||
.mockReturnValue(scrollWidth);
|
||||
jest
|
||||
.spyOn(HTMLElement.prototype, 'clientWidth', 'get')
|
||||
.mockReturnValue(clientWidth);
|
||||
}
|
||||
|
||||
afterEach(() => {
|
||||
jest.restoreAllMocks();
|
||||
});
|
||||
|
||||
it('shows the full name on hover when the title is truncated', async () => {
|
||||
mockTitleWidths(200, 100);
|
||||
const user = userEvent.setup();
|
||||
render(<CheckboxFilterV2Header {...defaultProps} />);
|
||||
|
||||
await user.hover(screen.getByText(defaultProps.title));
|
||||
|
||||
await expect(screen.findByRole('tooltip')).resolves.toHaveTextContent(
|
||||
defaultProps.title,
|
||||
);
|
||||
});
|
||||
|
||||
it('shows no tooltip when the title fits', async () => {
|
||||
mockTitleWidths(100, 100);
|
||||
const user = userEvent.setup();
|
||||
render(<CheckboxFilterV2Header {...defaultProps} />);
|
||||
|
||||
await user.hover(screen.getByText(defaultProps.title));
|
||||
|
||||
expect(screen.queryByRole('tooltip')).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -114,6 +114,19 @@ export const loadingFiltersHandlers = [
|
||||
),
|
||||
];
|
||||
|
||||
export const longTitleConfig = [
|
||||
{
|
||||
attributeKey: {
|
||||
dataType: DataTypes.Int64,
|
||||
key: 'http.request.content_length_uncompressed',
|
||||
type: 'tag',
|
||||
},
|
||||
defaultOpen: false,
|
||||
title: 'Http Request Content Length Uncompressed',
|
||||
type: FiltersType.CHECKBOX,
|
||||
},
|
||||
];
|
||||
|
||||
export const LONG_FILTER_VALUES = [
|
||||
'checkout-service.production-eu-central-1.svc.cluster.local',
|
||||
'payments-authorisation-worker.production-us-east-2.svc.cluster.local',
|
||||
|
||||
@@ -8,6 +8,7 @@ import type { GlobalMockArgs } from '@/storybook/globals';
|
||||
import QuickFilters from '../QuickFilters';
|
||||
import {
|
||||
dirtySettings,
|
||||
hoverTruncatedTitle,
|
||||
openQueryPicker,
|
||||
openSettings,
|
||||
} from './__story_mockdata__/quickFilters.play';
|
||||
@@ -18,6 +19,7 @@ import {
|
||||
handlers,
|
||||
LONG_FILTER_VALUES,
|
||||
loadingFiltersHandlers,
|
||||
longTitleConfig,
|
||||
MANY_FILTER_VALUES,
|
||||
queryBuilder,
|
||||
selectedServiceQueryBuilder,
|
||||
@@ -159,6 +161,15 @@ export const Tooltips: GlobalArgsStory = {
|
||||
},
|
||||
};
|
||||
|
||||
/** A section title too long for the rail: hovering it shows the full title once. */
|
||||
export const TruncatedTitle: GlobalArgsStory = {
|
||||
args: { config: longTitleConfig },
|
||||
parameters: {
|
||||
msw: { handlers: [noSavedFiltersHandler, ...handlers] },
|
||||
},
|
||||
play: hoverTruncatedTitle,
|
||||
};
|
||||
|
||||
const [firstQuery] = queryBuilder.currentQuery.builder.queryData;
|
||||
|
||||
/** Interaction: the query picker lists every query the filters can follow. */
|
||||
|
||||
@@ -8,9 +8,12 @@ import { QuickFilterManagePermissions } from 'lib/authz/hooks/useAuthZ/permissio
|
||||
import { expect, screen, userEvent, waitFor, within } from 'storybook/test';
|
||||
|
||||
import { grantsAll } from '@/storybook/access/access';
|
||||
import { hoverTruncatableText } from '@/storybook/play/truncatedText';
|
||||
import type { GlobalMockArgs } from '@/storybook/globals';
|
||||
|
||||
import type QuickFilters from '../../QuickFilters';
|
||||
import { longTitleConfig } from '../QuickFilters.stories.mocks';
|
||||
import { FiltersType } from '../../types';
|
||||
|
||||
interface PlayContext {
|
||||
canvasElement: HTMLElement;
|
||||
@@ -61,6 +64,26 @@ export const dirtySettings = async (context: PlayContext): Promise<void> => {
|
||||
await screen.findByRole('button', { name: 'Save changes' });
|
||||
};
|
||||
|
||||
export const hoverTruncatedTitle = async ({
|
||||
canvasElement,
|
||||
args,
|
||||
}: PlayContext): Promise<void> => {
|
||||
const [filter] = args.config ?? [];
|
||||
// Duration and slider sections render no title of their own.
|
||||
if (filter?.type !== FiltersType.CHECKBOX || !filter.title) {
|
||||
return;
|
||||
}
|
||||
|
||||
const [label] = await within(canvasElement).findAllByText(
|
||||
filter.title,
|
||||
{},
|
||||
UNTIL_LOADED,
|
||||
);
|
||||
await hoverTruncatableText(label, filter.title, {
|
||||
cut: filter.title === longTitleConfig[0].title || undefined,
|
||||
});
|
||||
};
|
||||
|
||||
export const openQueryPicker = async ({
|
||||
canvasElement,
|
||||
}: PlayContext): Promise<void> => {
|
||||
|
||||
@@ -108,6 +108,8 @@
|
||||
.left {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
gap: 8px;
|
||||
|
||||
.value {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { useMemo } from 'react';
|
||||
import { Color } from '@signozhq/design-tokens';
|
||||
import { Tooltip } from 'antd';
|
||||
import { Typography } from '@signozhq/ui/typography';
|
||||
import cx from 'classnames';
|
||||
import { isEmpty, isObject } from 'lodash-es';
|
||||
@@ -46,28 +45,73 @@ function Suggestions(props: ISuggestionsProps): React.ReactElement {
|
||||
return (
|
||||
<div className="option">
|
||||
{!isEmpty(optionType) && isObject(value) ? (
|
||||
<Tooltip title={value.key} placement="topLeft">
|
||||
<div className="container">
|
||||
<section className="left-section">
|
||||
{value.isIndexed ? (
|
||||
<Zap size={12} fill={Color.BG_AMBER_500} />
|
||||
) : (
|
||||
<div className="dot" />
|
||||
)}
|
||||
<div className="value">
|
||||
<Typography
|
||||
variant="paragraph"
|
||||
size="base"
|
||||
weight="regular"
|
||||
color="inherit"
|
||||
as="p"
|
||||
textOverflow="ellipsis"
|
||||
>
|
||||
{label}
|
||||
</Typography>
|
||||
</div>
|
||||
<div className="container">
|
||||
<section className="left-section">
|
||||
{value.isIndexed ? (
|
||||
<Zap size={12} fill={Color.BG_AMBER_500} />
|
||||
) : (
|
||||
<div className="dot" />
|
||||
)}
|
||||
<div className="value">
|
||||
<Typography
|
||||
variant="paragraph"
|
||||
size="base"
|
||||
weight="regular"
|
||||
color="inherit"
|
||||
as="p"
|
||||
textOverflow="ellipsis"
|
||||
>
|
||||
{label}
|
||||
</Typography>
|
||||
</div>
|
||||
</section>
|
||||
<section className="right-section">
|
||||
<div className="data-type">
|
||||
<Typography
|
||||
variant="paragraph"
|
||||
size="base"
|
||||
weight="regular"
|
||||
color="inherit"
|
||||
as="p"
|
||||
textOverflow="visible"
|
||||
>
|
||||
{value.dataType}
|
||||
</Typography>
|
||||
</div>
|
||||
<section className={cx('type-tag', value.type)}>
|
||||
<div className="dot" />
|
||||
<Typography
|
||||
variant="paragraph"
|
||||
size="small"
|
||||
weight="regular"
|
||||
color="inherit"
|
||||
as="span"
|
||||
textOverflow="visible"
|
||||
textTransform="capitalize"
|
||||
>
|
||||
{value.type}
|
||||
</Typography>
|
||||
</section>
|
||||
<section className="right-section">
|
||||
</section>
|
||||
</div>
|
||||
) : (
|
||||
<div className="container-without-tag">
|
||||
<section className="left">
|
||||
<div className="dot" />
|
||||
<div className={cx('value', option)}>
|
||||
<Typography
|
||||
{...labelTextStyle}
|
||||
size="base"
|
||||
color="inherit"
|
||||
as="p"
|
||||
textOverflow="ellipsis"
|
||||
>
|
||||
{`${label}`}
|
||||
</Typography>
|
||||
</div>
|
||||
</section>
|
||||
<section className="right">
|
||||
{dataType && (
|
||||
<div className="data-type">
|
||||
<Typography
|
||||
variant="paragraph"
|
||||
@@ -77,62 +121,13 @@ function Suggestions(props: ISuggestionsProps): React.ReactElement {
|
||||
as="p"
|
||||
textOverflow="visible"
|
||||
>
|
||||
{value.dataType}
|
||||
{dataType}
|
||||
</Typography>
|
||||
</div>
|
||||
<section className={cx('type-tag', value.type)}>
|
||||
<div className="dot" />
|
||||
<Typography
|
||||
variant="paragraph"
|
||||
size="small"
|
||||
weight="regular"
|
||||
color="inherit"
|
||||
as="span"
|
||||
textOverflow="visible"
|
||||
textTransform="capitalize"
|
||||
>
|
||||
{value.type}
|
||||
</Typography>
|
||||
</section>
|
||||
</section>
|
||||
</div>
|
||||
</Tooltip>
|
||||
) : (
|
||||
<Tooltip title={label} placement="topLeft">
|
||||
<div className="container-without-tag">
|
||||
<section className="left">
|
||||
<div className="dot" />
|
||||
<div className={cx('value', option)}>
|
||||
<Typography
|
||||
{...labelTextStyle}
|
||||
size="base"
|
||||
color="inherit"
|
||||
as="p"
|
||||
textOverflow="ellipsis"
|
||||
>
|
||||
{`${label}`}
|
||||
</Typography>
|
||||
</div>
|
||||
</section>
|
||||
<section className="right">
|
||||
{dataType && (
|
||||
<div className="data-type">
|
||||
<Typography
|
||||
variant="paragraph"
|
||||
size="base"
|
||||
weight="regular"
|
||||
color="inherit"
|
||||
as="p"
|
||||
textOverflow="visible"
|
||||
>
|
||||
{dataType}
|
||||
</Typography>
|
||||
</div>
|
||||
)}
|
||||
{tagValue.includes(label) && <Check size={14} />}
|
||||
</section>
|
||||
</div>
|
||||
</Tooltip>
|
||||
)}
|
||||
{tagValue.includes(label) && <Check size={14} />}
|
||||
</section>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -5,6 +5,7 @@ import { storyMocks } from '@/storybook/controls/defineStoryMocks';
|
||||
import { type PipelinesArgs, pipelinesMocks } from './Pipelines.stories.mocks';
|
||||
import {
|
||||
expandProcessors,
|
||||
hoverPipelineFilterSuggestions,
|
||||
openAddPipeline,
|
||||
openAddProcessor,
|
||||
openChangeHistory,
|
||||
@@ -75,6 +76,11 @@ export const AddPipelineFilterValues: Story = {
|
||||
play: suggestPipelineFilterValues,
|
||||
};
|
||||
|
||||
/** The filter's suggestions hovered: a key that fits has no tooltip, a route cut short shows in full once. */
|
||||
export const AddPipelineFilterHover: Story = {
|
||||
play: hoverPipelineFilterSuggestions,
|
||||
};
|
||||
|
||||
/** The same form over an existing pipeline, filter included. */
|
||||
export const EditPipeline: Story = {
|
||||
play: openEditPipeline,
|
||||
|
||||
@@ -3,7 +3,11 @@
|
||||
* Do not hand-edit: regenerate instead.
|
||||
*/
|
||||
|
||||
import { screen, userEvent, within } from 'storybook/test';
|
||||
import { expect, screen, userEvent, waitFor, within } from 'storybook/test';
|
||||
|
||||
import { hoverTruncatableText } from '@/storybook/play/truncatedText';
|
||||
|
||||
import { LONG_HTTP_ROUTE } from '../../../stories/__story_mockdata__/logs';
|
||||
|
||||
import type { PipelinesArgs } from '../Pipelines.stories.mocks';
|
||||
|
||||
@@ -144,6 +148,42 @@ export const suggestPipelineFilterValues = async ({
|
||||
await screen.findAllByText('checkout', undefined, untilLoaded);
|
||||
};
|
||||
|
||||
/** The pipeline list behind the form can show the same text, so look only in the open list. */
|
||||
const findSuggestion = (text: string): Promise<HTMLElement> =>
|
||||
waitFor(async () => {
|
||||
const match = Array.from(
|
||||
document.querySelectorAll<HTMLElement>(
|
||||
'.ant-select-dropdown:not(.ant-select-dropdown-hidden) .option p',
|
||||
),
|
||||
).find((element) => element.textContent === text);
|
||||
|
||||
await expect(match).toBeTruthy();
|
||||
|
||||
return match as HTMLElement;
|
||||
}, untilLoaded);
|
||||
|
||||
export const hoverPipelineFilterSuggestions = async ({
|
||||
canvasElement,
|
||||
args,
|
||||
}: PlayContext): Promise<void> => {
|
||||
if (!listsPipelines(args)) {
|
||||
return;
|
||||
}
|
||||
|
||||
await openNewPipelineForm(canvasElement);
|
||||
const input = await focusPipelineFilter();
|
||||
await hoverTruncatableText(await findSuggestion('http.route'), 'http.route', {
|
||||
cut: false,
|
||||
});
|
||||
|
||||
await userEvent.type(input, 'http.route = ');
|
||||
await hoverTruncatableText(
|
||||
await findSuggestion(LONG_HTTP_ROUTE),
|
||||
LONG_HTTP_ROUTE,
|
||||
{ cut: true },
|
||||
);
|
||||
};
|
||||
|
||||
export const openEditPipeline = async ({
|
||||
canvasElement,
|
||||
args,
|
||||
|
||||
@@ -445,6 +445,10 @@ export const logFieldKeysResponse = (
|
||||
};
|
||||
};
|
||||
|
||||
/** A route longer than the query builder's suggestion list is wide. */
|
||||
export const LONG_HTTP_ROUTE =
|
||||
'/api/v1/checkout/orders/{order_id}/payments/{payment_id}/authorisations/{authorisation_id}/retries/{retry_id}/events/{event_id}/acknowledgements/{acknowledgement_id}';
|
||||
|
||||
/** Keyed by the fields the quick filters and the query builder ask about. */
|
||||
const STRING_VALUES: Record<string, string[]> = {
|
||||
severity_text: [...LOG_SEVERITIES],
|
||||
@@ -459,7 +463,12 @@ const STRING_VALUES: Record<string, string[]> = {
|
||||
'host.name': ['ip-10-0-1-14', 'ip-10-0-2-31'],
|
||||
'os.description': ['Linux 6.8.0 x86_64', 'Darwin 23.5.0 arm64'],
|
||||
'process.owner': ['root', 'app'],
|
||||
'http.route': ['/api/v1/checkout', '/api/v1/cart', '/api/v1/auth/token'],
|
||||
'http.route': [
|
||||
'/api/v1/checkout',
|
||||
'/api/v1/cart',
|
||||
'/api/v1/auth/token',
|
||||
LONG_HTTP_ROUTE,
|
||||
],
|
||||
'body.level': LOG_SEVERITIES.map((severity) => severity.toLowerCase()),
|
||||
'body.service': SERVICES,
|
||||
'body.http.method': ['POST', 'GET', 'DELETE'],
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Button } from '@signozhq/ui/button';
|
||||
import { Popover, Tooltip } from 'antd';
|
||||
import { Popover } from 'antd';
|
||||
import { Typography } from '@signozhq/ui/typography';
|
||||
import { Fullscreen } from '@signozhq/icons';
|
||||
|
||||
@@ -35,18 +35,16 @@ function AttributeWithExpandablePopover({
|
||||
|
||||
return (
|
||||
<div className={styles.attributeContainer} key={attributeKey}>
|
||||
<Tooltip title={attributeKey}>
|
||||
<Typography
|
||||
variant="paragraph"
|
||||
size="base"
|
||||
weight="regular"
|
||||
color="secondary"
|
||||
as="p"
|
||||
textOverflow="ellipsis"
|
||||
>
|
||||
{attributeKey}
|
||||
</Typography>
|
||||
</Tooltip>
|
||||
<Typography
|
||||
variant="paragraph"
|
||||
size="base"
|
||||
weight="regular"
|
||||
color="secondary"
|
||||
as="p"
|
||||
textOverflow="ellipsis"
|
||||
>
|
||||
{attributeKey}
|
||||
</Typography>
|
||||
|
||||
<div className={styles.wrapper}>
|
||||
<Popover content={popoverContent} trigger="hover" placement="topRight">
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { Tooltip } from 'antd';
|
||||
import { Typography } from '@signozhq/ui/typography';
|
||||
|
||||
import styles from '../Events.module.scss';
|
||||
@@ -35,31 +34,27 @@ function EventAttribute({
|
||||
|
||||
return (
|
||||
<div className={styles.attributeContainer} key={attributeKey}>
|
||||
<Tooltip title={attributeKey}>
|
||||
<Typography
|
||||
variant="paragraph"
|
||||
size="base"
|
||||
weight="regular"
|
||||
color="secondary"
|
||||
as="p"
|
||||
textOverflow="ellipsis"
|
||||
>
|
||||
{attributeKey}
|
||||
</Typography>
|
||||
<div className={styles.wrapper}>
|
||||
<Typography
|
||||
variant="paragraph"
|
||||
size="base"
|
||||
weight="regular"
|
||||
color="secondary"
|
||||
color="main"
|
||||
as="p"
|
||||
textOverflow="ellipsis"
|
||||
>
|
||||
{attributeKey}
|
||||
{attributeValue}
|
||||
</Typography>
|
||||
</Tooltip>
|
||||
<div className={styles.wrapper}>
|
||||
<Tooltip title={attributeValue}>
|
||||
<Typography
|
||||
variant="paragraph"
|
||||
size="base"
|
||||
weight="regular"
|
||||
color="main"
|
||||
as="p"
|
||||
textOverflow="ellipsis"
|
||||
>
|
||||
{attributeValue}
|
||||
</Typography>
|
||||
</Tooltip>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -14,6 +14,7 @@ import {
|
||||
expandFilterBar,
|
||||
hoverAiSpan,
|
||||
hoverEventStacktrace,
|
||||
hoverLongEventAttributes,
|
||||
openAddSpanToFunnel,
|
||||
openAnalytics,
|
||||
openCreateFunnelStep,
|
||||
@@ -205,6 +206,11 @@ export const SpanPanelEventAttributePopover: Story = {
|
||||
play: hoverEventStacktrace,
|
||||
};
|
||||
|
||||
/** The Events tab hovered: a key that fits has no tooltip, attributes cut short show in full once. */
|
||||
export const SpanPanelEventLongAttributes: Story = {
|
||||
play: hoverLongEventAttributes,
|
||||
};
|
||||
|
||||
/** The analytics panel the header toggle opens. */
|
||||
export const AnalyticsOpen: Story = {
|
||||
play: openAnalytics,
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
} from 'storybook/test';
|
||||
|
||||
import { getToastText } from '@/storybook/play/toastText';
|
||||
import { hoverTruncatableText } from '@/storybook/play/truncatedText';
|
||||
|
||||
import { SpanDetailVariant } from '../../SpanDetailsPanel/constants';
|
||||
import {
|
||||
@@ -27,6 +28,7 @@ import {
|
||||
focusSpanAttributes,
|
||||
focusSpanEventCount,
|
||||
focusSpanIndex,
|
||||
LONG_EVENT_ATTRIBUTES,
|
||||
spanIdAt,
|
||||
spanMatchRows,
|
||||
traceHasEvents,
|
||||
@@ -353,6 +355,37 @@ export const hoverEventStacktrace = async (
|
||||
);
|
||||
};
|
||||
|
||||
export const hoverLongEventAttributes = async (
|
||||
context: PageContext,
|
||||
): Promise<void> => {
|
||||
const { canvasElement, args } = context;
|
||||
|
||||
// The dialog panel renders outside the canvas, where the Events tab lookup misses it.
|
||||
if (
|
||||
!showsSpanPanel(args) ||
|
||||
args.panelPosition === SpanDetailVariant.DIALOG ||
|
||||
focusSpanEventCount(traceOf(args)) === 0
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
await openSpanEvents(context);
|
||||
|
||||
// The long texts are sized to be cut in the right-docked panel; other docks measure.
|
||||
const longCut =
|
||||
args.panelPosition === SpanDetailVariant.DOCKED_RIGHT || undefined;
|
||||
const texts: [string, boolean | undefined][] = [
|
||||
['exception.type', false],
|
||||
[LONG_EVENT_ATTRIBUTES.endpointKey, longCut],
|
||||
[LONG_EVENT_ATTRIBUTES.endpoint, longCut],
|
||||
[LONG_EVENT_ATTRIBUTES.responseKey, longCut],
|
||||
];
|
||||
for (const [text, cut] of texts) {
|
||||
const [label] = await within(canvasElement).findAllByText(text);
|
||||
await hoverTruncatableText(label, text, { cut });
|
||||
}
|
||||
};
|
||||
|
||||
export const copyTraceId = async ({
|
||||
canvasElement,
|
||||
args,
|
||||
|
||||
@@ -381,6 +381,27 @@ const stacktraceOf = (span: BuiltSpan): string =>
|
||||
' at async handle (/app/src/checkout/handler.ts:127:22)',
|
||||
].join('\n');
|
||||
|
||||
const UPSTREAM =
|
||||
'payments-authorisation-worker.production-us-east-2.svc.cluster.local';
|
||||
|
||||
/**
|
||||
* Event attributes too long for the panel. `endpoint` stays at 100 characters
|
||||
* or fewer, so it renders plain; a longer value goes behind the preview popover.
|
||||
*/
|
||||
export const LONG_EVENT_ATTRIBUTES = {
|
||||
endpointKey: `upstream.${UPSTREAM}.authorisation.endpoint.url`,
|
||||
endpoint: `https://${UPSTREAM}:8443/v2/authorise?r=3`,
|
||||
responseKey: `upstream.${UPSTREAM}.authorisation.response.body`,
|
||||
};
|
||||
|
||||
const UPSTREAM_RESPONSE = JSON.stringify({
|
||||
error: 'circuit_open',
|
||||
upstream: 'payments-authorisation-worker',
|
||||
retry_after_ms: 1500,
|
||||
attempts: 3,
|
||||
region: 'us-east-2',
|
||||
});
|
||||
|
||||
const eventsOf = (span: BuiltSpan): SpantypesWaterfallSpanDTO['events'] =>
|
||||
span.hasError
|
||||
? [
|
||||
@@ -393,6 +414,8 @@ const eventsOf = (span: BuiltSpan): SpantypesWaterfallSpanDTO['events'] =>
|
||||
'exception.type': 'UpstreamUnavailable',
|
||||
'exception.message': `${span.template.service} refused the request`,
|
||||
'exception.stacktrace': stacktraceOf(span),
|
||||
[LONG_EVENT_ATTRIBUTES.endpointKey]: LONG_EVENT_ATTRIBUTES.endpoint,
|
||||
[LONG_EVENT_ATTRIBUTES.responseKey]: UPSTREAM_RESPONSE,
|
||||
},
|
||||
isError: true,
|
||||
},
|
||||
|
||||
60
frontend/src/storybook/play/truncatedText.ts
Normal file
60
frontend/src/storybook/play/truncatedText.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
import { expect, screen, userEvent, waitFor } from 'storybook/test';
|
||||
|
||||
// `Typography` counts text as cut only past this much overflow.
|
||||
const TRUNCATION_TOLERANCE_PX = 1;
|
||||
// Longer than the tooltip's open delay, so a tooltip that would open has opened.
|
||||
const PAST_OPEN_DELAY_MS = 600;
|
||||
|
||||
const tooltipsHolding = (text: string): HTMLElement[] =>
|
||||
screen
|
||||
.queryAllByRole('tooltip')
|
||||
.filter((tooltip) => tooltip.textContent?.includes(text));
|
||||
|
||||
/**
|
||||
* Hovers a `Typography` with `textOverflow="ellipsis"` and checks its tooltip:
|
||||
* one tooltip with the full text once while the text is cut, none while it
|
||||
* fits. Nested tooltips on one trigger merge into one, so a duplicate shows as
|
||||
* the text repeated inside it; an outer antd tooltip shows as a second one.
|
||||
*
|
||||
* `cut` fails the play when the layout stops cutting the text, or starts to;
|
||||
* leave it out where a control decides the width. `label` is the Typography
|
||||
* element itself, so a `flex` Typography, whose text sits in an inner span,
|
||||
* does not fit.
|
||||
*/
|
||||
export const hoverTruncatableText = async (
|
||||
label: HTMLElement,
|
||||
text: string,
|
||||
{ cut }: { cut?: boolean } = {},
|
||||
): Promise<void> => {
|
||||
// A width read before the font loads differs from the one `Typography` acts on.
|
||||
await document.fonts.ready;
|
||||
const isCut = label.scrollWidth - label.clientWidth > TRUNCATION_TOLERANCE_PX;
|
||||
if (cut !== undefined) {
|
||||
await expect(isCut).toBe(cut);
|
||||
}
|
||||
|
||||
if (!isCut) {
|
||||
await userEvent.hover(label);
|
||||
await new Promise((resolve) => {
|
||||
setTimeout(resolve, PAST_OPEN_DELAY_MS);
|
||||
});
|
||||
await expect(tooltipsHolding(text)).toHaveLength(0);
|
||||
return;
|
||||
}
|
||||
|
||||
// A hover before the text is measured finds no tooltip to open.
|
||||
await waitFor(() => expect(label).toHaveAttribute('data-truncated'));
|
||||
await userEvent.hover(label);
|
||||
|
||||
await waitFor(async () => {
|
||||
await expect(tooltipsHolding(text)[0]).toBeVisible();
|
||||
});
|
||||
// antd opens after 100ms and `Typography` after 300ms, so count once both have.
|
||||
await new Promise((resolve) => {
|
||||
setTimeout(resolve, PAST_OPEN_DELAY_MS);
|
||||
});
|
||||
|
||||
const tooltips = tooltipsHolding(text);
|
||||
await expect(tooltips).toHaveLength(1);
|
||||
await expect(tooltips[0].textContent?.split(text)).toHaveLength(2);
|
||||
};
|
||||
Reference in New Issue
Block a user