shortIdBreadcrumb.spec.tsx 1.5 KB

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