index.spec.tsx 3.4 KB

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