platform.spec.jsx 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import {browserHistory} from 'react-router';
  2. import {render, screen} from 'sentry-test/reactTestingLibrary';
  3. import {ProjectInstallPlatform} from 'sentry/views/projectInstall/platform';
  4. describe('ProjectInstallPlatform', function () {
  5. describe('render()', function () {
  6. const baseProps = {
  7. api: new MockApiClient(),
  8. organization: TestStubs.Organization(),
  9. project: TestStubs.Project(),
  10. location: {query: {}},
  11. };
  12. it('should redirect to if no matching platform', function () {
  13. const props = {
  14. ...baseProps,
  15. params: {
  16. projectId: baseProps.project.slug,
  17. platform: 'other',
  18. },
  19. };
  20. MockApiClient.addMockResponse({
  21. url: '/projects/org-slug/project-slug/docs/other/',
  22. body: {},
  23. });
  24. MockApiClient.addMockResponse({
  25. method: 'GET',
  26. url: '/organizations/org-slug/projects/',
  27. body: [baseProps.project],
  28. });
  29. render(<ProjectInstallPlatform {...props} />, {
  30. context: TestStubs.routerContext([{organization: {id: '1337'}}]),
  31. });
  32. expect(browserHistory.push).toHaveBeenCalledTimes(1);
  33. });
  34. it('should render NotFound if no matching integration/platform', async function () {
  35. const props = {
  36. ...baseProps,
  37. params: {
  38. projectId: baseProps.project.slug,
  39. platform: 'lua',
  40. },
  41. };
  42. MockApiClient.addMockResponse({
  43. url: '/projects/org-slug/project-slug/docs/lua/',
  44. statusCode: 404,
  45. });
  46. render(<ProjectInstallPlatform {...props} />, {
  47. context: TestStubs.routerContext([{organization: {id: '1337'}}]),
  48. });
  49. expect(await screen.findByText('Page Not Found')).toBeInTheDocument();
  50. });
  51. it('should render documentation', async function () {
  52. const props = {
  53. ...baseProps,
  54. params: {
  55. projectId: baseProps.project.slug,
  56. platform: 'node',
  57. },
  58. };
  59. MockApiClient.addMockResponse({
  60. url: '/projects/org-slug/project-slug/docs/node/',
  61. body: {html: '<h1>Documentation here</h1>'},
  62. });
  63. MockApiClient.addMockResponse({
  64. method: 'GET',
  65. url: '/organizations/org-slug/projects/',
  66. body: [baseProps.project],
  67. });
  68. render(<ProjectInstallPlatform {...props} />, {
  69. context: TestStubs.routerContext([{organization: {id: '1337'}}]),
  70. });
  71. expect(await screen.findByText('Documentation here')).toBeInTheDocument();
  72. });
  73. });
  74. });