apiTokenRow.spec.tsx 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  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', () => {
  11. render(<ApiTokenRow onRemove={() => {}} token={ApiTokenFixture()} />);
  12. });
  13. it('calls onRemove callback when trash can is clicked', async () => {
  14. const cb = jest.fn();
  15. render(<ApiTokenRow onRemove={cb} token={ApiTokenFixture()} />);
  16. renderGlobalModal();
  17. await userEvent.click(screen.getByLabelText('Remove'));
  18. await userEvent.click(screen.getByLabelText('Confirm'));
  19. expect(cb).toHaveBeenCalled();
  20. });
  21. it('uses NewTokenHandler when lastTokenCharacters field is found', () => {
  22. const token = ApiTokenFixture();
  23. token.tokenLastCharacters = 'a1b2c3d4';
  24. const cb = jest.fn();
  25. render(<ApiTokenRow onRemove={cb} token={token} />);
  26. expect(screen.queryByLabelText('Token preview')).toBeInTheDocument();
  27. });
  28. });