projectPluginDetails.spec.tsx 3.1 KB

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