personal-setting-appearance.spec.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { visitView } from '#tests/support/components/visitView.ts'
  3. import { mockUserCurrent } from '#tests/support/mock-userCurrent.ts'
  4. import { EnumAppearanceTheme } from '#shared/graphql/types.ts'
  5. import { waitForUserCurrentAppearanceMutationCalls } from '#desktop/pages/personal-setting/graphql/mutations/userCurrentAppearance.mocks.ts'
  6. describe('appearance page', () => {
  7. it('should have dark theme set', async () => {
  8. mockUserCurrent({
  9. preferences: {
  10. theme: EnumAppearanceTheme.Dark,
  11. },
  12. })
  13. const view = await visitView('/personal-setting/appearance')
  14. expect(view.getByRole('radio', { checked: true })).toHaveTextContent('dark')
  15. })
  16. it('should have light theme set', async () => {
  17. mockUserCurrent({
  18. preferences: {
  19. theme: EnumAppearanceTheme.Light,
  20. },
  21. })
  22. const view = await visitView('/personal-setting/appearance')
  23. expect(view.getByRole('radio', { checked: true })).toHaveTextContent(
  24. 'light',
  25. )
  26. })
  27. it('update appearance to dark', async () => {
  28. mockUserCurrent({
  29. preferences: {
  30. theme: EnumAppearanceTheme.Light,
  31. },
  32. })
  33. const view = await visitView('/personal-setting/appearance')
  34. expect(view.getByLabelText('Light')).toBeChecked()
  35. const darkMode = view.getByText('Dark')
  36. const lightMode = view.getByText('Light')
  37. const syncWithComputer = view.getByText('Sync with computer')
  38. await view.events.click(darkMode)
  39. expect(view.getByLabelText('Dark')).toBeChecked()
  40. const calls = await waitForUserCurrentAppearanceMutationCalls()
  41. expect(calls.at(-1)?.variables).toEqual({ theme: 'dark' })
  42. expect(window.matchMedia('(prefers-color-scheme: light)').matches).toBe(
  43. false,
  44. )
  45. await view.events.click(lightMode)
  46. await vi.waitUntil(() => calls.length === 2)
  47. expect(calls.at(-1)?.variables).toEqual({ theme: 'light' })
  48. expect(window.matchMedia('(prefers-color-scheme: dark)').matches).toBe(
  49. false,
  50. )
  51. await view.events.click(syncWithComputer)
  52. expect(view.getByLabelText('Sync with computer')).toBeChecked()
  53. })
  54. })