settings-overall-theme.test.tsx 3.0 KB

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