settings-overall-theme.test.tsx 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 { renderWithEditorContext } from '../../../../helpers/render-with-context'
  7. const IEEE_BRAND_ID = 1234
  8. const OTHER_BRAND_ID = 2234
  9. describe('<SettingsOverallTheme />', function () {
  10. const overallThemes: OverallThemeMeta[] = [
  11. {
  12. name: 'Overall Theme 1',
  13. val: '',
  14. path: 'https://overleaf.com/overalltheme-1.css',
  15. },
  16. {
  17. name: 'Overall Theme 2',
  18. val: 'light-',
  19. path: 'https://overleaf.com/overalltheme-2.css',
  20. },
  21. ]
  22. beforeEach(function () {
  23. window.metaAttributesCache.set('ol-overallThemes', overallThemes)
  24. window.metaAttributesCache.set('ol-ExposedSettings', {
  25. ieeeBrandId: IEEE_BRAND_ID,
  26. })
  27. })
  28. afterEach(function () {
  29. fetchMock.reset()
  30. window.metaAttributesCache = new Map()
  31. })
  32. it('shows correct menu', async function () {
  33. renderWithEditorContext(<SettingsOverallTheme />)
  34. const select = screen.getByLabelText('Overall theme')
  35. for (const theme of overallThemes) {
  36. const option = within(select).getByText(theme.name)
  37. expect(option.getAttribute('value')).to.equal(theme.val)
  38. }
  39. })
  40. describe('Branded Project', function () {
  41. it('should hide overall theme picker for IEEE branded projects', function () {
  42. window.metaAttributesCache.set('ol-brandVariation', {
  43. brand_id: IEEE_BRAND_ID,
  44. })
  45. renderWithEditorContext(<SettingsOverallTheme />)
  46. const select = screen.queryByText('Overall theme')
  47. expect(select).to.not.exist
  48. })
  49. it('should show overall theme picker for branded projects that are not IEEE', function () {
  50. window.metaAttributesCache.set('ol-brandVariation', {
  51. brand_id: OTHER_BRAND_ID,
  52. })
  53. renderWithEditorContext(<SettingsOverallTheme />)
  54. const select = screen.getByLabelText('Overall theme')
  55. expect(select).to.exist
  56. })
  57. it('should show overall theme picker for non branded projects', function () {
  58. window.metaAttributesCache.set('ol-brandVariation', undefined)
  59. renderWithEditorContext(<SettingsOverallTheme />)
  60. const select = screen.getByLabelText('Overall theme')
  61. expect(select).to.exist
  62. })
  63. })
  64. })