new-editor-utils.test.tsx 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import { expect } from 'chai'
  2. import { mockScope } from './scope'
  3. import { EditorProviders } from '../../helpers/editor-providers'
  4. import { renderHook } from '@testing-library/react'
  5. import { useNewEditorVariant } from '@/features/ide-redesign/utils/new-editor-utils'
  6. describe('new-editor-utils', function () {
  7. describe('useNewEditorVariant', function () {
  8. const newEditorVariants = [
  9. { splitTestVariant: 'default', uiVariant: 'default' },
  10. {
  11. splitTestVariant: 'new-editor',
  12. uiVariant: 'new-editor-new-logs-old-position',
  13. },
  14. {
  15. splitTestVariant: 'new-editor-old-logs',
  16. uiVariant: 'new-editor-new-logs-old-position',
  17. },
  18. {
  19. splitTestVariant: 'new-editor-new-logs-old-position',
  20. uiVariant: 'new-editor-new-logs-old-position',
  21. },
  22. ]
  23. for (const variant of newEditorVariants) {
  24. it(`forwards ?editor-redesign-new-users=${variant}`, function () {
  25. window.metaAttributesCache.set('ol-splitTestVariants', {
  26. 'editor-redesign-new-users': variant.splitTestVariant,
  27. })
  28. const scope = mockScope()
  29. const { result } = renderHook(() => useNewEditorVariant(), {
  30. wrapper: ({ children }) => (
  31. <EditorProviders
  32. scope={scope}
  33. userSettings={{ enableNewEditor: true }}
  34. >
  35. {children}
  36. </EditorProviders>
  37. ),
  38. })
  39. expect(result.current).to.equal(variant.uiVariant)
  40. })
  41. }
  42. for (const variant of newEditorVariants) {
  43. it(`ignores ?editor-redesign-new-users=${variant} when disabled by user`, function () {
  44. window.metaAttributesCache.set('ol-splitTestVariants', {
  45. 'editor-redesign-new-users': variant.splitTestVariant,
  46. })
  47. const scope = mockScope()
  48. const { result } = renderHook(() => useNewEditorVariant(), {
  49. wrapper: ({ children }) => (
  50. <EditorProviders
  51. scope={scope}
  52. userSettings={{ enableNewEditor: false }}
  53. >
  54. {children}
  55. </EditorProviders>
  56. ),
  57. })
  58. expect(result.current).to.equal('default')
  59. })
  60. }
  61. it(`handles ?editor-redesign=enabled`, function () {
  62. window.metaAttributesCache.set('ol-splitTestVariants', {
  63. 'editor-redesign': 'enabled',
  64. })
  65. const scope = mockScope()
  66. const { result } = renderHook(() => useNewEditorVariant(), {
  67. wrapper: ({ children }) => (
  68. <EditorProviders
  69. scope={scope}
  70. userSettings={{ enableNewEditor: true }}
  71. >
  72. {children}
  73. </EditorProviders>
  74. ),
  75. })
  76. expect(result.current).to.equal('new-editor-new-logs-old-position')
  77. })
  78. })
  79. })