projectPluginDetails.spec.jsx 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import {mount} from 'enzyme';
  4. import ProjectPluginDetailsContainer, {
  5. ProjectPluginDetails,
  6. } from 'app/views/projectPluginDetails';
  7. jest.mock('jquery');
  8. describe('ProjectPluginDetails', function() {
  9. let component;
  10. let org = TestStubs.Organization();
  11. let project = TestStubs.Project();
  12. let plugins = TestStubs.Plugins();
  13. let plugin = TestStubs.Plugin();
  14. let pluginId = plugin.id;
  15. beforeEach(function() {
  16. MockApiClient.addMockResponse({
  17. url: `/projects/${org.slug}/${project.slug}/plugins/`,
  18. method: 'GET',
  19. body: plugins,
  20. });
  21. MockApiClient.addMockResponse({
  22. url: `/projects/${org.slug}/${project.slug}/plugins/${pluginId}/`,
  23. method: 'DELETE',
  24. });
  25. MockApiClient.addMockResponse({
  26. url: `/projects/${org.slug}/${project.slug}/plugins/${pluginId}/`,
  27. method: 'GET',
  28. body: plugin,
  29. });
  30. MockApiClient.addMockResponse({
  31. url: `/projects/${org.slug}/${project.slug}/plugins/${pluginId}/`,
  32. method: 'POST',
  33. body: {
  34. ...plugin,
  35. config: [{value: 'default'}],
  36. },
  37. });
  38. component = mount(
  39. <ProjectPluginDetailsContainer
  40. organization={org}
  41. project={project}
  42. params={{orgId: org.slug, projectId: project.slug, pluginId: 'amazon-sqs'}}
  43. location={TestStubs.location()}
  44. />,
  45. {
  46. context: {
  47. router: TestStubs.router(),
  48. },
  49. childContextTypes: {
  50. router: PropTypes.object,
  51. },
  52. }
  53. );
  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. let wrapper = mount(
  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. {
  69. context: {
  70. router: TestStubs.router(),
  71. },
  72. childContextTypes: {
  73. router: PropTypes.object,
  74. },
  75. }
  76. );
  77. let btn = wrapper.find('button').at(1);
  78. btn.simulate('click');
  79. expect(wrapper.state().pluginDetails.config[0].value).toBe('default');
  80. });
  81. it('enables/disables plugin', function(done) {
  82. let btn = component.find('button').first();
  83. expect(btn.text()).toBe('Enable Plugin');
  84. btn.simulate('click');
  85. setTimeout(() => {
  86. try {
  87. component.update();
  88. expect(btn.text()).toBe('Disable Plugin');
  89. done();
  90. } catch (err) {
  91. done(err);
  92. }
  93. }, 1);
  94. });
  95. });