accountSubscriptions.spec.jsx 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  2. import {Client} from 'sentry/api';
  3. import AccountSubscriptions from 'sentry/views/settings/account/accountSubscriptions';
  4. const ENDPOINT = '/users/me/subscriptions/';
  5. describe('AccountSubscriptions', function () {
  6. beforeEach(function () {
  7. Client.clearMockResponses();
  8. });
  9. it('renders empty', function () {
  10. Client.addMockResponse({
  11. url: ENDPOINT,
  12. body: [],
  13. });
  14. const wrapper = render(<AccountSubscriptions />, {
  15. context: TestStubs.routerContext(),
  16. });
  17. expect(wrapper.container).toSnapshot();
  18. });
  19. it('renders list and can toggle', async function () {
  20. Client.addMockResponse({
  21. url: ENDPOINT,
  22. body: TestStubs.Subscriptions(),
  23. });
  24. const mock = Client.addMockResponse({
  25. url: ENDPOINT,
  26. method: 'PUT',
  27. });
  28. const wrapper = render(<AccountSubscriptions />, {
  29. context: TestStubs.routerContext(),
  30. });
  31. expect(wrapper.container).toSnapshot();
  32. expect(mock).not.toHaveBeenCalled();
  33. await userEvent.click(screen.getAllByTestId('switch')[0]);
  34. expect(mock).toHaveBeenCalledWith(
  35. ENDPOINT,
  36. expect.objectContaining({
  37. method: 'PUT',
  38. data: {
  39. listId: 2,
  40. subscribed: false,
  41. },
  42. })
  43. );
  44. });
  45. });