shortIdBreadcrumb.spec.tsx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import {GroupFixture} from 'sentry-fixture/group';
  2. import {initializeOrg} from 'sentry-test/initializeOrg';
  3. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  4. import {ShortIdBreadrcumb} from './shortIdBreadcrumb';
  5. describe('ShortIdBreadrcumb', function () {
  6. const {organization, project} = initializeOrg();
  7. const group = GroupFixture({shortId: 'ABC-123'});
  8. beforeEach(() => {
  9. Object.assign(navigator, {
  10. clipboard: {writeText: jest.fn().mockResolvedValue('')},
  11. });
  12. });
  13. it('renders short ID', function () {
  14. render(<ShortIdBreadrcumb {...{organization, project, group}} />);
  15. expect(screen.getByText('ABC-123')).toBeInTheDocument();
  16. });
  17. it('supports copy', async function () {
  18. render(<ShortIdBreadrcumb {...{organization, project, group}} />);
  19. async function clickMenuItem(name: string) {
  20. await userEvent.click(screen.getByRole('button', {name: 'Short-ID copy actions'}));
  21. await userEvent.click(screen.getByRole('menuitemradio', {name}));
  22. }
  23. // Copy short ID
  24. await clickMenuItem('Copy Short-ID');
  25. expect(navigator.clipboard.writeText).toHaveBeenCalledWith('ABC-123');
  26. // Copy short ID URL
  27. await clickMenuItem('Copy Issue URL');
  28. expect(navigator.clipboard.writeText).toHaveBeenCalledWith(
  29. 'http://localhost/organizations/org-slug/issues/1/'
  30. );
  31. // Copy short ID Markdown
  32. await clickMenuItem('Copy Markdown Link');
  33. expect(navigator.clipboard.writeText).toHaveBeenCalledWith(
  34. '[ABC-123](http://localhost/organizations/org-slug/issues/1/)'
  35. );
  36. });
  37. });