index.spec.tsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import {Organization} from 'sentry-fixture/organization';
  2. import {getByRole, render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  3. import {disablePlugin, enablePlugin, fetchPlugins} from 'sentry/actionCreators/plugins';
  4. import type {Organization as TOrganization, Plugin, Project} from 'sentry/types';
  5. import {ProjectPluginsContainer} from 'sentry/views/settings/projectPlugins';
  6. jest.mock('sentry/actionCreators/plugins', () => ({
  7. fetchPlugins: jest.fn().mockResolvedValue([]),
  8. enablePlugin: jest.fn(),
  9. disablePlugin: jest.fn(),
  10. }));
  11. describe('ProjectPluginsContainer', function () {
  12. let org: TOrganization,
  13. project: Project,
  14. plugins: Plugin[],
  15. params: {projectId: string};
  16. beforeEach(function () {
  17. org = Organization();
  18. project = TestStubs.Project();
  19. plugins = TestStubs.Plugins([
  20. {
  21. enabled: true,
  22. id: 'disableable plugin',
  23. name: 'Disableable Plugin',
  24. slug: 'disableable plugin',
  25. canDisable: true,
  26. },
  27. ]);
  28. params = {
  29. projectId: project.slug,
  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. {...TestStubs.routeComponentProps()}
  57. plugins={{plugins, loading: false, error: undefined}}
  58. params={params}
  59. organization={org}
  60. project={project}
  61. />
  62. );
  63. });
  64. it('calls `fetchPlugins` action creator after mount', function () {
  65. expect(fetchPlugins).toHaveBeenCalled();
  66. });
  67. it('calls `enablePlugin` action creator when enabling plugin', async function () {
  68. const amazonSQS = await screen.findByText('Amazon SQS');
  69. const pluginItem = amazonSQS.parentElement?.parentElement?.parentElement;
  70. if (!pluginItem) {
  71. return;
  72. }
  73. const button = getByRole(pluginItem, 'checkbox');
  74. expect(enablePlugin).not.toHaveBeenCalled();
  75. await userEvent.click(button);
  76. expect(enablePlugin).toHaveBeenCalled();
  77. });
  78. it('calls `disablePlugin` action creator when disabling plugin', async function () {
  79. const disabledPlugin = await screen.findByText('Disableable Plugin');
  80. const pluginItem = disabledPlugin.parentElement?.parentElement?.parentElement;
  81. if (!pluginItem) {
  82. return;
  83. }
  84. const button = getByRole(pluginItem, 'checkbox');
  85. expect(disablePlugin).not.toHaveBeenCalled();
  86. await userEvent.click(button);
  87. expect(disablePlugin).toHaveBeenCalled();
  88. });
  89. });