123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265 |
- // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
- import { expect } from 'vitest'
- import {
- getByIconName,
- queryByIconName,
- } from '#tests/support/components/iconQueries.ts'
- import { visitView } from '#tests/support/components/visitView.ts'
- import { mockTicketQuery } from '#shared/entities/ticket/graphql/queries/ticket.mocks.ts'
- import { getTicketLiveUserUpdatesSubscriptionHandler } from '#shared/entities/ticket/graphql/subscriptions/ticketLiveUserUpdates.mocks.ts'
- import { createDummyTicket } from '#shared/entities/ticket-article/__tests__/mocks/ticket.ts'
- import { EnumTaskbarApp } from '#shared/graphql/types.ts'
- import { convertToGraphQLId } from '#shared/graphql/utils.ts'
- vi.hoisted(() => {
- vi.setSystemTime(new Date('2024-09-19T09:06:00Z'))
- })
- describe('Ticket detail view live users handling', () => {
- beforeEach(() => {
- mockTicketQuery({ ticket: createDummyTicket() })
- })
- it('displays idle state of the user avatar', async () => {
- const view = await visitView('/tickets/1')
- await getTicketLiveUserUpdatesSubscriptionHandler().trigger({
- ticketLiveUserUpdates: {
- liveUsers: [
- {
- user: {
- id: convertToGraphQLId('User', 3),
- firstname: 'Nicole',
- lastname: 'Braun',
- fullname: 'Nicole Braun',
- vip: true,
- active: true,
- },
- apps: [
- {
- name: EnumTaskbarApp.Desktop,
- editing: false,
- lastInteraction: '2024-09-19T09:00:00Z',
- },
- ],
- },
- ],
- },
- })
- const customerAvatar = await view.findByRole('img', {
- name: 'Avatar (Nicole Braun) (VIP)',
- })
- expect(customerAvatar).toHaveClass('opacity-60')
- expect(
- getByIconName(customerAvatar.parentElement!, 'user-idle-2'),
- ).toHaveClasses(['fill-stone-200', 'dark:fill-neutral-500'])
- await getTicketLiveUserUpdatesSubscriptionHandler().trigger({
- ticketLiveUserUpdates: {
- liveUsers: [
- {
- user: {
- id: convertToGraphQLId('User', 3),
- firstname: 'Nicole',
- lastname: 'Braun',
- fullname: 'Nicole Braun',
- vip: true,
- active: true,
- },
- apps: [
- {
- name: EnumTaskbarApp.Desktop,
- editing: false,
- lastInteraction: '2024-09-19T09:05:00Z',
- },
- ],
- },
- ],
- },
- })
- expect(customerAvatar).not.toHaveClass('opacity-60')
- expect(
- queryByIconName(customerAvatar.parentElement!, 'user-idle'),
- ).not.toBeInTheDocument()
- })
- it('displays icon on user avatar if they are editing', async () => {
- const view = await visitView('/tickets/1')
- await getTicketLiveUserUpdatesSubscriptionHandler().trigger({
- ticketLiveUserUpdates: {
- liveUsers: [
- {
- user: {
- id: convertToGraphQLId('User', 3),
- firstname: 'Nicole',
- lastname: 'Braun',
- fullname: 'Nicole Braun',
- vip: true,
- active: true,
- },
- apps: [
- {
- name: EnumTaskbarApp.Desktop,
- editing: false,
- lastInteraction: '2024-09-19T09:00:00Z',
- },
- ],
- },
- ],
- },
- })
- const customerAvatar = await view.findByRole('img', {
- name: 'Avatar (Nicole Braun) (VIP)',
- })
- expect(
- queryByIconName(customerAvatar.parentElement!, 'pencil'),
- ).not.toBeInTheDocument()
- await getTicketLiveUserUpdatesSubscriptionHandler().trigger({
- ticketLiveUserUpdates: {
- liveUsers: [
- {
- user: {
- id: convertToGraphQLId('User', 3),
- firstname: 'Nicole',
- lastname: 'Braun',
- fullname: 'Nicole Braun',
- vip: true,
- active: true,
- },
- apps: [
- {
- name: EnumTaskbarApp.Desktop,
- editing: true,
- lastInteraction: '2024-09-19T09:05:00Z',
- },
- ],
- },
- ],
- },
- })
- expect(
- getByIconName(customerAvatar.parentElement!, 'pencil'),
- ).toHaveClasses(['text-black', 'dark:text-white'])
- })
- it('displays icon on user avatar if they are on mobile', async () => {
- const view = await visitView('/tickets/1')
- await getTicketLiveUserUpdatesSubscriptionHandler().trigger({
- ticketLiveUserUpdates: {
- liveUsers: [
- {
- user: {
- id: convertToGraphQLId('User', 3),
- firstname: 'Nicole',
- lastname: 'Braun',
- fullname: 'Nicole Braun',
- vip: true,
- active: true,
- },
- apps: [
- {
- name: EnumTaskbarApp.Desktop,
- editing: false,
- lastInteraction: '2024-09-19T09:00:00Z',
- },
- ],
- },
- ],
- },
- })
- const customerAvatar = await view.findByRole('img', {
- name: 'Avatar (Nicole Braun) (VIP)',
- })
- expect(
- queryByIconName(customerAvatar.parentElement!, 'phone'),
- ).not.toBeInTheDocument()
- await getTicketLiveUserUpdatesSubscriptionHandler().trigger({
- ticketLiveUserUpdates: {
- liveUsers: [
- {
- user: {
- id: convertToGraphQLId('User', 3),
- firstname: 'Nicole',
- lastname: 'Braun',
- fullname: 'Nicole Braun',
- vip: true,
- active: true,
- },
- apps: [
- {
- name: EnumTaskbarApp.Mobile,
- editing: false,
- lastInteraction: '2024-09-19T09:05:00Z',
- },
- ],
- },
- ],
- },
- })
- expect(getByIconName(customerAvatar.parentElement!, 'phone')).toHaveClasses(
- ['text-black', 'dark:text-white'],
- )
- })
- it('hides the user avatar if they leave the ticket', async () => {
- const view = await visitView('/tickets/1')
- await getTicketLiveUserUpdatesSubscriptionHandler().trigger({
- ticketLiveUserUpdates: {
- liveUsers: [
- {
- user: {
- id: convertToGraphQLId('User', 3),
- firstname: 'Nicole',
- lastname: 'Braun',
- fullname: 'Nicole Braun',
- vip: true,
- active: true,
- },
- apps: [
- {
- name: EnumTaskbarApp.Desktop,
- editing: false,
- lastInteraction: '2024-09-19T09:00:00Z',
- },
- ],
- },
- ],
- },
- })
- expect(
- await view.findByRole('img', {
- name: 'Avatar (Nicole Braun) (VIP)',
- }),
- ).toBeInTheDocument()
- await getTicketLiveUserUpdatesSubscriptionHandler().trigger({
- ticketLiveUserUpdates: {
- liveUsers: [],
- },
- })
- expect(
- view.queryByRole('img', { name: 'Avatar (Nicole Braun) (VIP)' }),
- ).not.toBeInTheDocument()
- })
- })
|