useFingerprint.spec.ts 848 B

12345678910111213141516171819202122232425262728293031323334
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import useFingerprint from '../useFingerprint.ts'
  3. const generateFingerprintSpy = vi.fn()
  4. vi.mock('#shared/utils/browser.ts', () => {
  5. return {
  6. generateFingerprint: () => {
  7. generateFingerprintSpy()
  8. return '123456789'
  9. },
  10. }
  11. })
  12. describe('useFingerprint', () => {
  13. afterEach(() => {
  14. generateFingerprintSpy.mockRestore()
  15. })
  16. it('generate new fingerprint', () => {
  17. const { fingerprint } = useFingerprint()
  18. expect(fingerprint.value).toBe('123456789')
  19. expect(generateFingerprintSpy).toHaveBeenCalledTimes(1)
  20. })
  21. it('fingerprint is used from local storage', () => {
  22. const { fingerprint } = useFingerprint()
  23. expect(fingerprint.value).toBe('123456789')
  24. expect(generateFingerprintSpy).toHaveBeenCalledTimes(0)
  25. })
  26. })