accountSubscriptions.spec.tsx 2.0 KB

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