formatters.spec.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { getInitials, toClassName } from '../formatter.ts'
  3. describe('getInitials', () => {
  4. it('returns ?? initials, if no arguments are present', () => {
  5. expect(getInitials()).toBe('??')
  6. expect(getInitials('', '', '')).toBe('??')
  7. })
  8. it('returns two letters from firstname, if no other are present', () => {
  9. expect(getInitials('John')).toBe('JO')
  10. expect(getInitials('John', '', '')).toBe('JO')
  11. })
  12. it('returns two letters from lastname, if no other are present', () => {
  13. expect(getInitials(undefined, 'Doe')).toBe('DO')
  14. expect(getInitials('', 'Doe', '')).toBe('DO')
  15. })
  16. it('returns two letters from email, if no other are present', () => {
  17. expect(getInitials(undefined, undefined, 'email@mail.com')).toBe('EM')
  18. expect(getInitials('', '', 'email@mail.com')).toBe('EM')
  19. })
  20. it('returns two letters from firstname and lastname', () => {
  21. expect(getInitials('John', 'Doe')).toBe('JD')
  22. expect(getInitials('John', 'Doe', '')).toBe('JD')
  23. expect(getInitials('John', 'Doe', 'email@mail.com')).toBe('JD')
  24. })
  25. it('returns last two numbers from phone and mobile', () => {
  26. expect(getInitials('', '', '', '490123456789')).toBe('89')
  27. expect(getInitials('', '', '', '', '491234567890')).toBe('90')
  28. })
  29. })
  30. describe('toClassName', () => {
  31. it('convert relation to class name', () => {
  32. expect(toClassName('TicketState')).toBe('Ticket::State')
  33. })
  34. })