apiTokenRow.spec.tsx 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import {ApiTokenFixture} from 'sentry-fixture/apiToken';
  2. import {
  3. render,
  4. renderGlobalModal,
  5. screen,
  6. userEvent,
  7. } from 'sentry-test/reactTestingLibrary';
  8. import ApiTokenRow from 'sentry/views/settings/account/apiTokenRow';
  9. describe('ApiTokenRow', () => {
  10. it('renders link when can edit', () => {
  11. render(
  12. <ApiTokenRow
  13. onRemove={() => {}}
  14. token={ApiTokenFixture({id: '1', name: 'token1'})}
  15. canEdit
  16. />
  17. );
  18. screen.getByRole('link', {name: /token1/i});
  19. });
  20. it('renders text when cannot edit', () => {
  21. render(
  22. <ApiTokenRow
  23. onRemove={() => {}}
  24. token={ApiTokenFixture({id: '1', name: 'token1'})}
  25. />
  26. );
  27. screen.getByRole('heading', {name: /token1/i});
  28. });
  29. it('calls onRemove callback when trash can is clicked', async () => {
  30. const cb = jest.fn();
  31. render(<ApiTokenRow onRemove={cb} token={ApiTokenFixture()} canEdit />);
  32. renderGlobalModal();
  33. await userEvent.click(screen.getByLabelText('Remove'));
  34. await userEvent.click(screen.getByLabelText('Confirm'));
  35. expect(cb).toHaveBeenCalled();
  36. });
  37. it('uses NewTokenHandler when lastTokenCharacters field is found', () => {
  38. const token = ApiTokenFixture();
  39. token.tokenLastCharacters = 'a1b2c3d4';
  40. const cb = jest.fn();
  41. render(<ApiTokenRow onRemove={cb} token={token} canEdit />);
  42. expect(screen.queryByLabelText('Token preview')).toBeInTheDocument();
  43. });
  44. });