accountSubscriptions.spec.jsx 1.5 KB

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