accountSubscriptions.spec.jsx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import * as PropTypes from 'prop-types';
  2. import {mountWithTheme} from 'sentry-test/enzyme';
  3. import {Client} from 'sentry/api';
  4. import AccountSubscriptions from 'sentry/views/settings/account/accountSubscriptions';
  5. const ENDPOINT = '/users/me/subscriptions/';
  6. describe('AccountSubscriptions', function () {
  7. beforeEach(function () {
  8. Client.clearMockResponses();
  9. });
  10. it('renders empty', function () {
  11. Client.addMockResponse({
  12. url: ENDPOINT,
  13. body: [],
  14. });
  15. const wrapper = mountWithTheme(<AccountSubscriptions />, {
  16. context: {
  17. router: TestStubs.router(),
  18. },
  19. childContextTypes: {
  20. router: PropTypes.object,
  21. },
  22. });
  23. expect(wrapper).toSnapshot();
  24. });
  25. it('renders list and can toggle', function () {
  26. Client.addMockResponse({
  27. url: ENDPOINT,
  28. body: TestStubs.Subscriptions(),
  29. });
  30. const mock = Client.addMockResponse({
  31. url: ENDPOINT,
  32. method: 'PUT',
  33. });
  34. const wrapper = mountWithTheme(<AccountSubscriptions />, {
  35. context: {
  36. router: TestStubs.router(),
  37. },
  38. childContextTypes: {
  39. router: PropTypes.object,
  40. },
  41. });
  42. expect(wrapper).toSnapshot();
  43. expect(mock).not.toHaveBeenCalled();
  44. wrapper.find('Switch').first().simulate('click');
  45. expect(mock).toHaveBeenCalledWith(
  46. ENDPOINT,
  47. expect.objectContaining({
  48. method: 'PUT',
  49. data: {
  50. listId: 2,
  51. subscribed: false,
  52. },
  53. })
  54. );
  55. });
  56. });