settings-overall-theme.test.tsx 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import { screen, within, render } from '@testing-library/react'
  2. import { expect } from 'chai'
  3. import fetchMock from 'fetch-mock'
  4. import SettingsOverallTheme from '../../../../../../frontend/js/features/editor-left-menu/components/settings/settings-overall-theme'
  5. import type { OverallThemeMeta } from '../../../../../../types/project-settings'
  6. import getMeta from '@/utils/meta'
  7. import { EditorProviders } from '../../../../helpers/editor-providers'
  8. import { EditorLeftMenuProvider } from '@/features/editor-left-menu/components/editor-left-menu-context'
  9. const IEEE_BRAND_ID = 1234
  10. const OTHER_BRAND_ID = 2234
  11. describe('<SettingsOverallTheme />', function () {
  12. const overallThemes: OverallThemeMeta[] = [
  13. {
  14. name: 'Overall Theme 1',
  15. val: '',
  16. path: 'https://overleaf.com/overalltheme-1.css',
  17. },
  18. {
  19. name: 'Overall Theme 2',
  20. val: 'light-',
  21. path: 'https://overleaf.com/overalltheme-2.css',
  22. },
  23. ]
  24. beforeEach(function () {
  25. window.metaAttributesCache.set('ol-overallThemes', overallThemes)
  26. Object.assign(getMeta('ol-ExposedSettings'), {
  27. ieeeBrandId: IEEE_BRAND_ID,
  28. })
  29. })
  30. afterEach(function () {
  31. fetchMock.removeRoutes().clearHistory()
  32. })
  33. it('shows correct menu', async function () {
  34. render(
  35. <EditorProviders>
  36. <EditorLeftMenuProvider>
  37. <SettingsOverallTheme />
  38. </EditorLeftMenuProvider>
  39. </EditorProviders>
  40. )
  41. const select = screen.getByLabelText('Overall theme')
  42. for (const theme of overallThemes) {
  43. const option = within(select).getByText(theme.name)
  44. expect(option.getAttribute('value')).to.equal(theme.val)
  45. }
  46. })
  47. describe('Branded Project', function () {
  48. it('should hide overall theme picker for IEEE branded projects', function () {
  49. window.metaAttributesCache.set('ol-brandVariation', {
  50. brand_id: IEEE_BRAND_ID,
  51. })
  52. render(
  53. <EditorProviders>
  54. <EditorLeftMenuProvider>
  55. <SettingsOverallTheme />
  56. </EditorLeftMenuProvider>
  57. </EditorProviders>
  58. )
  59. const select = screen.queryByText('Overall theme')
  60. expect(select).to.not.exist
  61. })
  62. it('should show overall theme picker for branded projects that are not IEEE', function () {
  63. window.metaAttributesCache.set('ol-brandVariation', {
  64. brand_id: OTHER_BRAND_ID,
  65. })
  66. render(
  67. <EditorProviders>
  68. <EditorLeftMenuProvider>
  69. <SettingsOverallTheme />
  70. </EditorLeftMenuProvider>
  71. </EditorProviders>
  72. )
  73. const select = screen.getByLabelText('Overall theme')
  74. expect(select).to.exist
  75. })
  76. it('should show overall theme picker for non branded projects', function () {
  77. window.metaAttributesCache.set('ol-brandVariation', undefined)
  78. render(
  79. <EditorProviders>
  80. <EditorLeftMenuProvider>
  81. <SettingsOverallTheme />
  82. </EditorLeftMenuProvider>
  83. </EditorProviders>
  84. )
  85. const select = screen.getByLabelText('Overall theme')
  86. expect(select).to.exist
  87. })
  88. })
  89. })