gnome-extension.service.test.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { describe, expect, it, vi } from 'vitest'
  2. vi.mock('./lwe.service', () => ({ getLweStatus: () => ({ installed: false }) }))
  3. vi.mock('../i18n', () => ({ t: (key: string) => key }))
  4. import { flatpakInstallCommands, parseExtensionState, parseStringArray } from './gnome-extension.service'
  5. describe('parseExtensionState', () => {
  6. it('reads the state line of gnome-extensions info', () => {
  7. const output = [
  8. 'linux-wallpaperengine@wallpaperenginelover.github.io',
  9. ' Name: linux-wallpaperengine',
  10. ' Path: /home/user/.local/share/gnome-shell/extensions/linux-wallpaperengine@wallpaperenginelover.github.io',
  11. ' Enabled: Yes',
  12. ' State: ACTIVE'
  13. ].join('\n')
  14. expect(parseExtensionState(output)).toBe('ACTIVE')
  15. })
  16. it('keeps states made of two words', () => {
  17. expect(parseExtensionState(' State: OUT OF DATE\n')).toBe('OUT OF DATE')
  18. })
  19. it('has nothing for an unknown extension', () => {
  20. expect(parseExtensionState('Extension “x” doesn\'t exist')).toBeUndefined()
  21. })
  22. })
  23. describe('parseStringArray', () => {
  24. it('reads gsettings string arrays', () => {
  25. expect(parseStringArray("['a@b', 'c@d']")).toEqual(['a@b', 'c@d'])
  26. expect(parseStringArray('@as []')).toEqual([])
  27. })
  28. })
  29. describe('flatpakInstallCommands', () => {
  30. it('copies the Flatpak copy from its host path and enables it', () => {
  31. const commands = flatpakInstallCommands("/var/lib/flatpak/app/x/files/bin/gnome-shell-extension/it's")
  32. expect(commands[1]).toBe("cp -r '/var/lib/flatpak/app/x/files/bin/gnome-shell-extension/it'\\''s' ~/.local/share/gnome-shell/extensions/")
  33. expect(commands[2]).toBe('gnome-extensions enable linux-wallpaperengine@wallpaperenginelover.github.io')
  34. })
  35. })