index.spec.tsx 3.2 KB

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