useTicketView.spec.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. import type { TicketById } from '@shared/entities/ticket/types'
  3. import { defaultTicket } from '@mobile/pages/ticket/__tests__/mocks/detail-view'
  4. import { mockPermissions } from '@tests/support/mock-permissions'
  5. import { ref } from 'vue'
  6. import { useTicketView } from '../useTicketView'
  7. const ticketDefault = defaultTicket().ticket
  8. const ticket = ref<TicketById | undefined>(ticketDefault)
  9. describe('useTicketView', () => {
  10. it('check agent permission', () => {
  11. mockPermissions([])
  12. const { isTicketAgent, isTicketCustomer } = useTicketView(ticket)
  13. expect(isTicketAgent.value).toBe(false)
  14. expect(isTicketCustomer.value).toBe(false)
  15. mockPermissions(['ticket.agent'])
  16. expect(isTicketAgent.value).toBe(true)
  17. expect(isTicketCustomer.value).toBe(false)
  18. })
  19. it('check customer permissions', () => {
  20. mockPermissions(['ticket.customer'])
  21. const { isTicketAgent, isTicketCustomer } = useTicketView(ticket)
  22. expect(isTicketAgent.value).toBe(false)
  23. expect(isTicketCustomer.value).toBe(true)
  24. })
  25. it('check ticket editable state', async () => {
  26. const { isTicketEditable } = useTicketView(ticket)
  27. expect(isTicketEditable.value).toBe(true)
  28. ticket.value = {
  29. ...ticketDefault,
  30. policy: {
  31. __typename: 'Policy',
  32. update: false,
  33. },
  34. }
  35. expect(isTicketEditable.value).toBe(false)
  36. ticket.value = undefined
  37. expect(isTicketEditable.value).toBe(false)
  38. })
  39. })