projectPluginDetails.spec.tsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 plugins = TestStubs.Plugins();
  10. const plugin = TestStubs.Plugin();
  11. const routerProps = TestStubs.routeComponentProps();
  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. {...routerProps}
  43. organization={organization}
  44. project={project}
  45. params={{
  46. projectId: project.slug,
  47. pluginId: 'amazon-sqs',
  48. }}
  49. />
  50. );
  51. expect(container).toSnapshot();
  52. });
  53. it('resets plugin', async function () {
  54. jest.spyOn(indicators, 'addSuccessMessage');
  55. render(
  56. <ProjectPluginDetails
  57. {...routerProps}
  58. organization={organization}
  59. project={project}
  60. plugins={{plugins}}
  61. params={{
  62. projectId: project.slug,
  63. pluginId: 'amazon-sqs',
  64. }}
  65. />
  66. );
  67. await userEvent.click(screen.getByRole('button', {name: 'Reset Configuration'}));
  68. await waitFor(() =>
  69. expect(indicators.addSuccessMessage).toHaveBeenCalledWith('Plugin was reset')
  70. );
  71. });
  72. it('enables/disables plugin', async function () {
  73. jest.spyOn(indicators, 'addSuccessMessage');
  74. render(
  75. <ProjectPluginDetailsContainer
  76. {...routerProps}
  77. organization={organization}
  78. project={project}
  79. params={{
  80. projectId: project.slug,
  81. pluginId: 'amazon-sqs',
  82. }}
  83. />
  84. );
  85. await userEvent.click(screen.getByRole('button', {name: 'Enable Plugin'}));
  86. await waitFor(() =>
  87. expect(indicators.addSuccessMessage).toHaveBeenCalledWith('Plugin was enabled')
  88. );
  89. });
  90. });