apiTokenRow.spec.tsx 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import {ApiTokenFixture} from 'sentry-fixture/apiToken';
  2. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  3. import ApiTokenRow from 'sentry/views/settings/account/apiTokenRow';
  4. describe('ApiTokenRow', () => {
  5. it('renders', () => {
  6. render(<ApiTokenRow onRemove={() => {}} token={ApiTokenFixture()} />);
  7. });
  8. it('calls onRemove callback when trash can is clicked', async () => {
  9. const cb = jest.fn();
  10. render(<ApiTokenRow onRemove={cb} token={ApiTokenFixture()} />);
  11. await userEvent.click(screen.getByLabelText('Remove'));
  12. expect(cb).toHaveBeenCalled();
  13. });
  14. it('uses NewTokenHandler when lastTokenCharacters field is found', () => {
  15. const token = ApiTokenFixture();
  16. token.tokenLastCharacters = 'a1b2c3d4';
  17. const cb = jest.fn();
  18. render(<ApiTokenRow onRemove={cb} token={token} />);
  19. expect(screen.queryByLabelText('Token preview')).toBeInTheDocument();
  20. });
  21. it('uses old logic when lastTokenCharacters field is not found', () => {
  22. const token = ApiTokenFixture();
  23. const cb = jest.fn();
  24. render(<ApiTokenRow onRemove={cb} token={token} />);
  25. expect(screen.queryByLabelText('Token preview')).not.toBeInTheDocument();
  26. });
  27. });