actions.spec.jsx 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. import {mountWithTheme} from 'sentry-test/enzyme';
  2. import {makePinSearchAction} from 'sentry/components/smartSearchBar/actions';
  3. describe('SmartSearchBarActions', () => {
  4. describe('make', function () {
  5. const organization = TestStubs.Organization({id: '123'});
  6. const api = new MockApiClient();
  7. let pinRequest, unpinRequest, location, options;
  8. beforeEach(function () {
  9. location = {
  10. pathname: `/organizations/${organization.slug}/recent-searches/`,
  11. query: {
  12. projectId: '0',
  13. },
  14. };
  15. options = TestStubs.routerContext([
  16. {
  17. organization,
  18. },
  19. ]);
  20. pinRequest = MockApiClient.addMockResponse({
  21. url: `/organizations/${organization.slug}/pinned-searches/`,
  22. method: 'PUT',
  23. body: [],
  24. });
  25. unpinRequest = MockApiClient.addMockResponse({
  26. url: `/organizations/${organization.slug}/pinned-searches/`,
  27. method: 'DELETE',
  28. body: [],
  29. });
  30. MockApiClient.addMockResponse({
  31. url: `/organizations/${organization.slug}/recent-searches/`,
  32. method: 'POST',
  33. body: {},
  34. });
  35. });
  36. it('does not pin when query is empty', function () {
  37. const {Action} = makePinSearchAction({sort: ''});
  38. const wrapper = mountWithTheme(
  39. <Action
  40. api={api}
  41. organization={organization}
  42. query=""
  43. savedSearchType={0}
  44. location={location}
  45. />,
  46. options
  47. );
  48. wrapper.find('ActionButton button').simulate('click');
  49. wrapper.update();
  50. expect(pinRequest).not.toHaveBeenCalled();
  51. });
  52. it('adds pins', function () {
  53. const {Action} = makePinSearchAction({sort: ''});
  54. const wrapper = mountWithTheme(
  55. <Action
  56. api={api}
  57. organization={organization}
  58. query="is:unresolved"
  59. savedSearchType={0}
  60. location={location}
  61. />,
  62. options
  63. );
  64. wrapper.find('ActionButton button').simulate('click');
  65. wrapper.update();
  66. expect(pinRequest).toHaveBeenCalled();
  67. expect(unpinRequest).not.toHaveBeenCalled();
  68. });
  69. it('removes pins', function () {
  70. const pinnedSearch = TestStubs.Search({isPinned: true});
  71. const {Action} = makePinSearchAction({pinnedSearch, sort: ''});
  72. const wrapper = mountWithTheme(
  73. <Action
  74. api={api}
  75. organization={organization}
  76. query="is:unresolved"
  77. savedSearchType={0}
  78. location={location}
  79. />,
  80. options
  81. );
  82. wrapper.find('ActionButton button').simulate('click');
  83. wrapper.update();
  84. expect(pinRequest).not.toHaveBeenCalled();
  85. expect(unpinRequest).toHaveBeenCalled();
  86. });
  87. });
  88. });