useResolveRoute.spec.tsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import {reactHooks} from 'sentry-test/reactTestingLibrary';
  2. import {OrganizationContext} from 'sentry/views/organizationContext';
  3. import useResolveRoute from './useResolveRoute';
  4. describe('useResolveRoute', () => {
  5. let devUi, host;
  6. const organization = TestStubs.Organization();
  7. const otherOrg = TestStubs.Organization({
  8. features: ['customer-domains'],
  9. slug: 'other-org',
  10. });
  11. beforeEach(() => {
  12. devUi = window.__SENTRY_DEV_UI;
  13. host = window.location.host;
  14. });
  15. afterEach(() => {
  16. window.__SENTRY_DEV_UI = devUi;
  17. window.location.host = host;
  18. });
  19. it('should use sentryUrl when no org is provided', () => {
  20. window.__SENTRY_DEV_UI = true;
  21. window.location.host = 'localhost:7999';
  22. const wrapper = ({children}) => (
  23. <OrganizationContext.Provider value={organization}>
  24. {children}
  25. </OrganizationContext.Provider>
  26. );
  27. const {result} = reactHooks.renderHook(() => useResolveRoute('/organizations/new/'), {
  28. wrapper,
  29. });
  30. expect(result.current).toBe('/organizations/new/');
  31. });
  32. it('should replace domains with dev-ui mode on localhost', () => {
  33. window.__SENTRY_DEV_UI = true;
  34. window.location.host = 'acme.localhost:7999';
  35. const wrapper = ({children}) => (
  36. <OrganizationContext.Provider value={organization}>
  37. {children}
  38. </OrganizationContext.Provider>
  39. );
  40. const {result} = reactHooks.renderHook(() => useResolveRoute('/issues/', otherOrg), {
  41. wrapper,
  42. });
  43. expect(result.current).toBe('https://other-org.localhost:7999/issues/');
  44. });
  45. it('should replace domains with dev-ui mode on dev.getsentry.net', () => {
  46. window.__SENTRY_DEV_UI = true;
  47. window.location.host = 'acme.dev.getsentry.net:7999';
  48. const wrapper = ({children}) => (
  49. <OrganizationContext.Provider value={organization}>
  50. {children}
  51. </OrganizationContext.Provider>
  52. );
  53. const {result} = reactHooks.renderHook(() => useResolveRoute('/issues/', otherOrg), {
  54. wrapper,
  55. });
  56. expect(result.current).toBe('https://other-org.dev.getsentry.net:7999/issues/');
  57. });
  58. it('should replace domains with dev-ui mode on sentry.dev', () => {
  59. window.__SENTRY_DEV_UI = true;
  60. window.location.host = 'acme.sentry-abc123.sentry.dev';
  61. const wrapper = ({children}) => (
  62. <OrganizationContext.Provider value={organization}>
  63. {children}
  64. </OrganizationContext.Provider>
  65. );
  66. const {result} = reactHooks.renderHook(() => useResolveRoute('/issues/', otherOrg), {
  67. wrapper,
  68. });
  69. expect(result.current).toBe('https://other-org.sentry-abc123.sentry.dev/issues/');
  70. });
  71. it('will not replace domains with dev-ui mode and an unsafe host', () => {
  72. window.__SENTRY_DEV_UI = true;
  73. window.location.host = 'bad-domain.com';
  74. const wrapper = ({children}) => (
  75. <OrganizationContext.Provider value={organization}>
  76. {children}
  77. </OrganizationContext.Provider>
  78. );
  79. const {result} = reactHooks.renderHook(() => useResolveRoute('/issues/', otherOrg), {
  80. wrapper,
  81. });
  82. expect(result.current).toBe('https://other-org.sentry.io/issues/');
  83. });
  84. it('should not replace domains normally', () => {
  85. const wrapper = ({children}) => (
  86. <OrganizationContext.Provider value={organization}>
  87. {children}
  88. </OrganizationContext.Provider>
  89. );
  90. const {result} = reactHooks.renderHook(() => useResolveRoute('/issues/', otherOrg), {
  91. wrapper,
  92. });
  93. expect(result.current).toBe('https://other-org.sentry.io/issues/');
  94. });
  95. });