123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- import {ReactElement, useEffect, useMemo} from 'react';
- import {initializeOrg} from 'sentry-test/initializeOrg';
- import {render, screen} from 'sentry-test/reactTestingLibrary';
- import {FunctionsTable} from 'sentry/components/profiling/functionsTable';
- import ProjectsStore from 'sentry/stores/projectsStore';
- import {OrganizationContext} from 'sentry/views/organizationContext';
- import {RouteContext} from 'sentry/views/routeContext';
- const organization = TestStubs.Organization();
- const project = TestStubs.Project();
- function TestContext({children}: {children: ReactElement}) {
- const {router} = useMemo(() => initializeOrg({organization, project} as any), []);
- useEffect(() => {
- ProjectsStore.loadInitialData([project]);
- return () => ProjectsStore.reset();
- }, []);
- return (
- <RouteContext.Provider
- value={{
- router,
- location: router.location,
- params: {},
- routes: [],
- }}
- >
- <OrganizationContext.Provider value={organization}>
- {children}
- </OrganizationContext.Provider>
- </RouteContext.Provider>
- );
- }
- describe('FunctionsTable', function () {
- it('renders loading', function () {
- render(
- <TestContext>
- <FunctionsTable
- isLoading
- error={null}
- functions={[]}
- project={project}
- sort="p99"
- />
- </TestContext>
- );
- expect(screen.getByTestId('loading-indicator')).toBeInTheDocument();
- });
- it('renders empty data', function () {
- render(
- <TestContext>
- <FunctionsTable
- isLoading={false}
- error={null}
- functions={[]}
- project={project}
- sort="-p99"
- />
- </TestContext>
- );
- expect(screen.getByText('No results found for your query')).toBeInTheDocument();
- });
- it('renders one function', function () {
- const func = {
- count: 10,
- examples: ['aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'],
- fingerprint: 1234,
- name: 'foo',
- p75: 10000000,
- p95: 12000000,
- p99: 12500000,
- package: 'bar',
- path: 'baz',
- worst: 'cccccccccccccccccccccccccccccccc',
- };
- render(
- <TestContext>
- <FunctionsTable
- isLoading={false}
- error={null}
- functions={[func]}
- project={project}
- sort="-p99"
- />
- </TestContext>
- );
- expect(screen.getByText('Name')).toBeInTheDocument();
- expect(screen.getByText('foo')).toBeInTheDocument();
- expect(screen.getByText('Package')).toBeInTheDocument();
- expect(screen.getByText('bar')).toBeInTheDocument();
- expect(screen.getByText('Count')).toBeInTheDocument();
- expect(screen.getByText('10')).toBeInTheDocument();
- expect(screen.getByText('P75 Duration')).toBeInTheDocument();
- expect(screen.getByText('10.00ms')).toBeInTheDocument();
- expect(screen.getByText('P99 Duration')).toBeInTheDocument();
- expect(screen.getByText('12.50ms')).toBeInTheDocument();
- });
- it('renders empty name', function () {
- const func = {
- count: 10,
- examples: ['aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'],
- fingerprint: 1234,
- name: '',
- p75: 10000000,
- p95: 12000000,
- p99: 12500000,
- package: 'bar',
- path: 'baz',
- worst: 'cccccccccccccccccccccccccccccccc',
- };
- render(
- <TestContext>
- <FunctionsTable
- isLoading={false}
- error={null}
- functions={[func]}
- project={project}
- sort="-p99"
- />
- </TestContext>
- );
- expect(screen.getByText('Name')).toBeInTheDocument();
- expect(screen.getByText('Unknown')).toBeInTheDocument();
- expect(screen.getByText('Package')).toBeInTheDocument();
- expect(screen.getByText('bar')).toBeInTheDocument();
- });
- it('renders empty package', function () {
- const func = {
- count: 10,
- examples: ['aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'],
- fingerprint: 1234,
- name: 'foo',
- p75: 10000000,
- p95: 12000000,
- p99: 12500000,
- package: '',
- path: 'baz',
- worst: 'cccccccccccccccccccccccccccccccc',
- };
- render(
- <TestContext>
- <FunctionsTable
- isLoading={false}
- error={null}
- functions={[func]}
- project={project}
- sort="-p99"
- />
- </TestContext>
- );
- expect(screen.getByText('Name')).toBeInTheDocument();
- expect(screen.getByText('foo')).toBeInTheDocument();
- expect(screen.getByText('Package')).toBeInTheDocument();
- expect(screen.getByText('Unknown')).toBeInTheDocument();
- });
- });
|