docsSearchModal.spec.jsx 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import React from 'react';
  2. import {mount} from 'enzyme';
  3. import {openDocsSearchModal} from 'app/actionCreators/modal';
  4. import App from 'app/views/app';
  5. describe('Docs Search Modal', function() {
  6. beforeEach(function() {
  7. MockApiClient.clearMockResponses();
  8. MockApiClient.addMockResponse({
  9. url: '/organizations/',
  10. body: [TestStubs.Organization({slug: 'billy-org', name: 'billy org'})],
  11. });
  12. MockApiClient.addMockResponse({
  13. url: '/organizations/org-slug/projects/',
  14. query: 'foo',
  15. body: [TestStubs.Project({slug: 'foo-project'})],
  16. });
  17. MockApiClient.addMockResponse({
  18. url: '/organizations/org-slug/teams/',
  19. query: 'foo',
  20. body: [TestStubs.Team({slug: 'foo-team'})],
  21. });
  22. MockApiClient.addMockResponse({
  23. url: '/organizations/org-slug/members/',
  24. query: 'foo',
  25. body: TestStubs.Members(),
  26. });
  27. MockApiClient.addMockResponse({
  28. url: '/organizations/org-slug/plugins/?plugins=_all',
  29. query: 'foo',
  30. body: [],
  31. });
  32. MockApiClient.addMockResponse({
  33. url: '/organizations/org-slug/config/integrations/',
  34. query: 'foo',
  35. body: [],
  36. });
  37. MockApiClient.addMockResponse({
  38. url: '/internal/health/',
  39. body: {
  40. problems: [],
  41. },
  42. });
  43. MockApiClient.addMockResponse({
  44. url: '/assistant/',
  45. body: [],
  46. });
  47. });
  48. it('can open docs search modal and search', async function() {
  49. let wrapper = mount(
  50. <App params={{orgId: 'org-slug'}}>{<div>placeholder content</div>}</App>,
  51. TestStubs.routerContext([
  52. {
  53. router: TestStubs.router({
  54. params: {orgId: 'org-slug'},
  55. }),
  56. },
  57. ])
  58. );
  59. // No Modal
  60. expect(wrapper.find('ModalDialog')).toHaveLength(0);
  61. openDocsSearchModal();
  62. await tick();
  63. await tick();
  64. wrapper.update();
  65. // Should have Modal + input
  66. expect(wrapper.find('ModalDialog')).toHaveLength(1);
  67. let stub = sinon.stub($, 'get', (url, cb) => {
  68. if (url.includes('rigidsearch')) {
  69. cb({
  70. items: [
  71. {path: 'clients/node#sourcemaps', title: 'Source Maps'},
  72. {path: 'clients/java/modules/logback#usage', title: 'Usage'},
  73. ],
  74. });
  75. } else {
  76. cb({
  77. results: [
  78. {html_url: 'https://help.sentry.io/100', title: '100'},
  79. {html_url: 'https://help.sentry.io/200', title: '200'},
  80. ],
  81. });
  82. }
  83. });
  84. wrapper.find('ModalDialog input').simulate('change', {target: {value: 'dummy'}});
  85. await tick();
  86. wrapper.update();
  87. expect(wrapper.find('SearchResultWrapper')).toHaveLength(4);
  88. expect(wrapper.find('SearchSources DropdownBox')).toMatchSnapshot();
  89. stub.restore();
  90. });
  91. });