projectPluginDetails.spec.tsx 2.7 KB

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