projectPluginDetails.spec.jsx 2.5 KB

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