1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- import {mountWithTheme} from 'sentry-test/enzyme';
- import {Client} from 'sentry/api';
- import {ApiTokens} from 'sentry/views/settings/account/apiTokens';
- const organization = TestStubs.Organization();
- describe('ApiTokens', function () {
- const routerContext = TestStubs.routerContext();
- beforeEach(function () {
- Client.clearMockResponses();
- });
- it('renders empty result', function () {
- Client.addMockResponse({
- url: '/api-tokens/',
- body: null,
- });
- const wrapper = mountWithTheme(
- <ApiTokens organization={organization} />,
- routerContext
- );
- // Should be loading
- expect(wrapper).toSnapshot();
- });
- it('renders with result', function () {
- Client.addMockResponse({
- url: '/api-tokens/',
- body: [TestStubs.ApiToken()],
- });
- const wrapper = mountWithTheme(
- <ApiTokens organization={organization} />,
- routerContext
- );
- // Should be loading
- expect(wrapper).toSnapshot();
- });
- it('can delete token', function () {
- Client.addMockResponse({
- url: '/api-tokens/',
- body: [TestStubs.ApiToken()],
- });
- const mock = Client.addMockResponse({
- url: '/api-tokens/',
- method: 'DELETE',
- });
- expect(mock).not.toHaveBeenCalled();
- const wrapper = mountWithTheme(
- <ApiTokens organization={organization} />,
- routerContext
- );
- wrapper.find('button[aria-label="Remove"]').simulate('click');
- // Should be loading
- expect(mock).toHaveBeenCalledTimes(1);
- expect(mock).toHaveBeenCalledWith(
- '/api-tokens/',
- expect.objectContaining({
- method: 'DELETE',
- })
- );
- });
- });
|