accountSubscriptions.spec.tsx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  2. import AccountSubscriptions from 'sentry/views/settings/account/accountSubscriptions';
  3. const ENDPOINT = '/users/me/subscriptions/';
  4. describe('AccountSubscriptions', function () {
  5. beforeEach(function () {
  6. MockApiClient.clearMockResponses();
  7. });
  8. it('renders empty', function () {
  9. MockApiClient.addMockResponse({
  10. url: ENDPOINT,
  11. body: [],
  12. });
  13. const wrapper = render(<AccountSubscriptions />, {
  14. context: TestStubs.routerContext(),
  15. });
  16. expect(wrapper.container).toSnapshot();
  17. });
  18. it('renders list and can toggle', async function () {
  19. MockApiClient.addMockResponse({
  20. url: ENDPOINT,
  21. body: TestStubs.Subscriptions(),
  22. });
  23. const mock = MockApiClient.addMockResponse({
  24. url: ENDPOINT,
  25. method: 'PUT',
  26. });
  27. render(<AccountSubscriptions />);
  28. expect(mock).not.toHaveBeenCalled();
  29. await userEvent.click(
  30. screen.getByRole('checkbox', {name: 'Product & Feature Updates'})
  31. );
  32. expect(mock).toHaveBeenCalledWith(
  33. ENDPOINT,
  34. expect.objectContaining({
  35. method: 'PUT',
  36. data: {
  37. listId: 2,
  38. subscribed: false,
  39. },
  40. })
  41. );
  42. });
  43. it('can handle multiple email addresses', async function () {
  44. MockApiClient.addMockResponse({
  45. url: ENDPOINT,
  46. body: [
  47. ...TestStubs.Subscriptions().map(x => ({...x, email: 'a@1.com'})),
  48. ...TestStubs.Subscriptions().map(x => ({...x, email: 'b@2.com'})),
  49. ],
  50. });
  51. const mock = MockApiClient.addMockResponse({
  52. url: ENDPOINT,
  53. method: 'PUT',
  54. });
  55. render(<AccountSubscriptions />);
  56. await userEvent.click(
  57. screen.getAllByRole('checkbox', {name: 'Sentry Newsletter'})[0]
  58. );
  59. expect(mock).toHaveBeenCalledWith(
  60. ENDPOINT,
  61. expect.objectContaining({
  62. method: 'PUT',
  63. data: {
  64. listId: 1,
  65. subscribed: true,
  66. },
  67. })
  68. );
  69. });
  70. });