projectPluginDetails.spec.tsx 2.8 KB

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