index.spec.tsx 3.3 KB

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