accountSubscriptions.spec.tsx 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import {Subscriptions} 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. context: TestStubs.routerContext(),
  16. });
  17. });
  18. it('renders list and can toggle', async function () {
  19. MockApiClient.addMockResponse({
  20. url: ENDPOINT,
  21. body: 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. ...Subscriptions().map(x => ({...x, email: 'a@1.com'})),
  48. ...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. });