123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- import React from 'react';
- import {shallow, mountWithTheme} from 'sentry-test/enzyme';
- import {Client} from 'app/api';
- import ApiTokens from 'app/views/settings/account/apiTokens';
- describe('ApiTokens', function() {
- const routerContext = TestStubs.routerContext();
- beforeEach(function() {
- Client.clearMockResponses();
- });
- it('renders empty result', function() {
- Client.addMockResponse({
- url: '/api-tokens/',
- });
- const wrapper = shallow(<ApiTokens />, routerContext);
- // Should be loading
- expect(wrapper).toMatchSnapshot();
- });
- it('renders with result', function() {
- Client.addMockResponse({
- url: '/api-tokens/',
- body: [TestStubs.ApiToken()],
- });
- const wrapper = shallow(<ApiTokens />, routerContext);
- // Should be loading
- expect(wrapper).toMatchSnapshot();
- });
- 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 />, routerContext);
- wrapper.find('.ref-delete-api-token').simulate('click');
- // Should be loading
- expect(mock).toHaveBeenCalledTimes(1);
- expect(mock).toHaveBeenCalledWith(
- '/api-tokens/',
- expect.objectContaining({
- method: 'DELETE',
- })
- );
- });
- });
|