index.spec.jsx 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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, organization;
  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. orgId: org.slug,
  25. projectId: project.slug,
  26. };
  27. organization = {
  28. id: org.slug,
  29. features: [],
  30. };
  31. MockApiClient.addMockResponse({
  32. url: `/organizations/${org.slug}/`,
  33. method: 'GET',
  34. body: org,
  35. });
  36. MockApiClient.addMockResponse({
  37. url: `/organizations/${org.slug}/integrations/`,
  38. method: 'GET',
  39. body: [],
  40. });
  41. MockApiClient.addMockResponse({
  42. url: `/projects/${org.slug}/${project.slug}/plugins/`,
  43. method: 'GET',
  44. body: plugins,
  45. });
  46. MockApiClient.addMockResponse({
  47. url: `/projects/${org.slug}/${project.slug}/plugins/amazon-sqs/`,
  48. method: 'POST',
  49. });
  50. MockApiClient.addMockResponse({
  51. url: `/projects/${org.slug}/${project.slug}/plugins/github/`,
  52. method: 'DELETE',
  53. });
  54. render(
  55. <ProjectPluginsContainer
  56. plugins={{plugins, loading: false}}
  57. params={params}
  58. organization={organization}
  59. />
  60. );
  61. });
  62. it('calls `fetchPlugins` action creator after mount', function () {
  63. expect(fetchPlugins).toHaveBeenCalled();
  64. });
  65. it('calls `enablePlugin` action creator when enabling plugin', async function () {
  66. const pluginItem = (await screen.findByText('Amazon SQS')).parentElement.parentElement
  67. .parentElement;
  68. const button = getByRole(pluginItem, 'checkbox');
  69. expect(enablePlugin).not.toHaveBeenCalled();
  70. userEvent.click(button);
  71. expect(enablePlugin).toHaveBeenCalled();
  72. });
  73. it('calls `disablePlugin` action creator when disabling plugin', async function () {
  74. const pluginItem = (await screen.findByText('Disableable Plugin')).parentElement
  75. .parentElement.parentElement;
  76. const button = getByRole(pluginItem, 'checkbox');
  77. expect(disablePlugin).not.toHaveBeenCalled();
  78. userEvent.click(button);
  79. expect(disablePlugin).toHaveBeenCalled();
  80. });
  81. });