projectPluginDetails.spec.tsx 3.1 KB

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