apiTokenRow.spec.tsx 1.1 KB

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