Skip to content

Commit

Permalink
test(ui): Use built-in test providers
Browse files Browse the repository at this point in the history
  • Loading branch information
scttcper committed Aug 29, 2024
1 parent 2bfd35e commit 768ce5f
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ import {OrganizationFixture} from 'sentry-fixture/organization';
import {ProjectFixture} from 'sentry-fixture/project';
import {RepositoryFixture} from 'sentry-fixture/repository';

import {makeTestQueryClient} from 'sentry-test/queryClient';
import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';

import {GroupStatus} from 'sentry/types/group';
import type {EventData} from 'sentry/utils/discover/eventView';
import {QueryClientProvider} from 'sentry/utils/queryClient';

import IssueContext from './issueContext';
import {defaultRow} from './testUtils';
Expand All @@ -32,12 +30,7 @@ const mockedGroup = GroupFixture({

const renderIssueContext = (dataRow: EventData = defaultRow) => {
const organization = OrganizationFixture();
render(
<QueryClientProvider client={makeTestQueryClient()}>
<IssueContext dataRow={dataRow} organization={organization} />
</QueryClientProvider>,
{organization}
);
render(<IssueContext dataRow={dataRow} organization={organization} />, {organization});
};

describe('Quick Context Content Issue Column', function () {
Expand Down
69 changes: 34 additions & 35 deletions static/app/views/performance/landing/metricsDataSwitcher.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@ import {ProjectFixture} from 'sentry-fixture/project';

import {addMetricsDataMock} from 'sentry-test/performance/addMetricsDataMock';
import {initializeData} from 'sentry-test/performance/initializePerformanceData';
import {makeTestQueryClient} from 'sentry-test/queryClient';
import {act, render, screen} from 'sentry-test/reactTestingLibrary';

import TeamStore from 'sentry/stores/teamStore';
import {MetricsCardinalityProvider} from 'sentry/utils/performance/contexts/metricsCardinality';
import {QueryClientProvider} from 'sentry/utils/queryClient';
import {OrganizationContext} from 'sentry/views/organizationContext';
import {generatePerformanceEventView} from 'sentry/views/performance/data';
import {PerformanceLanding} from 'sentry/views/performance/landing';

function WrappedComponent({data, withStaticFilters = true}) {
function WrappedComponent({
data,
withStaticFilters = true,
}: {
data: any;
withStaticFilters?: boolean;
}) {
const eventView = generatePerformanceEventView(
data.router.location,
data.projects,
Expand All @@ -23,28 +26,24 @@ function WrappedComponent({data, withStaticFilters = true}) {
);

return (
<QueryClientProvider client={makeTestQueryClient()}>
<OrganizationContext.Provider value={data.organization}>
<MetricsCardinalityProvider
location={data.router.location}
organization={data.organization}
>
<PerformanceLanding
router={data.router}
organization={data.organization}
location={data.router.location}
eventView={eventView}
projects={data.projects}
selection={eventView.getPageFilters()}
onboardingProject={undefined}
handleSearch={() => {}}
handleTrendsClick={() => {}}
setError={() => {}}
withStaticFilters={withStaticFilters}
/>
</MetricsCardinalityProvider>
</OrganizationContext.Provider>
</QueryClientProvider>
<MetricsCardinalityProvider
location={data.router.location}
organization={data.organization}
>
<PerformanceLanding
router={data.router}
organization={data.organization}
location={data.router.location}
eventView={eventView}
projects={data.projects}
selection={eventView.getPageFilters()}
onboardingProject={undefined}
handleSearch={() => {}}
handleTrendsClick={() => {}}
setError={() => {}}
withStaticFilters={withStaticFilters}
/>
</MetricsCardinalityProvider>
);
}

Expand Down Expand Up @@ -133,7 +132,7 @@ describe('Performance > Landing > MetricsDataSwitcher', function () {
features,
});

wrapper = render(<WrappedComponent data={data} />);
wrapper = render(<WrappedComponent data={data} />, {organization: data.organization});
expect(screen.getByTestId('performance-landing-v3')).toBeInTheDocument();
});

Expand All @@ -146,7 +145,7 @@ describe('Performance > Landing > MetricsDataSwitcher', function () {
features,
});

wrapper = render(<WrappedComponent data={data} />);
wrapper = render(<WrappedComponent data={data} />, {organization: data.organization});

expect(await screen.findByTestId('transaction-search-bar')).toBeInTheDocument();
});
Expand All @@ -164,7 +163,7 @@ describe('Performance > Landing > MetricsDataSwitcher', function () {
features,
});

wrapper = render(<WrappedComponent data={data} />);
wrapper = render(<WrappedComponent data={data} />, {organization: data.organization});

expect(await screen.findByTestId('transaction-search-bar')).toBeInTheDocument();
});
Expand All @@ -182,7 +181,7 @@ describe('Performance > Landing > MetricsDataSwitcher', function () {
features,
});

wrapper = render(<WrappedComponent data={data} />);
wrapper = render(<WrappedComponent data={data} />, {organization: data.organization});
expect(await screen.findByTestId('transaction-search-bar')).toBeInTheDocument();
expect(
await screen.findByTestId('landing-mep-alert-single-project-incompatible')
Expand All @@ -204,7 +203,7 @@ describe('Performance > Landing > MetricsDataSwitcher', function () {
features,
});

wrapper = render(<WrappedComponent data={data} />);
wrapper = render(<WrappedComponent data={data} />, {organization: data.organization});
expect(await screen.findByTestId('transaction-search-bar')).toBeInTheDocument();
expect(
await screen.findByTestId('landing-mep-alert-multi-project-incompatible')
Expand All @@ -226,7 +225,7 @@ describe('Performance > Landing > MetricsDataSwitcher', function () {
features,
});

wrapper = render(<WrappedComponent data={data} />);
wrapper = render(<WrappedComponent data={data} />, {organization: data.organization});
expect(await screen.findByTestId('transaction-search-bar')).toBeInTheDocument();
expect(
await screen.findByTestId('landing-mep-alert-multi-project-all-incompatible')
Expand All @@ -246,7 +245,7 @@ describe('Performance > Landing > MetricsDataSwitcher', function () {
features,
});

wrapper = render(<WrappedComponent data={data} />);
wrapper = render(<WrappedComponent data={data} />, {organization: data.organization});
expect(await screen.findByTestId('transaction-search-bar')).toBeInTheDocument();
expect(
await screen.findByTestId('landing-mep-alert-unnamed-discover')
Expand All @@ -266,7 +265,7 @@ describe('Performance > Landing > MetricsDataSwitcher', function () {
features,
});

wrapper = render(<WrappedComponent data={data} />);
wrapper = render(<WrappedComponent data={data} />, {organization: data.organization});
expect(await screen.findByTestId('transaction-search-bar')).toBeInTheDocument();
expect(
await screen.findByTestId('landing-mep-alert-unnamed-discover-or-set')
Expand All @@ -286,7 +285,7 @@ describe('Performance > Landing > MetricsDataSwitcher', function () {
features,
});

wrapper = render(<WrappedComponent data={data} />);
wrapper = render(<WrappedComponent data={data} />, {organization: data.organization});
expect(await screen.findByTestId('transaction-search-bar')).toBeInTheDocument();
expect(
await screen.findByTestId('landing-mep-alert-unnamed-discover')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {ProjectFixture} from 'sentry-fixture/project';
import {TeamFixture} from 'sentry-fixture/team';

import {initializeOrg} from 'sentry-test/initializeOrg';
import {makeTestQueryClient} from 'sentry-test/queryClient';
import {
render,
renderGlobalModal,
Expand All @@ -24,7 +23,6 @@ import {
MEPSetting,
MEPState,
} from 'sentry/utils/performance/contexts/metricsEnhancedSetting';
import {QueryClientProvider} from 'sentry/utils/queryClient';
import TransactionSummary from 'sentry/views/performance/transactionSummary/transactionOverview';

const teams = [
Expand Down Expand Up @@ -80,14 +78,12 @@ function TestComponent({
}

return (
<QueryClientProvider client={makeTestQueryClient()}>
<MetricsCardinalityProvider
organization={props.organization}
location={props.location}
>
<TransactionSummary {...props} />
</MetricsCardinalityProvider>
</QueryClientProvider>
<MetricsCardinalityProvider
organization={props.organization}
location={props.location}
>
<TransactionSummary {...props} />
</MetricsCardinalityProvider>
);
}

Expand Down

0 comments on commit 768ce5f

Please sign in to comment.