platform.spec.jsx 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import {browserHistory} from 'react-router';
  2. import {mountWithTheme} from 'sentry-test/enzyme';
  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. orgId: baseProps.organization.slug,
  17. projectId: baseProps.project.slug,
  18. platform: 'other',
  19. },
  20. };
  21. MockApiClient.addMockResponse({
  22. url: '/projects/org-slug/project-slug/docs/other/',
  23. body: {},
  24. });
  25. mountWithTheme(
  26. <ProjectInstallPlatform {...props} />,
  27. TestStubs.routerContext([{organization: {id: '1337'}}])
  28. );
  29. expect(browserHistory.push).toHaveBeenCalledTimes(1);
  30. });
  31. it('should render NotFound if no matching integration/platform', async function () {
  32. const props = {
  33. ...baseProps,
  34. params: {
  35. orgId: baseProps.organization.slug,
  36. projectId: baseProps.project.slug,
  37. platform: 'lua',
  38. },
  39. };
  40. MockApiClient.addMockResponse({
  41. url: '/projects/org-slug/project-slug/docs/lua/',
  42. statusCode: 404,
  43. });
  44. const wrapper = mountWithTheme(
  45. <ProjectInstallPlatform {...props} />,
  46. TestStubs.routerContext([{organization: {id: '1337'}}])
  47. );
  48. await tick();
  49. wrapper.update();
  50. expect(wrapper.find('NotFound')).toHaveLength(1);
  51. });
  52. it('should render documentation', async function () {
  53. const props = {
  54. ...baseProps,
  55. params: {
  56. orgId: baseProps.organization.slug,
  57. projectId: baseProps.project.slug,
  58. platform: 'node',
  59. },
  60. };
  61. MockApiClient.addMockResponse({
  62. url: '/projects/org-slug/project-slug/docs/node/',
  63. body: {html: '<h1>Documentation here</h1>'},
  64. });
  65. const wrapper = mountWithTheme(
  66. <ProjectInstallPlatform {...props} />,
  67. TestStubs.routerContext([{organization: {id: '1337'}}])
  68. );
  69. // Initially has loading indicator
  70. expect(wrapper.find('LoadingIndicator')).toHaveLength(1);
  71. await tick();
  72. wrapper.update();
  73. expect(wrapper.find('DocumentationWrapper')).toHaveLength(1);
  74. expect(wrapper.find('DocumentationWrapper').text()).toBe('Documentation here');
  75. });
  76. });
  77. });