projectPluginDetails.spec.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. plugins={{plugins: []}}
  49. location={router.location}
  50. route={{}}
  51. routeParams={router.params}
  52. router={router}
  53. routes={router.routes}
  54. />
  55. );
  56. expect(container).toSnapshot();
  57. });
  58. it('resets plugin', async function () {
  59. jest.spyOn(indicators, 'addSuccessMessage');
  60. render(
  61. <ProjectPluginDetails
  62. organization={organization}
  63. project={project}
  64. plugins={{plugins}}
  65. params={{
  66. projectId: project.slug,
  67. pluginId: 'amazon-sqs',
  68. }}
  69. location={router.location}
  70. route={{}}
  71. routeParams={router.params}
  72. router={router}
  73. routes={router.routes}
  74. />
  75. );
  76. await userEvent.click(screen.getByRole('button', {name: 'Reset Configuration'}));
  77. await waitFor(() =>
  78. expect(indicators.addSuccessMessage).toHaveBeenCalledWith('Plugin was reset')
  79. );
  80. });
  81. it('enables/disables plugin', async function () {
  82. jest.spyOn(indicators, 'addSuccessMessage');
  83. render(
  84. <ProjectPluginDetailsContainer
  85. organization={organization}
  86. project={project}
  87. plugins={{plugins}}
  88. params={{
  89. projectId: project.slug,
  90. pluginId: 'amazon-sqs',
  91. }}
  92. location={router.location}
  93. route={{}}
  94. routeParams={router.params}
  95. router={router}
  96. routes={router.routes}
  97. />
  98. );
  99. await userEvent.click(screen.getByRole('button', {name: 'Enable Plugin'}));
  100. await waitFor(() =>
  101. expect(indicators.addSuccessMessage).toHaveBeenCalledWith('Plugin was enabled')
  102. );
  103. });
  104. });