relatedIssues.spec.tsx 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import {GroupFixture} from 'sentry-fixture/group';
  2. import {MetricRuleFixture} from 'sentry-fixture/metricRule';
  3. import {ProjectFixture} from 'sentry-fixture/project';
  4. import {initializeOrg} from 'sentry-test/initializeOrg';
  5. import {render, screen} from 'sentry-test/reactTestingLibrary';
  6. import RelatedIssues from './relatedIssues';
  7. describe('metric details -> RelatedIssues', () => {
  8. const project = ProjectFixture();
  9. it('adds environment to query parameters', async () => {
  10. const {routerContext, organization, router} = initializeOrg({
  11. router: {
  12. location: {
  13. pathname: '/mock-pathname/',
  14. query: {environment: 'test-env'},
  15. },
  16. },
  17. });
  18. const rule = MetricRuleFixture({
  19. projects: [project.slug],
  20. environment: 'production',
  21. });
  22. MockApiClient.addMockResponse({
  23. url: '/organizations/org-slug/users/',
  24. body: [],
  25. });
  26. MockApiClient.addMockResponse({
  27. url: '/organizations/org-slug/issues/?end=2017-10-17T02%3A41%3A20.000Z&environment=production&groupStatsPeriod=auto&limit=5&project=2&sort=freq&start=2017-10-17T02%3A41%3A20.000Z',
  28. body: [GroupFixture()],
  29. });
  30. render(
  31. <RelatedIssues
  32. organization={organization}
  33. projects={[project]}
  34. rule={rule}
  35. timePeriod={{
  36. display: '',
  37. start: new Date().toISOString(),
  38. end: new Date().toISOString(),
  39. label: '',
  40. period: '1d',
  41. usingPeriod: true,
  42. }}
  43. />,
  44. {context: routerContext, organization}
  45. );
  46. expect(await screen.findByTestId('group')).toBeInTheDocument();
  47. expect(router.replace).toHaveBeenCalledWith({
  48. pathname: '/mock-pathname/',
  49. query: {
  50. environment: 'production',
  51. },
  52. });
  53. // The links should contain the query parameters, our test environment isn't able to update it
  54. expect(
  55. screen.getByRole('link', {name: /Level: Warning RequestError fetchData/})
  56. ).toHaveAttribute('href', expect.stringContaining('environment=test-env'));
  57. });
  58. });