accountNotifications.spec.jsx 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import React from 'react';
  2. import {mountWithTheme} from 'sentry-test/enzyme';
  3. import AccountNotifications from 'app/views/settings/account/accountNotifications';
  4. describe('AccountNotifications', function() {
  5. const url = '/users/me/notifications/';
  6. beforeEach(function() {
  7. MockApiClient.addMockResponse({
  8. url,
  9. method: 'GET',
  10. body: {
  11. workflowNotifications: 1,
  12. selfAssignOnResolve: false,
  13. weeklyReports: true,
  14. deployNotifications: 3,
  15. personalActivityNotifications: true,
  16. subscribeByDefault: true,
  17. },
  18. });
  19. });
  20. afterEach(function() {
  21. MockApiClient.clearMockResponses();
  22. });
  23. it('renders with values from API', function() {
  24. const wrapper = mountWithTheme(<AccountNotifications />, TestStubs.routerContext());
  25. // "Send Me Project Alerts"
  26. expect(wrapper.find('Switch[name="subscribeByDefault"]').prop('isActive')).toBe(true);
  27. // "Workflow Notifications"
  28. expect(
  29. wrapper.find('Field[id="workflowNotifications"] RadioGroup').prop('value')
  30. ).toBe(1);
  31. // "Deploy Notifications"
  32. expect(wrapper.find('Field[id="deployNotifications"] RadioGroup').prop('value')).toBe(
  33. 3
  34. );
  35. // "Notify Me About my Own Activity"
  36. expect(
  37. wrapper.find('Switch[name="personalActivityNotifications"]').prop('isActive')
  38. ).toBe(true);
  39. // "Claim Unassigned Issues"
  40. expect(wrapper.find('Switch[name="selfAssignOnResolve"]').prop('isActive')).toBe(
  41. false
  42. );
  43. });
  44. it('can change "Deploy Notifications"', function() {
  45. const wrapper = mountWithTheme(<AccountNotifications />, TestStubs.routerContext());
  46. const mock = MockApiClient.addMockResponse({
  47. url,
  48. method: 'PUT',
  49. });
  50. wrapper
  51. .find('Field[id="deployNotifications"] RadioLineItem')
  52. .at(2)
  53. .simulate('click');
  54. expect(mock).toHaveBeenCalledWith(
  55. url,
  56. expect.objectContaining({
  57. data: {deployNotifications: 4},
  58. })
  59. );
  60. });
  61. });