import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
import {textWithMarkupMatcher} from 'sentry-test/utils';
import {BigNumberWidget} from 'sentry/views/dashboards/widgets/bigNumberWidget/bigNumberWidget';
describe('BigNumberWidget', () => {
describe('Layout', () => {
it('Renders', () => {
render(
);
expect(screen.getByText('0.0109/s')).toBeInTheDocument();
});
});
describe('Visualization', () => {
it('Explains missing data', () => {
render(
);
expect(screen.getByText('No Data')).toBeInTheDocument();
});
it('Explains non-numeric data', () => {
render(
);
expect(screen.getByText('Value is not a finite number.')).toBeInTheDocument();
});
it('Formats dates', () => {
render(
);
expect(screen.getByText('Oct 17, 2024 4:08:07 PM UTC')).toBeInTheDocument();
});
it('Renders strings', () => {
render(
);
expect(screen.getByText('/api/0/fetch')).toBeInTheDocument();
});
it('Formats duration data', () => {
render(
);
expect(screen.getByText('17.28ms')).toBeInTheDocument();
});
it('Shows the full unformatted value on hover', async () => {
render(
);
await userEvent.hover(screen.getByText('178m'));
expect(screen.getByText('178451214')).toBeInTheDocument();
});
it('Respect maximum value', () => {
render(
);
expect(screen.getByText(textWithMarkupMatcher('>100m'))).toBeInTheDocument();
});
});
describe('State', () => {
it('Shows a loading placeholder', () => {
render();
expect(screen.getByText('—')).toBeInTheDocument();
});
it('Loading state takes precedence over error state', () => {
render(
);
expect(screen.getByText('—')).toBeInTheDocument();
});
it('Shows an error message', () => {
render();
expect(screen.getByText('Error: Uh oh')).toBeInTheDocument();
});
it('Shows a retry button', async () => {
const onRetry = jest.fn();
render();
await userEvent.click(screen.getByRole('button', {name: 'Retry'}));
expect(onRetry).toHaveBeenCalledTimes(1);
});
it('Hides other actions if there is an error and a retry handler', () => {
const onRetry = jest.fn();
render(
);
expect(screen.getByRole('button', {name: 'Retry'})).toBeInTheDocument();
expect(
screen.queryByRole('link', {name: 'Open in Discover'})
).not.toBeInTheDocument();
});
});
describe('Previous Period Data', () => {
it('Shows the difference between the current and previous data', () => {
render(
);
expect(screen.getByText('14.23%')).toBeInTheDocument();
expect(screen.getByText('3.05%')).toBeInTheDocument();
});
});
describe('Thresholds', () => {
it('Evaluates the current value against a threshold', async () => {
render(
);
expect(screen.getByRole('status')).toHaveAttribute('aria-label', 'meh');
await userEvent.hover(screen.getByRole('status'));
expect(await screen.findByText('Thresholds in /second')).toBeInTheDocument();
});
it('Normalizes the units', () => {
render(
);
expect(screen.getByRole('status')).toHaveAttribute('aria-label', 'meh');
});
it('Respects the preferred polarity', () => {
render(
);
expect(screen.getByRole('status')).toHaveAttribute('aria-label', 'good');
});
});
});