projectPluginDetails.spec.tsx 2.8 KB

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