projectPluginDetails.spec.jsx 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. import React from 'react';
  2. import {mountWithTheme} from 'sentry-test/enzyme';
  3. import ProjectPluginDetailsContainer, {
  4. ProjectPluginDetails,
  5. } from 'app/views/settings/projectPlugins/details';
  6. jest.mock('jquery');
  7. describe('ProjectPluginDetails', function() {
  8. let component;
  9. const routerContext = TestStubs.routerContext();
  10. const {organization, project} = routerContext.context;
  11. const org = organization;
  12. const plugins = TestStubs.Plugins();
  13. const plugin = TestStubs.Plugin();
  14. const pluginId = plugin.id;
  15. beforeAll(function() {
  16. jest.spyOn(console, 'info').mockImplementation(() => {});
  17. });
  18. beforeEach(function() {
  19. MockApiClient.addMockResponse({
  20. url: `/projects/${org.slug}/${project.slug}/plugins/`,
  21. method: 'GET',
  22. body: plugins,
  23. });
  24. MockApiClient.addMockResponse({
  25. url: `/projects/${org.slug}/${project.slug}/plugins/${pluginId}/`,
  26. method: 'DELETE',
  27. });
  28. MockApiClient.addMockResponse({
  29. url: `/projects/${org.slug}/${project.slug}/plugins/${pluginId}/`,
  30. method: 'GET',
  31. body: plugin,
  32. });
  33. MockApiClient.addMockResponse({
  34. url: `/projects/${org.slug}/${project.slug}/plugins/${pluginId}/`,
  35. method: 'POST',
  36. body: {
  37. ...plugin,
  38. config: [{value: 'default'}],
  39. },
  40. });
  41. component = mountWithTheme(
  42. <ProjectPluginDetailsContainer
  43. organization={org}
  44. project={project}
  45. params={{orgId: org.slug, projectId: project.slug, pluginId: 'amazon-sqs'}}
  46. location={TestStubs.location()}
  47. />,
  48. routerContext
  49. );
  50. });
  51. afterAll(function() {
  52. // eslint-disable-next-line no-console
  53. console.info.restore();
  54. });
  55. it('renders', function() {
  56. expect(component).toMatchSnapshot();
  57. });
  58. it('resets plugin', function() {
  59. // Test component instead of container so that we can access state
  60. const wrapper = mountWithTheme(
  61. <ProjectPluginDetails
  62. organization={org}
  63. project={project}
  64. plugins={TestStubs.Plugins()}
  65. params={{orgId: org.slug, projectId: project.slug, pluginId: 'amazon-sqs'}}
  66. location={TestStubs.location()}
  67. />,
  68. routerContext
  69. );
  70. const btn = wrapper.find('button').at(1);
  71. btn.simulate('click');
  72. expect(wrapper.state().pluginDetails.config[0].value).toBe('default');
  73. });
  74. it('enables/disables plugin', function(done) {
  75. const btn = component.find('button').first();
  76. expect(btn.text()).toBe('Enable Plugin');
  77. btn.simulate('click');
  78. setTimeout(() => {
  79. try {
  80. component.update();
  81. expect(btn.text()).toBe('Disable Plugin');
  82. done();
  83. } catch (err) {
  84. done(err);
  85. }
  86. }, 1);
  87. });
  88. });