relatedIssues.spec.tsx 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 {router, organization} = 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. {router, 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(screen.getByRole('link', {name: /RequestError fetchData/})).toHaveAttribute(
  55. 'href',
  56. expect.stringContaining('environment=test-env')
  57. );
  58. });
  59. });