index.spec.tsx 2.9 KB

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