accountSubscriptions.spec.tsx 1.9 KB

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