Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions static/app/views/dashboards/prebuiltDashboardRenderer.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import {OrganizationFixture} from 'sentry-fixture/organization';

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

import {PrebuiltDashboardRenderer} from 'sentry/views/dashboards/prebuiltDashboardRenderer';
import {PrebuiltDashboardId} from 'sentry/views/dashboards/utils/prebuiltConfigs';

jest.mock('sentry/views/dashboards/detail', () => ({
DashboardDetailWithInjectedProps: () => <div data-test-id="dashboard-detail" />,
}));

jest.mock('sentry/views/dashboards/utils/usePopulateLinkedDashboards', () => ({
useGetPrebuiltDashboard: () => ({
dashboard: {id: '42', widgets: []},
isLoading: false,
}),
}));

describe('PrebuiltDashboardRenderer', () => {
const organization = OrganizationFixture();

it('renders dashboard link with page filter query params from the URL', async () => {
render(
<PrebuiltDashboardRenderer prebuiltId={PrebuiltDashboardId.BACKEND_OVERVIEW} />,
{
organization,
initialRouterConfig: {
location: {
pathname: '/insights/backend/',
query: {
project: '1',
environment: 'production',
statsPeriod: '7d',
},
},
},
}
);

const link = await screen.findByRole('link', {
name: 'View this page on Dashboards',
});

expect(link).toHaveAttribute(
'href',
expect.stringContaining(`/organizations/${organization.slug}/dashboard/42/`)
);
expect(link).toHaveAttribute('href', expect.stringContaining('project=1'));
expect(link).toHaveAttribute(
'href',
expect.stringContaining('environment=production')
);
expect(link).toHaveAttribute('href', expect.stringContaining('statsPeriod=7d'));
});
});
8 changes: 7 additions & 1 deletion static/app/views/dashboards/prebuiltDashboardRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import {Link} from '@sentry/scraps/link';

import {useDismissable} from 'sentry/components/banner';
import {LoadingContainer} from 'sentry/components/loading/loadingContainer';
import {extractSelectionParameters} from 'sentry/components/pageFilters/parse';
import {usePageFilters} from 'sentry/components/pageFilters/usePageFilters';
import {IconClose} from 'sentry/icons';
import {tct} from 'sentry/locale';
import {useIsSentryEmployee} from 'sentry/utils/useIsSentryEmployee';
import {useLocation} from 'sentry/utils/useLocation';
import {useOrganization} from 'sentry/utils/useOrganization';
import {DashboardDetailWithInjectedProps as DashboardDetail} from 'sentry/views/dashboards/detail';
import {
Expand All @@ -33,6 +35,7 @@ export function PrebuiltDashboardRenderer({
storageNamespace,
}: PrebuiltDashboardRendererProps) {
const organization = useOrganization();
const location = useLocation();
const prebuiltDashboard = PREBUILT_DASHBOARDS[prebuiltId];
const {dashboard: populatedPrebuiltDashboard, isLoading} =
useGetPrebuiltDashboard(prebuiltId);
Expand Down Expand Up @@ -100,7 +103,10 @@ export function PrebuiltDashboardRenderer({
{
link: (
<Link
to={`/organizations/${organization.slug}/dashboards/${dashboardId}/`}
to={{
pathname: `/organizations/${organization.slug}/dashboard/${dashboardId}/`,
query: extractSelectionParameters(location.query),
}}
/>
),
}
Expand Down
Loading