123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185 |
- // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
- import { ApolloError } from '@apollo/client/errors'
- import { getNode } from '@formkit/core'
- import { getAllByTestId, getByLabelText, getByRole } from '@testing-library/vue'
- import { flushPromises } from '@vue/test-utils'
- import { getByIconName } from '#tests/support/components/iconQueries.ts'
- import { getTestRouter } from '#tests/support/components/renderComponent.ts'
- import { visitView } from '#tests/support/components/visitView.ts'
- import {
- mockGraphQLApi,
- mockGraphQLSubscription,
- } from '#tests/support/mock-graphql-api.ts'
- import { mockPermissions } from '#tests/support/mock-permissions.ts'
- import { mockUserCurrent } from '#tests/support/mock-userCurrent.ts'
- import { nullableMock, waitUntil } from '#tests/support/utils.ts'
- import { TicketArticlesDocument } from '#shared/entities/ticket/graphql/queries/ticket/articles.api.ts'
- import { TicketArticleUpdatesDocument } from '#shared/entities/ticket/graphql/subscriptions/ticketArticlesUpdates.api.ts'
- import { TicketUpdatesDocument } from '#shared/entities/ticket/graphql/subscriptions/ticketUpdates.api.ts'
- import { TicketState } from '#shared/entities/ticket/types.ts'
- import { TicketArticleRetrySecurityProcessDocument } from '#shared/entities/ticket-article/graphql/mutations/ticketArticleRetrySecurityProcess.api.ts'
- import {
- EnumChannelArea,
- EnumSecurityStateType,
- type TicketArticleRetrySecurityProcessMutation,
- } from '#shared/graphql/types.ts'
- import { convertToGraphQLId } from '#shared/graphql/utils.ts'
- import { TicketWithMentionLimitDocument } from '#mobile/entities/ticket/graphql/queries/ticketWithMentionLimit.api.ts'
- import { clearTicketArticlesLoadedState } from '../composable/useTicketArticlesVariables.ts'
- import { TicketLiveUserDeleteDocument } from '../graphql/mutations/live-user/delete.api.ts'
- import { TicketLiveUserUpsertDocument } from '../graphql/mutations/live-user/ticketLiveUserUpsert.api.ts'
- import { mockArticleQuery } from './mocks/articles.ts'
- import {
- defaultArticles,
- defaultTicket,
- mockTicketDetailViewGql,
- } from './mocks/detail-view.ts'
- vi.hoisted(() => {
- const now = new Date(2022, 1, 1, 0, 0, 0, 0)
- vi.setSystemTime(now)
- })
- beforeEach(() => {
- mockPermissions(['ticket.agent'])
- clearTicketArticlesLoadedState()
- })
- test('statics inside ticket zoom view', async () => {
- const { waitUntilTicketLoaded } = mockTicketDetailViewGql({
- mockFrontendObjectAttributes: true,
- })
- const view = await visitView('/tickets/1')
- expect(view.getByTestId('loader-list')).toBeInTheDocument()
- expect(view.getByTestId('loader-title')).toBeInTheDocument()
- expect(view.getByTestId('loader-header')).toBeInTheDocument()
- await waitUntilTicketLoaded()
- const form = getNode('form-ticket-edit')
- await form?.settled
- const header = view.getByTestId('header-content')
- expect(header).toHaveTextContent('#610001')
- expect(header).toHaveTextContent('created 3 days ago')
- const titleElement = view.getByTestId('title-content')
- expect(titleElement).toHaveTextContent('Test Ticket View')
- expect(titleElement).toHaveTextContent('escalation 2 days ago')
- expect(titleElement, 'has customer avatar').toHaveTextContent('JD')
- const articlesElement = view.getByRole('group', { name: 'Articles' })
- const times = getAllByTestId(articlesElement, 'date-time-absolute')
- expect(times).toHaveLength(2)
- expect(times[0]).toHaveTextContent('2022-01-29')
- expect(times[1]).toHaveTextContent('2022-01-30')
- const comments = view.getAllByRole('comment')
- // everything else for article is testes inside ArticleBubble
- expect(comments).toHaveLength(3)
- // customer article
- expect(comments[0]).toHaveClass('flex-row-reverse')
- expect(comments[0]).toHaveTextContent('John')
- expect(comments[0]).toHaveTextContent('Body of a test ticket')
- // agent public comment
- expect(comments[1]).not.toHaveClass('flex-row-reverse')
- expect(comments[1]).toHaveTextContent('Albert')
- expect(comments[1]).toHaveTextContent('energy equals power times time')
- // agent internal comment
- expect(comments[2]).not.toHaveClass('flex-row-reverse')
- expect(comments[2]).toHaveTextContent('Monkey')
- expect(comments[2]).toHaveTextContent('only agents can see this haha')
- expect(view.getByRole('button', { name: 'Add reply' })).toBeInTheDocument()
- expect(
- view.queryByText('not-visible-attachment.png'),
- 'filters original-format attachments',
- ).not.toBeInTheDocument()
- })
- describe('user avatars', () => {
- it('renders customer avatar, when user is inactive', async () => {
- const ticket = defaultTicket()
- const image = Buffer.from('max.png').toString('base64')
- const { customer } = ticket.ticket
- customer.active = false
- customer.image = image
- const { waitUntilTicketLoaded } = mockTicketDetailViewGql({
- ticket,
- })
- const view = await visitView('/tickets/1')
- await waitUntilTicketLoaded()
- const titleBlock = view.getByTestId('ticket-title')
- const avatar = getByRole(titleBlock, 'img', {
- name: `Avatar (${customer.fullname})`,
- })
- expect(avatar).toBeAvatarElement({
- active: false,
- image,
- type: 'user',
- })
- })
- it('renders organization avatar when organization is present', async () => {
- const ticket = defaultTicket()
- const { organization } = ticket.ticket
- organization!.vip = false
- const { waitUntilTicketLoaded } = mockTicketDetailViewGql({
- ticket,
- })
- const view = await visitView('/tickets/1')
- await waitUntilTicketLoaded()
- const titleBlock = view.getByTestId('ticket-title')
- const avatar = getByRole(titleBlock, 'img', {
- name: `Avatar (${organization!.name})`,
- })
- expect(avatar).toBeAvatarElement({
- active: true,
- vip: false,
- type: 'organization',
- })
- })
- it('renders organization avatar when organization is VIP', async () => {
- const ticket = defaultTicket()
- const image = Buffer.from('max.png').toString('base64')
- const { customer, organization } = ticket.ticket
- organization!.vip = true
- customer.image = image
- const { waitUntilTicketLoaded } = mockTicketDetailViewGql({
- ticket,
- })
- const view = await visitView('/tickets/1')
- await waitUntilTicketLoaded()
- const titleBlock = view.getByTestId('ticket-title')
- const orgAvatar = getByRole(titleBlock, 'img', {
- name: `Avatar (${organization!.name})`,
- })
- const userAvatar = getByRole(titleBlock, 'img', {
- name: `Avatar (${customer.fullname})`,
- })
- expect(orgAvatar).toBeAvatarElement({
- active: true,
- vip: true,
- type: 'organization',
- })
- expect(userAvatar).toBeAvatarElement({
- active: true,
- vip: false,
- image,
- type: 'user',
- })
- })
- it('renders article user image when he is inactive', async () => {
- const articles = defaultArticles()
- const { author } = articles.firstArticles!.edges[0].node
- author.active = false
- author.image = 'avatar.png'
- author.firstname = 'Max'
- author.lastname = 'Mustermann'
- author.fullname = 'Max Mustermann'
- const { waitUntilTicketLoaded } = mockTicketDetailViewGql({
- articles,
- })
- const view = await visitView('/tickets/1')
- await waitUntilTicketLoaded()
- expect(
- view.getByRole('img', { name: `Avatar (${author.fullname})` }),
- ).toBeAvatarElement({
- type: 'user',
- image: 'avatar.png',
- outOfOffice: false,
- outOfOfficeStartAt: null,
- outOfOfficeEndAt: null,
- vip: false,
- active: false,
- })
- })
- it('renders article user when he is out of office', async () => {
- const articles = defaultArticles()
- const { author } = articles.firstArticles!.edges[0].node
- author.outOfOffice = true
- author.outOfOfficeStartAt = '2021-12-01'
- author.outOfOfficeEndAt = '2022-02-01'
- author.active = true
- author.vip = true
- author.firstname = 'Max'
- author.lastname = 'Mustermann'
- author.fullname = 'Max Mustermann'
- const { waitUntilTicketLoaded } = mockTicketDetailViewGql({
- articles,
- })
- const view = await visitView('/tickets/1')
- await waitUntilTicketLoaded()
- expect(
- view.getByRole('img', { name: `Avatar (${author.fullname}) (VIP)` }),
- ).toBeAvatarElement({
- type: 'user',
- outOfOffice: true,
- outOfOfficeStartAt: '2021-12-01',
- outOfOfficeEndAt: '2022-02-01',
- vip: true,
- active: true,
- })
- })
- })
- test("redirects to error page, if can't find ticket", async () => {
- const { calls } = mockGraphQLApi(
- TicketWithMentionLimitDocument,
- ).willFailWithNotFoundError('The ticket 9866 could not be found')
- mockGraphQLApi(TicketLiveUserDeleteDocument).willFailWithNotFoundError(
- 'The ticket 9866 could not be found',
- )
- mockGraphQLApi(TicketLiveUserUpsertDocument).willFailWithNotFoundError(
- 'The ticket 9866 could not be found',
- )
- mockGraphQLApi(TicketArticlesDocument).willFailWithNotFoundError(
- 'The ticket 9866 could not be found',
- )
- mockGraphQLSubscription(TicketUpdatesDocument).error(
- new ApolloError({ errorMessage: "Couldn't find Ticket with 'id'=9866" }),
- )
- mockGraphQLSubscription(TicketArticleUpdatesDocument).error(
- new ApolloError({ errorMessage: "Couldn't find Ticket with 'id'=9866" }),
- )
- await visitView('/tickets/9866')
- await waitUntil(() => calls.error > 0)
- await flushPromises()
- const router = getTestRouter()
- expect(router.replace).toHaveBeenCalledWith({
- name: 'Error',
- query: {
- redirect: '1',
- },
- })
- })
- test('show article context on click', async () => {
- const { waitUntilTicketLoaded } = mockTicketDetailViewGql()
- const view = await visitView('/tickets/1', {
- global: {
- stubs: {
- transition: false,
- },
- },
- })
- await waitUntilTicketLoaded()
- vi.useRealTimers()
- const contextTriggers = view.getAllByRole('button', {
- name: 'Article actions',
- })
- expect(contextTriggers).toHaveLength(3)
- await view.events.click(contextTriggers[0])
- expect(view.getByText('Set to internal')).toBeInTheDocument()
- })
- test('change content on subscription', async () => {
- const { waitUntilTicketLoaded, mockTicketSubscription, ticket } =
- mockTicketDetailViewGql()
- const view = await visitView('/tickets/1')
- await waitUntilTicketLoaded()
- expect(view.getByText(ticket.title)).toBeInTheDocument()
- await mockTicketSubscription.next({
- data: {
- ticketUpdates: {
- __typename: 'TicketUpdatesPayload',
- ticket: nullableMock({ ...ticket, title: 'Some New Title' }),
- ticketArticle: null,
- },
- },
- })
- expect(view.getByText('Some New Title')).toBeInTheDocument()
- })
- describe('calling API to retry encryption', () => {
- it('updates ticket description', async () => {
- const articlesQuery = defaultArticles()
- const article = articlesQuery.firstArticles!.edges[0].node
- article.securityState = {
- __typename: 'TicketArticleSecurityState',
- encryptionMessage: '',
- encryptionSuccess: false,
- signingMessage: 'The certificate for verification could not be found.',
- signingSuccess: false,
- }
- const { waitUntilTicketLoaded } = mockTicketDetailViewGql({
- articles: articlesQuery,
- })
- const view = await visitView('/tickets/1')
- await waitUntilTicketLoaded()
- const securityError = view.getByRole('button', { name: 'Security Error' })
- await view.events.click(securityError)
- const retryResult = {
- __typename: 'TicketArticleSecurityState',
- encryptionMessage: '',
- encryptionSuccess: false,
- signingMessage:
- '/emailAddress=smime1@example.com/C=DE/ST=Berlin/L=Berlin/O=Example Security/OU=IT Department/CN=example.com',
- signingSuccess: true,
- type: EnumSecurityStateType.Smime,
- } as const
- const mutation = mockGraphQLApi(
- TicketArticleRetrySecurityProcessDocument,
- ).willResolve<TicketArticleRetrySecurityProcessMutation>({
- ticketArticleRetrySecurityProcess: {
- __typename: 'TicketArticleRetrySecurityProcessPayload',
- retryResult,
- article: {
- __typename: 'TicketArticle',
- id: article.id,
- securityState: { ...retryResult },
- },
- errors: null,
- },
- })
- await view.events.click(view.getByText('Try again'))
- expect(mutation.spies.resolve).toHaveBeenCalled()
- expect(view.queryByTestId('popupWindow')).not.toBeInTheDocument()
- const [articlesElement] = view.getAllByRole('comment')
- expect(getByLabelText(articlesElement, 'Signed')).toBeInTheDocument()
- expect(getByIconName(articlesElement, 'signed')).toBeInTheDocument()
- })
- it('updates non-description article', async () => {
- const articlesQuery = defaultArticles()
- const article = articlesQuery.articles.edges[0].node
- article.securityState = {
- __typename: 'TicketArticleSecurityState',
- encryptionMessage: '',
- encryptionSuccess: false,
- signingMessage: 'The certificate for verification could not be found.',
- signingSuccess: false,
- }
- const { waitUntilTicketLoaded } = mockTicketDetailViewGql({
- articles: articlesQuery,
- })
- const view = await visitView('/tickets/1')
- await waitUntilTicketLoaded()
- const securityError = view.getByRole('button', { name: 'Security Error' })
- await view.events.click(securityError)
- const retryResult = {
- __typename: 'TicketArticleSecurityState',
- encryptionMessage: '',
- encryptionSuccess: false,
- signingMessage:
- '/emailAddress=smime1@example.com/C=DE/ST=Berlin/L=Berlin/O=Example Security/OU=IT Department/CN=example.com',
- signingSuccess: true,
- type: EnumSecurityStateType.Smime,
- } as const
- const mutation = mockGraphQLApi(
- TicketArticleRetrySecurityProcessDocument,
- ).willResolve<TicketArticleRetrySecurityProcessMutation>({
- ticketArticleRetrySecurityProcess: {
- __typename: 'TicketArticleRetrySecurityProcessPayload',
- retryResult,
- article: {
- __typename: 'TicketArticle',
- id: article.id,
- securityState: { ...retryResult },
- },
- errors: null,
- },
- })
- await view.events.click(view.getByText('Try again'))
- expect(mutation.spies.resolve).toHaveBeenCalled()
- expect(view.queryByTestId('popupWindow')).not.toBeInTheDocument()
- const [, firstCommentArticle] = view.getAllByRole('comment')
- expect(getByLabelText(firstCommentArticle, 'Signed')).toBeInTheDocument()
- expect(getByIconName(firstCommentArticle, 'signed')).toBeInTheDocument()
- })
- })
- describe('remote content removal', () => {
- it('shows blocked content badge', async () => {
- const articlesQuery = defaultArticles()
- const article = articlesQuery.firstArticles!.edges[0].node
- article.preferences = {
- remote_content_removed: true,
- }
- article.attachmentsWithoutInline = [
- {
- id: convertToGraphQLId('Store', 1),
- internalId: 1,
- name: 'message',
- preferences: {
- 'original-format': true,
- },
- },
- ]
- const { waitUntilTicketLoaded } = mockTicketDetailViewGql({
- articles: articlesQuery,
- })
- const view = await visitView('/tickets/1')
- await waitUntilTicketLoaded()
- const blockedContent = view.getByRole('button', { name: 'Blocked Content' })
- await view.events.click(blockedContent)
- await view.events.click(view.getByText('Original Formatting'))
- expect(view.queryByTestId('popupWindow')).not.toBeInTheDocument()
- })
- })
- describe('ticket viewers inside a ticket', () => {
- it('displays information with newer last interaction (and without own entry)', async () => {
- const { waitUntilTicketLoaded, mockTicketLiveUsersSubscription } =
- mockTicketDetailViewGql()
- mockUserCurrent({
- lastname: 'Doe',
- firstname: 'John',
- fullname: 'John Doe',
- id: convertToGraphQLId('User', 4),
- })
- mockPermissions(['ticket.agent'])
- const view = await visitView('/tickets/1')
- await waitUntilTicketLoaded()
- await mockTicketLiveUsersSubscription.next({
- data: {
- ticketLiveUserUpdates: {
- liveUsers: [
- {
- user: {
- id: 'gid://zammad/User/4',
- firstname: 'Agent 1',
- lastname: 'Test',
- fullname: 'Agent 1 Test',
- __typename: 'User',
- },
- apps: [
- {
- name: 'mobile',
- editing: false,
- lastInteraction: '2022-02-01T10:55:26Z',
- __typename: 'TicketLiveUserApp',
- },
- ],
- __typename: 'TicketLiveUser',
- },
- {
- user: {
- id: 'gid://zammad/User/160',
- firstname: 'John',
- lastname: 'Doe',
- fullname: 'John Doe',
- __typename: 'User',
- },
- apps: [
- {
- name: 'desktop',
- editing: false,
- lastInteraction: '2022-01-31T10:30:24Z',
- __typename: 'TicketLiveUserApp',
- },
- {
- name: 'mobile',
- editing: false,
- lastInteraction: '2022-01-31T16:45:53Z',
- __typename: 'TicketLiveUserApp',
- },
- ],
- __typename: 'TicketLiveUser',
- },
- {
- user: {
- id: 'gid://zammad/User/165',
- firstname: 'Rose',
- lastname: 'Nylund',
- fullname: 'Rose Nylund',
- __typename: 'User',
- },
- apps: [
- {
- name: 'mobile',
- editing: false,
- lastInteraction: '2022-01-31T16:45:53Z',
- __typename: 'TicketLiveUserApp',
- },
- ],
- __typename: 'TicketLiveUser',
- },
- ],
- __typename: 'TicketLiveUserUpdatesPayload',
- },
- },
- })
- const counter = view.getByLabelText(/Ticket has 2 viewers/)
- expect(counter, 'has a counter').toBeInTheDocument()
- expect(counter).toHaveTextContent('+1')
- await view.events.click(
- view.getByRole('button', { name: 'Show ticket viewers' }),
- )
- await waitUntil(() =>
- view.queryByRole('dialog', { name: 'Ticket viewers' }),
- )
- expect(view.getByText('Opened in tabs')).toBeInTheDocument()
- expect(
- view.queryByRole('dialog', { name: 'Ticket viewers' }),
- ).toHaveTextContent('John Doe')
- expect(view.queryByIconName('desktop')).not.toBeInTheDocument()
- await mockTicketLiveUsersSubscription.next({
- data: {
- ticketLiveUserUpdates: {
- liveUsers: [
- {
- user: {
- id: 'gid://zammad/User/160',
- firstname: 'John',
- lastname: 'Doe',
- fullname: 'John Doe',
- __typename: 'User',
- },
- apps: [
- {
- name: 'desktop',
- editing: false,
- lastInteraction: '2022-01-31T18:30:24Z',
- __typename: 'TicketLiveUserApp',
- },
- {
- name: 'mobile',
- editing: false,
- lastInteraction: '2022-01-31T16:45:53Z',
- __typename: 'TicketLiveUserApp',
- },
- ],
- __typename: 'TicketLiveUser',
- },
- ],
- __typename: 'TicketLiveUserUpdatesPayload',
- },
- },
- })
- expect(view.queryByIconName('desktop')).toBeInTheDocument()
- })
- it('editing has always the highest priority', async () => {
- const { waitUntilTicketLoaded, mockTicketLiveUsersSubscription } =
- mockTicketDetailViewGql()
- mockUserCurrent({
- lastname: 'Doe',
- firstname: 'John',
- fullname: 'John Doe',
- id: convertToGraphQLId('User', 4),
- })
- mockPermissions(['ticket.agent'])
- const view = await visitView('/tickets/1')
- await waitUntilTicketLoaded()
- await mockTicketLiveUsersSubscription.next({
- data: {
- ticketLiveUserUpdates: {
- liveUsers: [
- {
- user: {
- id: 'gid://zammad/User/160',
- firstname: 'John',
- lastname: 'Doe',
- fullname: 'John Doe',
- __typename: 'User',
- },
- apps: [
- {
- name: 'desktop',
- editing: true,
- lastInteraction: '2022-01-31T10:30:24Z',
- __typename: 'TicketLiveUserApp',
- },
- {
- name: 'mobile',
- editing: false,
- lastInteraction: '2022-01-31T16:45:53Z',
- __typename: 'TicketLiveUserApp',
- },
- ],
- __typename: 'TicketLiveUser',
- },
- ],
- __typename: 'TicketLiveUserUpdatesPayload',
- },
- },
- })
- await view.events.click(
- view.getByRole('button', { name: 'Show ticket viewers' }),
- )
- await waitUntil(() =>
- view.queryByRole('dialog', { name: 'Ticket viewers' }),
- )
- expect(
- view.queryByRole('dialog', { name: 'Ticket viewers' }),
- ).toHaveTextContent('John Doe')
- expect(view.queryByIconName('desktop-edit')).toBeInTheDocument()
- })
- it('show current user avatar when editing on other device', async () => {
- const { waitUntilTicketLoaded, mockTicketLiveUsersSubscription } =
- mockTicketDetailViewGql()
- mockUserCurrent({
- lastname: 'Doe',
- firstname: 'John',
- fullname: 'John Doe',
- id: convertToGraphQLId('User', 4),
- })
- mockPermissions(['ticket.agent'])
- const view = await visitView('/tickets/1')
- await waitUntilTicketLoaded()
- await mockTicketLiveUsersSubscription.next({
- data: {
- ticketLiveUserUpdates: {
- liveUsers: [
- {
- user: {
- id: 'gid://zammad/User/4',
- firstname: 'Agent 1',
- lastname: 'Test',
- fullname: 'Agent 1 Test',
- __typename: 'User',
- },
- apps: [
- {
- name: 'mobile',
- editing: false,
- lastInteraction: '2022-02-01T10:55:26Z',
- __typename: 'TicketLiveUserApp',
- },
- {
- name: 'desktop',
- editing: true,
- lastInteraction: '2022-02-01T09:55:26Z',
- __typename: 'TicketLiveUserApp',
- },
- ],
- __typename: 'TicketLiveUser',
- },
- ],
- __typename: 'TicketLiveUserUpdatesPayload',
- },
- },
- })
- await view.events.click(
- view.getByRole('button', { name: 'Show ticket viewers' }),
- )
- await waitUntil(() =>
- view.queryByRole('dialog', { name: 'Ticket viewers' }),
- )
- expect(
- view.queryByRole('dialog', { name: 'Ticket viewers' }),
- ).toHaveTextContent('Agent 1 Test')
- expect(view.queryByIconName('desktop-edit')).toBeInTheDocument()
- })
- it('customer should only add live user entry but not subscribe', async () => {
- mockUserCurrent({
- lastname: 'Braun',
- firstname: 'Nicole',
- fullname: 'Nicole Braun',
- id: convertToGraphQLId('User', 3),
- })
- const {
- waitUntilTicketLoaded,
- mockTicketLiveUserUpsert,
- mockTicketLiveUsersSubscription,
- } = mockTicketDetailViewGql({ ticketView: 'customer' })
- const view = await visitView('/tickets/1')
- await waitUntilTicketLoaded()
- await waitUntil(() => mockTicketLiveUserUpsert.calls.resolve === 1)
- await mockTicketLiveUsersSubscription.next({
- data: {
- ticketLiveUserUpdates: {
- liveUsers: [
- {
- user: {
- id: 'gid://zammad/User/160',
- firstname: 'John',
- lastname: 'Doe',
- fullname: 'John Doe',
- __typename: 'User',
- },
- apps: [
- {
- name: 'desktop',
- editing: false,
- lastInteraction: '2022-01-31T18:30:24Z',
- __typename: 'TicketLiveUserApp',
- },
- {
- name: 'mobile',
- editing: false,
- lastInteraction: '2022-01-31T16:45:53Z',
- __typename: 'TicketLiveUserApp',
- },
- ],
- __typename: 'TicketLiveUser',
- },
- ],
- __typename: 'TicketLiveUserUpdatesPayload',
- },
- },
- })
- expect(
- view.queryByRole('button', { name: 'Show ticket viewers' }),
- ).not.toBeInTheDocument()
- })
- })
- describe('ticket add/edit reply article', () => {
- beforeEach(() => {
- vi.useRealTimers()
- })
- it('save button is not shown when select field is opened', async () => {
- const { waitUntilTicketLoaded } = mockTicketDetailViewGql({
- mockFrontendObjectAttributes: true,
- })
- const view = await visitView('/tickets/1')
- await waitUntilTicketLoaded()
- await view.events.click(view.getByRole('button', { name: 'Add reply' }))
- await waitUntil(() => view.queryByRole('dialog', { name: 'Add reply' }))
- await view.events.type(view.getByLabelText('Text'), 'Testing')
- await expect(
- view.findByRole('button', { name: 'Save' }),
- ).resolves.toBeInTheDocument()
- await view.events.click(view.getByRole('combobox', { name: 'Visibility' }))
- expect(view.queryByRole('button', { name: 'Save' })).not.toBeInTheDocument()
- await view.events.click(view.getByRole('option', { name: 'Public' }))
- await expect(
- view.findByRole('button', { name: 'Save' }),
- ).resolves.toBeInTheDocument()
- })
- it('save button is not shown when non-reply dialog field is opened', async () => {
- const { waitUntilTicketLoaded } = mockTicketDetailViewGql({
- mockFrontendObjectAttributes: true,
- })
- const view = await visitView('/tickets/1')
- await waitUntilTicketLoaded()
- await view.events.click(view.getByRole('button', { name: 'Add reply' }))
- await waitUntil(() => view.queryByRole('dialog', { name: 'Add reply' }))
- await view.events.type(view.getByLabelText('Text'), 'Testing')
- await expect(
- view.findByRole('button', { name: 'Save' }),
- ).resolves.toBeInTheDocument()
- await view.events.click(view.getByRole('button', { name: 'Done' }))
- await view.events.click(
- view.getByRole('button', { name: 'Show ticket actions' }),
- )
- await waitUntil(() =>
- view.queryByRole('dialog', { name: 'Ticket actions' }),
- )
- expect(
- view.queryByText('You have unsaved changes.'),
- ).not.toBeInTheDocument()
- await view.events.click(view.getByText('Change customer'))
- await waitUntil(() =>
- view.queryByRole('dialog', { name: 'Change customer' }),
- )
- expect(
- view.queryByText('You have unsaved changes.'),
- ).not.toBeInTheDocument()
- })
- it('add reply (first time) should hold the form state after save button with an invalid state is used', async () => {
- const { waitUntilTicketLoaded } = mockTicketDetailViewGql({
- mockFrontendObjectAttributes: true,
- })
- const view = await visitView('/tickets/1')
- await waitUntilTicketLoaded()
- const form = getNode('form-ticket-edit')
- await form?.settled
- form?.find('title', 'name')?.input('')
- await expect(
- view.findByLabelText('Validation failed'),
- ).resolves.toBeInTheDocument()
- await view.events.click(view.getByRole('button', { name: 'Add reply' }))
- await waitUntil(() => view.queryByRole('dialog', { name: 'Add reply' }))
- await getNode('form-ticket-edit')?.settled
- await view.events.type(view.getByLabelText('Text'), 'Testing')
- // Wait for form updater.
- await getNode('form-ticket-edit')?.settled
- await view.events.click(view.getByRole('button', { name: 'Save' }))
- expect(view.getByText('This field is required.')).toBeInTheDocument()
- expect(form?.find('body', 'name')?.value).toBe('Testing')
- })
- })
- it('correctly redirects from ticket hash-based routes', async () => {
- const { waitUntilTicketLoaded } = mockTicketDetailViewGql({
- ticketView: 'agent',
- })
- await visitView('/#ticket/zoom/1')
- await waitUntilTicketLoaded()
- const router = getTestRouter()
- const route = router.currentRoute.value
- expect(route.name).toBe('TicketDetailArticlesView')
- expect(route.params).toEqual({ internalId: '1' })
- })
- it('correctly redirects from ticket hash-based routes with other ids', async () => {
- const { waitUntilTicketLoaded } = mockTicketDetailViewGql({
- ticketView: 'agent',
- })
- await visitView('/#ticket/zoom/1/20')
- await waitUntilTicketLoaded()
- const router = getTestRouter()
- const route = router.currentRoute.value
- expect(route.name).toBe('TicketDetailArticlesView')
- expect(route.params).toEqual({ internalId: '1' })
- })
- it("scrolls to the bottom the first time, but doesn't trigger rescroll on subsequent updates", async () => {
- const newArticlesQuery = mockArticleQuery(
- {
- internalId: 1,
- bodyWithUrls: '<p>Existing article> all can see this haha</p>',
- },
- [
- {
- internalId: 2,
- bodyWithUrls:
- '<p>Existing article switched to internal> all can see this haha</p>',
- },
- {
- internalId: 3,
- bodyWithUrls: '<p>Existing article> all can see this haha</p>',
- },
- ],
- )
- const newArticlesQueryAfterUpdate = mockArticleQuery(
- {
- internalId: 1,
- bodyWithUrls: '<p>Existing article> all can see this haha</p>',
- },
- [
- {
- internalId: 3,
- bodyWithUrls: '<p>Existing article> all can see this haha</p>',
- },
- ],
- )
- const { waitUntilTicketLoaded, mockTicketArticleSubscription } =
- mockTicketDetailViewGql({
- ticketView: 'agent',
- articles: [newArticlesQuery, newArticlesQueryAfterUpdate],
- })
- vi.spyOn(window, 'scrollTo').mockReturnValue()
- await visitView('/tickets/1')
- await waitUntilTicketLoaded()
- const router = getTestRouter()
- router.restoreMethods()
- expect(Element.prototype.scrollIntoView).toHaveBeenCalledTimes(1)
- await mockTicketArticleSubscription.next(
- nullableMock({
- data: {
- ticketArticleUpdates: {
- addArticle: {
- __typename: 'TicketArticle',
- id: convertToGraphQLId('TicketArticle', 100),
- createdAt: new Date(2022, 0, 31, 0, 0, 0, 0).toISOString(),
- },
- },
- },
- }),
- )
- expect(Element.prototype.scrollIntoView).toHaveBeenCalledTimes(1)
- })
- describe('with ticket on a whatsapp channel', () => {
- it('shows reply link in the article context when the service window is open', async () => {
- const testDate = new Date()
- const articles = defaultArticles()
- articles.firstArticles!.edges[0].node.type!.name = 'whatsapp message'
- const ticket = defaultTicket(
- {},
- {
- whatsapp: {
- timestamp_incoming: testDate.getTime(),
- },
- },
- )
- ticket.ticket.initialChannel = EnumChannelArea.WhatsAppBusiness
- const { waitUntilTicketLoaded } = mockTicketDetailViewGql({
- ticket,
- articles,
- })
- const view = await visitView('/tickets/1', {
- global: {
- stubs: {
- transition: false,
- },
- },
- })
- await waitUntilTicketLoaded()
- vi.useRealTimers()
- const contextTriggers = view.getAllByRole('button', {
- name: 'Article actions',
- })
- expect(contextTriggers).toHaveLength(3)
- await view.events.click(contextTriggers[0])
- expect(view.getByText('Reply')).toBeInTheDocument()
- })
- it('hides reply link in the article context when the service window is closed', async () => {
- const testDate = new Date()
- const articles = defaultArticles()
- articles.firstArticles!.edges[0].node.type!.name = 'whatsapp message'
- const ticket = defaultTicket(
- {},
- {
- whatsapp: {
- timestamp_incoming:
- testDate.setHours(testDate.getHours() - 25).valueOf() / 1000,
- },
- },
- )
- ticket.ticket.initialChannel = EnumChannelArea.WhatsAppBusiness
- const { waitUntilTicketLoaded } = mockTicketDetailViewGql({
- ticket,
- articles,
- })
- const view = await visitView('/tickets/1', {
- global: {
- stubs: {
- transition: false,
- },
- },
- })
- await waitUntilTicketLoaded()
- vi.useRealTimers()
- const contextTriggers = view.getAllByRole('button', {
- name: 'Article actions',
- })
- expect(contextTriggers).toHaveLength(3)
- await view.events.click(contextTriggers[0])
- expect(view.queryByText('Reply')).not.toBeInTheDocument()
- })
- it('hides reply link in the article context when the ticket is closed', async () => {
- const testDate = new Date()
- const articles = defaultArticles()
- articles.firstArticles!.edges[0].node.type!.name = 'whatsapp message'
- const ticket = defaultTicket(
- {},
- {
- whatsapp: {
- timestamp_incoming: testDate.getTime(),
- },
- },
- {
- name: 'closed',
- stateType: {
- name: TicketState.Closed,
- },
- },
- )
- ticket.ticket.initialChannel = EnumChannelArea.WhatsAppBusiness
- const { waitUntilTicketLoaded } = mockTicketDetailViewGql({
- ticket,
- articles,
- })
- const view = await visitView('/tickets/1', {
- global: {
- stubs: {
- transition: false,
- },
- },
- })
- await waitUntilTicketLoaded()
- vi.useRealTimers()
- const contextTriggers = view.getAllByRole('button', {
- name: 'Article actions',
- })
- expect(contextTriggers).toHaveLength(3)
- await view.events.click(contextTriggers[0])
- expect(view.queryByText('Reply')).not.toBeInTheDocument()
- })
- })
|