UserSettingsHelper.test.mjs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import { expect } from 'vitest'
  2. const modulePath = '../../../../app/src/Features/Project/UserSettingsHelper.mjs'
  3. describe('UserSettingsHelper', function () {
  4. beforeEach(async function (ctx) {
  5. ctx.req = { query: {} }
  6. ctx.res = {}
  7. ctx.UserSettingsHelper = (await import(modulePath)).default
  8. })
  9. describe('overall theme', function () {
  10. it('should return the overall theme if set', async function (ctx) {
  11. const user = {
  12. ace: {
  13. overallTheme: 'light',
  14. },
  15. signUpDate: new Date('2022-01-01'),
  16. }
  17. const settings = await ctx.UserSettingsHelper.buildUserSettings(
  18. ctx.req,
  19. ctx.res,
  20. user
  21. )
  22. expect(settings.overallTheme).toBe('light')
  23. })
  24. it('should return system for new users with no overall theme set', async function (ctx) {
  25. const user = {
  26. ace: {},
  27. signUpDate: new Date('2026-03-16T00:00:00Z'),
  28. }
  29. const settings = await ctx.UserSettingsHelper.buildUserSettings(
  30. ctx.req,
  31. ctx.res,
  32. user
  33. )
  34. expect(settings.overallTheme).toBe('system')
  35. })
  36. it('should return dark for old users with no overall theme set', async function (ctx) {
  37. const user = {
  38. ace: {},
  39. signUpDate: new Date('2025-02-15T00:00:00Z'),
  40. }
  41. const settings = await ctx.UserSettingsHelper.buildUserSettings(
  42. ctx.req,
  43. ctx.res,
  44. user
  45. )
  46. expect(settings.overallTheme).toBe('')
  47. })
  48. })
  49. })