accountSubscriptions.spec.tsx 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. render(<AccountSubscriptions />, {
  14. context: TestStubs.routerContext(),
  15. });
  16. });
  17. it('renders list and can toggle', async function () {
  18. MockApiClient.addMockResponse({
  19. url: ENDPOINT,
  20. body: TestStubs.Subscriptions(),
  21. });
  22. const mock = MockApiClient.addMockResponse({
  23. url: ENDPOINT,
  24. method: 'PUT',
  25. });
  26. render(<AccountSubscriptions />);
  27. expect(mock).not.toHaveBeenCalled();
  28. await userEvent.click(
  29. screen.getByRole('checkbox', {name: 'Product & Feature Updates'})
  30. );
  31. expect(mock).toHaveBeenCalledWith(
  32. ENDPOINT,
  33. expect.objectContaining({
  34. method: 'PUT',
  35. data: {
  36. listId: 2,
  37. subscribed: false,
  38. },
  39. })
  40. );
  41. });
  42. it('can handle multiple email addresses', async function () {
  43. MockApiClient.addMockResponse({
  44. url: ENDPOINT,
  45. body: [
  46. ...TestStubs.Subscriptions().map(x => ({...x, email: 'a@1.com'})),
  47. ...TestStubs.Subscriptions().map(x => ({...x, email: 'b@2.com'})),
  48. ],
  49. });
  50. const mock = MockApiClient.addMockResponse({
  51. url: ENDPOINT,
  52. method: 'PUT',
  53. });
  54. render(<AccountSubscriptions />);
  55. await userEvent.click(
  56. screen.getAllByRole('checkbox', {name: 'Sentry Newsletter'})[0]
  57. );
  58. expect(mock).toHaveBeenCalledWith(
  59. ENDPOINT,
  60. expect.objectContaining({
  61. method: 'PUT',
  62. data: {
  63. listId: 1,
  64. subscribed: true,
  65. },
  66. })
  67. );
  68. });
  69. });