index.spec.tsx 3.1 KB

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