projectPluginDetails.spec.tsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import {Organization} from 'sentry-fixture/organization';
  2. import {Plugin} from 'sentry-fixture/plugin';
  3. import {Plugins} from 'sentry-fixture/plugins';
  4. import {Project as ProjectFixture} from 'sentry-fixture/project';
  5. import {render, screen, userEvent, waitFor} from 'sentry-test/reactTestingLibrary';
  6. import * as indicators from 'sentry/actionCreators/indicator';
  7. import ProjectPluginDetailsContainer, {
  8. ProjectPluginDetails,
  9. } from 'sentry/views/settings/projectPlugins/details';
  10. describe('ProjectPluginDetails', function () {
  11. const organization = Organization();
  12. const project = ProjectFixture();
  13. const plugins = Plugins();
  14. const plugin = Plugin();
  15. const routerProps = TestStubs.routeComponentProps();
  16. beforeAll(function () {
  17. jest.spyOn(console, 'info').mockImplementation(() => {});
  18. });
  19. beforeEach(function () {
  20. MockApiClient.addMockResponse({
  21. url: `/projects/${organization.slug}/${project.slug}/plugins/`,
  22. method: 'GET',
  23. body: plugins,
  24. });
  25. MockApiClient.addMockResponse({
  26. url: `/projects/${organization.slug}/${project.slug}/plugins/${plugin.id}/`,
  27. method: 'DELETE',
  28. });
  29. MockApiClient.addMockResponse({
  30. url: `/projects/${organization.slug}/${project.slug}/plugins/${plugin.id}/`,
  31. method: 'GET',
  32. body: plugin,
  33. });
  34. MockApiClient.addMockResponse({
  35. url: `/projects/${organization.slug}/${project.slug}/plugins/${plugin.id}/`,
  36. method: 'POST',
  37. body: {
  38. ...plugin,
  39. config: [{value: 'default'}],
  40. },
  41. });
  42. });
  43. it('renders', function () {
  44. render(
  45. <ProjectPluginDetailsContainer
  46. {...routerProps}
  47. organization={organization}
  48. project={project}
  49. params={{
  50. projectId: project.slug,
  51. pluginId: 'amazon-sqs',
  52. }}
  53. />
  54. );
  55. });
  56. it('resets plugin', async function () {
  57. jest.spyOn(indicators, 'addSuccessMessage');
  58. render(
  59. <ProjectPluginDetails
  60. {...routerProps}
  61. organization={organization}
  62. project={project}
  63. plugins={{plugins}}
  64. params={{
  65. projectId: project.slug,
  66. pluginId: 'amazon-sqs',
  67. }}
  68. />
  69. );
  70. await userEvent.click(screen.getByRole('button', {name: 'Reset Configuration'}));
  71. await waitFor(() =>
  72. expect(indicators.addSuccessMessage).toHaveBeenCalledWith('Plugin was reset')
  73. );
  74. });
  75. it('enables/disables plugin', async function () {
  76. jest.spyOn(indicators, 'addSuccessMessage');
  77. render(
  78. <ProjectPluginDetailsContainer
  79. {...routerProps}
  80. organization={organization}
  81. project={project}
  82. params={{
  83. projectId: project.slug,
  84. pluginId: 'amazon-sqs',
  85. }}
  86. />
  87. );
  88. await userEvent.click(screen.getByRole('button', {name: 'Enable Plugin'}));
  89. await waitFor(() =>
  90. expect(indicators.addSuccessMessage).toHaveBeenCalledWith('Plugin was enabled')
  91. );
  92. });
  93. });