index.spec.jsx 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import {getByRole, render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  2. import {disablePlugin, enablePlugin, fetchPlugins} from 'sentry/actionCreators/plugins';
  3. import {ProjectPluginsContainer} from 'sentry/views/settings/projectPlugins';
  4. jest.mock('sentry/actionCreators/plugins', () => ({
  5. fetchPlugins: jest.fn().mockResolvedValue([]),
  6. enablePlugin: jest.fn(),
  7. disablePlugin: jest.fn(),
  8. }));
  9. describe('ProjectPluginsContainer', function () {
  10. let org, project, plugins, params;
  11. beforeEach(function () {
  12. org = TestStubs.Organization();
  13. project = TestStubs.Project();
  14. plugins = TestStubs.Plugins([
  15. {
  16. enabled: true,
  17. id: 'disableable plugin',
  18. name: 'Disableable Plugin',
  19. slug: 'disableable plugin',
  20. canDisable: true,
  21. },
  22. ]);
  23. params = {
  24. projectId: project.slug,
  25. };
  26. MockApiClient.addMockResponse({
  27. url: `/organizations/${org.slug}/`,
  28. method: 'GET',
  29. body: org,
  30. });
  31. MockApiClient.addMockResponse({
  32. url: `/organizations/${org.slug}/integrations/`,
  33. method: 'GET',
  34. body: [],
  35. });
  36. MockApiClient.addMockResponse({
  37. url: `/projects/${org.slug}/${project.slug}/plugins/`,
  38. method: 'GET',
  39. body: plugins,
  40. });
  41. MockApiClient.addMockResponse({
  42. url: `/projects/${org.slug}/${project.slug}/plugins/amazon-sqs/`,
  43. method: 'POST',
  44. });
  45. MockApiClient.addMockResponse({
  46. url: `/projects/${org.slug}/${project.slug}/plugins/github/`,
  47. method: 'DELETE',
  48. });
  49. render(
  50. <ProjectPluginsContainer
  51. plugins={{plugins, loading: false}}
  52. params={params}
  53. organization={org}
  54. project={project}
  55. />
  56. );
  57. });
  58. it('calls `fetchPlugins` action creator after mount', function () {
  59. expect(fetchPlugins).toHaveBeenCalled();
  60. });
  61. it('calls `enablePlugin` action creator when enabling plugin', async function () {
  62. const pluginItem = (await screen.findByText('Amazon SQS')).parentElement.parentElement
  63. .parentElement;
  64. const button = getByRole(pluginItem, 'checkbox');
  65. expect(enablePlugin).not.toHaveBeenCalled();
  66. userEvent.click(button);
  67. expect(enablePlugin).toHaveBeenCalled();
  68. });
  69. it('calls `disablePlugin` action creator when disabling plugin', async function () {
  70. const pluginItem = (await screen.findByText('Disableable Plugin')).parentElement
  71. .parentElement.parentElement;
  72. const button = getByRole(pluginItem, 'checkbox');
  73. expect(disablePlugin).not.toHaveBeenCalled();
  74. userEvent.click(button);
  75. expect(disablePlugin).toHaveBeenCalled();
  76. });
  77. });