groupTags.spec.tsx 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import {GroupFixture} from 'sentry-fixture/group';
  2. import {TagsFixture} from 'sentry-fixture/tags';
  3. import {initializeOrg} from 'sentry-test/initializeOrg';
  4. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  5. import GroupTags from 'sentry/views/issueDetails/groupTags';
  6. describe('GroupTags', function () {
  7. const {routerProps, router, organization} = initializeOrg();
  8. const group = GroupFixture();
  9. let tagsMock;
  10. beforeEach(function () {
  11. tagsMock = MockApiClient.addMockResponse({
  12. url: '/organizations/org-slug/issues/1/tags/',
  13. body: TagsFixture(),
  14. });
  15. });
  16. it('navigates to issue details events tab with correct query params', async function () {
  17. render(
  18. <GroupTags
  19. {...routerProps}
  20. group={group}
  21. environments={['dev']}
  22. baseUrl={`/organizations/${organization.slug}/issues/${group.id}/`}
  23. />,
  24. {router, organization}
  25. );
  26. const headers = await screen.findAllByTestId('tag-title');
  27. expect(tagsMock).toHaveBeenCalledWith(
  28. '/organizations/org-slug/issues/1/tags/',
  29. expect.objectContaining({
  30. query: {environment: ['dev']},
  31. })
  32. );
  33. // Check headers have been sorted alphabetically
  34. expect(headers.map(h => h.innerHTML)).toEqual([
  35. 'browser',
  36. 'device',
  37. 'environment',
  38. 'url',
  39. 'user',
  40. ]);
  41. await userEvent.click(screen.getByText('david'));
  42. expect(router.push).toHaveBeenCalledWith({
  43. pathname: '/organizations/org-slug/issues/1/events/',
  44. query: {query: 'user.username:david'},
  45. });
  46. });
  47. it('shows an error message when the request fails', async function () {
  48. MockApiClient.addMockResponse({
  49. url: '/organizations/org-slug/issues/1/tags/',
  50. statusCode: 500,
  51. });
  52. render(
  53. <GroupTags
  54. {...routerProps}
  55. group={group}
  56. environments={['dev']}
  57. baseUrl={`/organizations/${organization.slug}/issues/${group.id}/`}
  58. />,
  59. {router, organization}
  60. );
  61. expect(
  62. await screen.findByText('There was an error loading issue tags.')
  63. ).toBeInTheDocument();
  64. });
  65. });