123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229 |
- // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
- import { within } from '@testing-library/vue'
- import { visitView } from '#tests/support/components/visitView.ts'
- import { mockPermissions } from '#tests/support/mock-permissions.ts'
- import { mockUserCurrent } from '#tests/support/mock-userCurrent.ts'
- import { waitForNextTick } from '#tests/support/utils.ts'
- import { mockFormUpdaterQuery } from '#shared/components/Form/graphql/queries/formUpdater.mocks.ts'
- import { waitForMentionSubscribeMutationCalls } from '#shared/entities/ticket/graphql/mutations/subscribe.mocks.ts'
- import { mockTicketQuery } from '#shared/entities/ticket/graphql/queries/ticket.mocks.ts'
- import { getTicketUpdatesSubscriptionHandler } from '#shared/entities/ticket/graphql/subscriptions/ticketUpdates.mocks.ts'
- import { createDummyTicket } from '#shared/entities/ticket-article/__tests__/mocks/ticket.ts'
- import { convertToGraphQLId } from '#shared/graphql/utils.ts'
- import { mockLinkListQuery } from '../graphql/queries/linkList.mocks.ts'
- describe('Ticket detail view', () => {
- beforeEach(() => {
- mockUserCurrent({
- firstname: 'Adam',
- lastname: 'Doe',
- })
- mockPermissions(['ticket.agent'])
- })
- describe('Subscribers', () => {
- it('shows subscriber information', async () => {
- const ticket = createDummyTicket({
- mentions: {
- __typename: 'MentionConnection',
- totalCount: 3,
- edges: [
- {
- cursor: 'AA',
- node: {
- __typename: 'Mention',
- user: {
- __typename: 'User',
- id: convertToGraphQLId('User', 1),
- internalId: 1,
- firstname: 'John',
- lastname: 'Doe',
- fullname: 'John Doe',
- active: true,
- },
- userTicketAccess: {
- agentReadAccess: true,
- },
- },
- },
- {
- cursor: 'AB',
- node: {
- __typename: 'Mention',
- user: {
- __typename: 'User',
- id: convertToGraphQLId('User', 2),
- internalId: 2,
- firstname: 'Jane',
- lastname: 'Doe',
- fullname: 'Jane Doe',
- active: true,
- },
- userTicketAccess: {
- agentReadAccess: true,
- },
- },
- },
- {
- cursor: 'AC',
- node: {
- __typename: 'Mention',
- user: {
- __typename: 'User',
- id: convertToGraphQLId('User', 3),
- internalId: 3,
- firstname: 'Jim',
- lastname: 'Doe',
- fullname: 'Jim Doe',
- active: false,
- },
- userTicketAccess: {
- agentReadAccess: true,
- },
- },
- },
- ],
- },
- })
- mockTicketQuery({
- ticket,
- })
- mockLinkListQuery({
- linkList: [],
- })
- mockFormUpdaterQuery({
- formUpdater: {
- fields: {
- group_id: {
- options: [
- {
- value: 1,
- label: 'Users',
- },
- {
- value: 2,
- label: 'test group',
- },
- ],
- },
- owner_id: {
- options: [
- {
- value: 3,
- label: 'Test Admin Agent',
- },
- ],
- },
- state_id: {
- options: [
- {
- value: 4,
- label: 'closed',
- },
- {
- value: 2,
- label: 'open',
- },
- {
- value: 6,
- label: 'pending close',
- },
- {
- value: 3,
- label: 'pending reminder',
- },
- ],
- },
- pending_time: {
- show: false,
- },
- priority_id: {
- options: [
- {
- value: 1,
- label: '1 low',
- },
- {
- value: 2,
- label: '2 normal',
- },
- {
- value: 3,
- label: '3 high',
- },
- ],
- },
- },
- flags: {
- newArticlePresent: false,
- },
- },
- })
- const view = await visitView('/tickets/1')
- const ticketMetaSidebar = within(view.getByLabelText('Content sidebar'))
- const subscribers = ticketMetaSidebar.getByText('Subscribers')
- expect(subscribers).toBeInTheDocument()
- expect(
- ticketMetaSidebar.queryByLabelText('Avatar (Adam Doe)'),
- ).not.toBeInTheDocument()
- const toggle = view.getByLabelText('Subscribe me')
- expect(toggle).toBeInTheDocument()
- await view.events.click(toggle)
- await waitForMentionSubscribeMutationCalls()
- await getTicketUpdatesSubscriptionHandler().trigger({
- ticketUpdates: {
- ticket: {
- ...ticket,
- mentions: {
- ...ticket.mentions,
- edges: [
- ...ticket.mentions!.edges,
- {
- cursor: 'AD',
- node: {
- __typename: 'Mention',
- user: {
- __typename: 'User',
- id: convertToGraphQLId('User', 4),
- internalId: 4,
- firstname: 'Adam',
- lastname: 'Doe',
- fullname: 'Adam Doe',
- active: true,
- },
- userTicketAccess: {
- agentReadAccess: true,
- },
- },
- },
- ],
- },
- },
- },
- })
- await waitForNextTick()
- expect(
- ticketMetaSidebar.getByLabelText('Avatar (Adam Doe)'),
- ).toBeInTheDocument()
- })
- })
- })
|