Skip to content

Commit

Permalink
ref(js): Make widgetCard tests react-router 6 compatible (#76445)
Browse files Browse the repository at this point in the history
  • Loading branch information
evanpurkhiser committed Aug 26, 2024
1 parent a7dc05d commit 0ab5f2f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 28 deletions.
41 changes: 16 additions & 25 deletions static/app/views/dashboards/widgetCard/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,15 @@ describe('Dashboards > WidgetCard', function () {
);

await userEvent.click(await screen.findByLabelText('Widget actions'));
expect(screen.getByText('Open in Discover')).toBeInTheDocument();
await userEvent.click(screen.getByText('Open in Discover'));
await userEvent.click(screen.getByRole('menuitemradio', {name: 'Open in Discover'}));
expect(spy).toHaveBeenCalledWith({
isMetricsData: false,
organization,
widget: multipleQueryWidget,
});
});

it('renders with Open in Discover button and opens in Discover when clicked', async function () {
it('renders with Open in Discover button', async function () {
renderWithProviders(
<WidgetCard
api={api}
Expand All @@ -140,9 +139,8 @@ describe('Dashboards > WidgetCard', function () {
);

await userEvent.click(await screen.findByLabelText('Widget actions'));
expect(screen.getByText('Open in Discover')).toBeInTheDocument();
await userEvent.click(screen.getByText('Open in Discover'));
expect(router.push).toHaveBeenCalledWith(
expect(screen.getByRole('link', {name: 'Open in Discover'})).toHaveAttribute(
'href',
'/organizations/org-slug/discover/results/?environment=prod&field=count%28%29&field=failure_count%28%29&name=Errors&project=1&query=event.type%3Aerror&statsPeriod=14d&yAxis=count%28%29&yAxis=failure_count%28%29'
);
});
Expand All @@ -166,7 +164,7 @@ describe('Dashboards > WidgetCard', function () {
expect(await screen.findByText('Valid widget description')).toBeInTheDocument();
});

it('Opens in Discover with prepended fields pulled from equations', async function () {
it('renders Discover button with prepended fields pulled from equations', async function () {
renderWithProviders(
<WidgetCard
api={api}
Expand Down Expand Up @@ -197,14 +195,13 @@ describe('Dashboards > WidgetCard', function () {
);

await userEvent.click(await screen.findByLabelText('Widget actions'));
expect(screen.getByText('Open in Discover')).toBeInTheDocument();
await userEvent.click(screen.getByText('Open in Discover'));
expect(router.push).toHaveBeenCalledWith(
expect(screen.getByRole('link', {name: 'Open in Discover'})).toHaveAttribute(
'href',
'/organizations/org-slug/discover/results/?environment=prod&field=count_if%28transaction.duration%2Cequals%2C300%29&field=failure_count%28%29&field=count%28%29&field=equation%7C%28count%28%29%20%2B%20failure_count%28%29%29%20%2F%20count_if%28transaction.duration%2Cequals%2C300%29&name=Errors&project=1&query=event.type%3Aerror&statsPeriod=14d&yAxis=equation%7C%28count%28%29%20%2B%20failure_count%28%29%29%20%2F%20count_if%28transaction.duration%2Cequals%2C300%29'
);
});

it('Opens in Discover with Top N', async function () {
it('renders button to open Discover with Top N', async function () {
renderWithProviders(
<WidgetCard
api={api}
Expand Down Expand Up @@ -232,9 +229,8 @@ describe('Dashboards > WidgetCard', function () {
);

await userEvent.click(await screen.findByLabelText('Widget actions'));
expect(screen.getByText('Open in Discover')).toBeInTheDocument();
await userEvent.click(screen.getByText('Open in Discover'));
expect(router.push).toHaveBeenCalledWith(
expect(screen.getByRole('link', {name: 'Open in Discover'})).toHaveAttribute(
'href',
'/organizations/org-slug/discover/results/?display=top5&environment=prod&field=transaction&field=count%28%29&name=Errors&project=1&query=event.type%3Aerror&statsPeriod=14d&yAxis=count%28%29'
);
});
Expand Down Expand Up @@ -268,9 +264,8 @@ describe('Dashboards > WidgetCard', function () {
);

await userEvent.click(await screen.findByLabelText('Widget actions'));
expect(screen.getByText('Open in Discover')).toBeInTheDocument();
await userEvent.click(screen.getByText('Open in Discover'));
expect(router.push).toHaveBeenCalledWith(
expect(screen.getByRole('link', {name: 'Open in Discover'})).toHaveAttribute(
'href',
'/organizations/org-slug/discover/results/?environment=prod&field=p99%28measurements.custom.measurement%29&name=Errors&project=1&query=&statsPeriod=14d&yAxis=p99%28measurements.custom.measurement%29'
);
});
Expand All @@ -297,8 +292,7 @@ describe('Dashboards > WidgetCard', function () {
);

await userEvent.click(await screen.findByLabelText('Widget actions'));
expect(screen.getByText('Duplicate Widget')).toBeInTheDocument();
await userEvent.click(screen.getByText('Duplicate Widget'));
await userEvent.click(screen.getByRole('menuitemradio', {name: 'Duplicate Widget'}));
expect(mock).toHaveBeenCalledTimes(1);
});

Expand All @@ -324,8 +318,7 @@ describe('Dashboards > WidgetCard', function () {
);

await userEvent.click(await screen.findByLabelText('Widget actions'));
expect(screen.getByText('Duplicate Widget')).toBeInTheDocument();
await userEvent.click(screen.getByText('Duplicate Widget'));
await userEvent.click(screen.getByRole('menuitemradio', {name: 'Duplicate Widget'}));
expect(mock).toHaveBeenCalledTimes(0);
});

Expand All @@ -351,8 +344,7 @@ describe('Dashboards > WidgetCard', function () {
);

await userEvent.click(await screen.findByLabelText('Widget actions'));
expect(screen.getByText('Edit Widget')).toBeInTheDocument();
await userEvent.click(screen.getByText('Edit Widget'));
await userEvent.click(screen.getByRole('menuitemradio', {name: 'Edit Widget'}));
expect(mock).toHaveBeenCalledTimes(1);
});

Expand All @@ -378,8 +370,7 @@ describe('Dashboards > WidgetCard', function () {
);

await userEvent.click(await screen.findByLabelText('Widget actions'));
expect(screen.getByText('Delete Widget')).toBeInTheDocument();
await userEvent.click(screen.getByText('Delete Widget'));
await userEvent.click(screen.getByRole('menuitemradio', {name: 'Delete Widget'}));
// Confirm Modal
renderGlobalModal();
await screen.findByRole('dialog');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,8 @@ describe('Dashboards > IssueWidgetCard', function () {
await userEvent.click(await screen.findByLabelText('Widget actions'));
expect(screen.getByText('Duplicate Widget')).toBeInTheDocument();

expect(screen.getByText('Open in Issues')).toBeInTheDocument();
await userEvent.click(screen.getByText('Open in Issues'));
expect(router.push).toHaveBeenCalledWith(
expect(screen.getByRole('link', {name: 'Open in Issues'})).toHaveAttribute(
'href',
'/organizations/org-slug/issues/?environment=prod&project=1&query=event.type%3Adefault&sort=freq&statsPeriod=14d'
);
});
Expand Down

0 comments on commit 0ab5f2f

Please sign in to comment.