projectPluginDetails.spec.tsx 3.3 KB

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