123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- // 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 { waitForNextTick } from '#tests/support/utils.ts'
- import { mockTicketQuery } from '#shared/entities/ticket/graphql/queries/ticket.mocks.ts'
- import { createDummyTicket } from '#shared/entities/ticket-article/__tests__/mocks/ticket.ts'
- import { EnumLinkType } from '#shared/graphql/types.ts'
- import { convertToGraphQLId } from '#shared/graphql/utils.ts'
- import { mockTicketRelationAndRecentTicketListsQuery } from '#desktop/pages/ticket/graphql/queries/ticketRelationAndRecentTicketLists.mocks.ts'
- import {
- mockLinkAddMutation,
- waitForLinkAddMutationCalls,
- } from '../graphql/mutations/linkAdd.mocks.ts'
- import { mockLinkListQuery } from '../graphql/queries/linkList.mocks.ts'
- describe('Ticket detail view links', () => {
- it('opens the links flyout and adds a link', async () => {
- mockPermissions(['ticket.agent'])
- mockTicketRelationAndRecentTicketListsQuery({
- ticketsRecentlyViewed: [createDummyTicket()],
- ticketsRecentByCustomer: [
- createDummyTicket({
- title: 'Foo Car',
- ticketId: '1111',
- }),
- ],
- })
- const ticket = createDummyTicket()
- mockTicketQuery({
- ticket,
- })
- mockLinkListQuery({
- linkList: [],
- })
- const view = await visitView('/tickets/1')
- const ticketMetaSidebar = within(view.getByLabelText('Content sidebar'))
- expect(ticketMetaSidebar.getByText('Links')).toBeInTheDocument()
- expect(
- ticketMetaSidebar.getByText('No links added yet.'),
- ).toBeInTheDocument()
- await view.events.click(
- await view.findByRole('button', { name: 'Add link' }),
- )
- expect(
- await view.findByRole('heading', { name: 'Link Tickets', level: 2 }),
- ).toBeInTheDocument()
- expect(await view.findByText('Recent Customer Tickets')).toBeInTheDocument()
- expect(view.getByText('Recently Viewed Tickets')).toBeInTheDocument()
- expect(view.getByText('Foo Car')).toBeInTheDocument()
- const rows = view.getAllByLabelText('Select table row')
- mockLinkAddMutation({
- linkAdd: {
- __typename: 'LinkAddPayload',
- link: {
- __typename: 'Link',
- item: {
- __typename: 'Ticket',
- id: convertToGraphQLId('Ticket', '1111'),
- title: 'Foo Car',
- },
- type: EnumLinkType.Parent,
- },
- },
- })
- await view.events.click(rows[0])
- await view.events.click(view.getByRole('button', { name: 'Link' }))
- await waitForLinkAddMutationCalls()
- mockLinkListQuery({
- linkList: [
- {
- __typename: 'Link',
- item: {
- __typename: 'Ticket',
- id: convertToGraphQLId('Ticket', '1111'),
- title: 'Foo Car',
- },
- type: EnumLinkType.Parent,
- },
- ],
- })
- await waitForNextTick()
- expect(
- ticketMetaSidebar.queryByText('No links added yet.'),
- ).not.toBeInTheDocument()
- expect(view.getByText('Parent')).toBeInTheDocument()
- expect(view.getByText('Foo Car')).toBeInTheDocument()
- })
- })
|