ticket-detail-view-edit.spec.ts 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { getNode } from '@formkit/core'
  3. import { getByLabelText, getByRole, within } from '@testing-library/vue'
  4. import { expect } from 'vitest'
  5. import { visitView } from '#tests/support/components/visitView.ts'
  6. import { mockApplicationConfig } from '#tests/support/mock-applicationConfig.ts'
  7. import { mockPermissions } from '#tests/support/mock-permissions.ts'
  8. import { waitForNextTick } from '#tests/support/utils.ts'
  9. import {
  10. mockAutocompleteSearchRecipientQuery,
  11. waitForAutocompleteSearchRecipientQueryCalls,
  12. } from '#shared/components/Form/fields/FieldRecipient/graphql/queries/autocompleteSearch/recipient.mocks.ts'
  13. import { mockFormUpdaterQuery } from '#shared/components/Form/graphql/queries/formUpdater.mocks.ts'
  14. import { waitForTicketUpdateMutationCalls } from '#shared/entities/ticket/graphql/mutations/update.mocks.ts'
  15. import { mockTicketArticlesQuery } from '#shared/entities/ticket/graphql/queries/ticket/articles.mocks.ts'
  16. import { mockTicketQuery } from '#shared/entities/ticket/graphql/queries/ticket.mocks.ts'
  17. import { getTicketUpdatesSubscriptionHandler } from '#shared/entities/ticket/graphql/subscriptions/ticketUpdates.mocks.ts'
  18. import { createDummyArticle } from '#shared/entities/ticket-article/__tests__/mocks/ticket-articles.ts'
  19. import { createDummyTicket } from '#shared/entities/ticket-article/__tests__/mocks/ticket.ts'
  20. import { convertToGraphQLId } from '#shared/graphql/utils.ts'
  21. import { mockLinkListQuery } from '../graphql/queries/linkList.mocks.ts'
  22. describe('Ticket detail view', () => {
  23. beforeEach(() => {
  24. mockPermissions(['ticket.agent'])
  25. mockLinkListQuery({
  26. linkList: [],
  27. })
  28. })
  29. describe('Ticket attributes', () => {
  30. it('updates ticket state to closed', async () => {
  31. const ticket = createDummyTicket({
  32. state: {
  33. id: convertToGraphQLId('Ticket::State', 2),
  34. name: 'open',
  35. stateType: {
  36. id: convertToGraphQLId('TicketStateType', 2),
  37. name: 'open',
  38. },
  39. },
  40. defaultPolicy: {
  41. update: true,
  42. agentReadAccess: true,
  43. },
  44. })
  45. mockTicketQuery({
  46. ticket,
  47. })
  48. mockFormUpdaterQuery({
  49. formUpdater: {
  50. fields: {
  51. group_id: {
  52. options: [
  53. {
  54. value: 1,
  55. label: 'Users',
  56. },
  57. {
  58. value: 2,
  59. label: 'test group',
  60. },
  61. ],
  62. },
  63. owner_id: {
  64. options: [
  65. {
  66. value: 3,
  67. label: 'Test Admin Agent',
  68. },
  69. ],
  70. },
  71. state_id: {
  72. options: [
  73. {
  74. value: 4,
  75. label: 'closed',
  76. },
  77. {
  78. value: 2,
  79. label: 'open',
  80. },
  81. {
  82. value: 6,
  83. label: 'pending close',
  84. },
  85. {
  86. value: 3,
  87. label: 'pending reminder',
  88. },
  89. ],
  90. },
  91. pending_time: {
  92. show: false,
  93. },
  94. priority_id: {
  95. options: [
  96. {
  97. value: 1,
  98. label: '1 low',
  99. },
  100. {
  101. value: 2,
  102. label: '2 normal',
  103. },
  104. {
  105. value: 3,
  106. label: '3 high',
  107. },
  108. ],
  109. },
  110. },
  111. flags: {
  112. newArticlePresent: false,
  113. },
  114. },
  115. })
  116. const view = await visitView('/tickets/1')
  117. await getNode('form-ticket-edit')?.settled
  118. expect(
  119. view.findByRole('heading', {
  120. level: 2,
  121. name: 'Ticket',
  122. }),
  123. )
  124. const statusBadges = view.getAllByTestId('common-badge')
  125. const hasOpenTicketStatus = statusBadges.some((badge) =>
  126. within(badge).getByText('open'),
  127. )
  128. expect(hasOpenTicketStatus).toBe(true)
  129. const ticketMetaSidebar = within(view.getByLabelText('Content sidebar'))
  130. await view.events.click(await ticketMetaSidebar.findByLabelText('State'))
  131. expect(
  132. await view.findByRole('listbox', { name: 'Select…' }),
  133. ).toBeInTheDocument()
  134. mockFormUpdaterQuery({
  135. formUpdater: {
  136. fields: {
  137. state_id: { value: 4 },
  138. },
  139. },
  140. })
  141. await view.events.click(view.getByRole('option', { name: 'closed' }))
  142. await getNode('form-ticket-edit')?.settled
  143. await view.events.click(view.getByRole('button', { name: 'Update' }))
  144. const calls = await waitForTicketUpdateMutationCalls()
  145. expect(calls?.at(-1)?.variables).toEqual({
  146. input: {
  147. article: null,
  148. groupId: convertToGraphQLId('Group', 2),
  149. objectAttributeValues: [],
  150. ownerId: convertToGraphQLId('User', 1),
  151. priorityId: convertToGraphQLId('Ticket::Priority', 2),
  152. stateId: convertToGraphQLId('Ticket::State', 4), // Updates from open to closed 2 -> 4
  153. },
  154. meta: {
  155. skipValidators: [],
  156. macroId: undefined,
  157. },
  158. ticketId: convertToGraphQLId('Ticket', 1),
  159. })
  160. await getTicketUpdatesSubscriptionHandler().trigger({
  161. ticketUpdates: {
  162. ticket: {
  163. ...ticket,
  164. state: {
  165. ...ticket.state,
  166. id: convertToGraphQLId('Ticket::State', 4),
  167. name: 'closed',
  168. stateType: {
  169. ...ticket.state.stateType,
  170. id: convertToGraphQLId('Ticket::StateType', 5),
  171. name: 'closed',
  172. },
  173. },
  174. },
  175. },
  176. })
  177. await waitForNextTick()
  178. const hasClosedTicketStatus = statusBadges.some((badge) =>
  179. within(badge).getByText('closed'),
  180. )
  181. expect(hasClosedTicketStatus).toBe(true)
  182. })
  183. })
  184. describe('Article actions', () => {
  185. it('adds an internal note', async () => {
  186. mockApplicationConfig({
  187. ui_ticket_zoom_article_note_new_internal: true,
  188. })
  189. mockTicketQuery({
  190. ticket: createDummyTicket({
  191. articleType: 'phone',
  192. defaultPolicy: {
  193. update: true,
  194. agentReadAccess: true,
  195. },
  196. }),
  197. })
  198. mockTicketArticlesQuery({
  199. articles: {
  200. totalCount: 1,
  201. edges: [
  202. {
  203. node: createDummyArticle({
  204. articleType: 'phone',
  205. internal: false,
  206. }),
  207. },
  208. ],
  209. },
  210. })
  211. mockFormUpdaterQuery({
  212. formUpdater: {
  213. fields: {
  214. group_id: {
  215. options: [
  216. {
  217. value: 1,
  218. label: 'Users',
  219. },
  220. {
  221. value: 2,
  222. label: 'test group',
  223. },
  224. ],
  225. },
  226. owner_id: {
  227. options: [
  228. {
  229. value: 3,
  230. label: 'Test Admin Agent',
  231. },
  232. ],
  233. },
  234. state_id: {
  235. options: [
  236. {
  237. value: 4,
  238. label: 'closed',
  239. },
  240. {
  241. value: 2,
  242. label: 'open',
  243. },
  244. {
  245. value: 6,
  246. label: 'pending close',
  247. },
  248. {
  249. value: 3,
  250. label: 'pending reminder',
  251. },
  252. ],
  253. },
  254. pending_time: {
  255. show: false,
  256. },
  257. priority_id: {
  258. options: [
  259. {
  260. value: 1,
  261. label: '1 low',
  262. },
  263. {
  264. value: 2,
  265. label: '2 normal',
  266. },
  267. {
  268. value: 3,
  269. label: '3 high',
  270. },
  271. ],
  272. },
  273. },
  274. flags: {
  275. newArticlePresent: false,
  276. },
  277. },
  278. })
  279. const view = await visitView('/tickets/1')
  280. await view.events.click(
  281. await view.findByRole('button', { name: 'Add internal note' }),
  282. )
  283. const complementary = await view.findByRole('complementary', {
  284. name: 'Reply',
  285. })
  286. expect(
  287. getByRole(complementary, 'heading', { level: 2, name: 'Reply' }),
  288. ).toBeInTheDocument()
  289. await getNode('form-ticket-edit')?.settled
  290. expect(getByLabelText(complementary, 'Visibility')).toHaveTextContent(
  291. 'Internal',
  292. )
  293. expect(complementary.firstChild).toHaveClass('bg-stripes')
  294. const editor = view.getByRole('textbox', { name: 'Text' })
  295. // FIXME: This is not possible to test ATM, due to TipTap editor not being supported in JSDOM.
  296. // expect(editor).toHaveFocus()
  297. await view.events.type(editor, 'Foo note')
  298. await getNode('form-ticket-edit')?.settled
  299. await view.events.click(view.getByRole('button', { name: 'Update' }))
  300. const calls = await waitForTicketUpdateMutationCalls()
  301. expect(calls?.at(-1)?.variables).toEqual(
  302. expect.objectContaining({
  303. input: expect.objectContaining({
  304. article: expect.objectContaining({ body: 'Foo note' }),
  305. }),
  306. }),
  307. )
  308. })
  309. it('replies to an article', async () => {
  310. mockTicketQuery({
  311. ticket: createDummyTicket({
  312. group: {
  313. id: convertToGraphQLId('Group', 1),
  314. emailAddress: {
  315. name: 'Zammad Helpdesk',
  316. emailAddress: 'zammad@localhost',
  317. },
  318. },
  319. articleType: 'email',
  320. defaultPolicy: {
  321. update: true,
  322. agentReadAccess: true,
  323. },
  324. }),
  325. })
  326. mockTicketArticlesQuery({
  327. articles: {
  328. totalCount: 1,
  329. edges: [
  330. {
  331. node: createDummyArticle({
  332. articleType: 'email',
  333. internal: false,
  334. }),
  335. },
  336. ],
  337. },
  338. })
  339. mockFormUpdaterQuery({
  340. formUpdater: {
  341. fields: {
  342. group_id: {
  343. options: [
  344. {
  345. value: 1,
  346. label: 'Users',
  347. },
  348. {
  349. value: 2,
  350. label: 'test group',
  351. },
  352. ],
  353. },
  354. owner_id: {
  355. options: [
  356. {
  357. value: 3,
  358. label: 'Test Admin Agent',
  359. },
  360. ],
  361. },
  362. state_id: {
  363. options: [
  364. {
  365. value: 4,
  366. label: 'closed',
  367. },
  368. {
  369. value: 2,
  370. label: 'open',
  371. },
  372. {
  373. value: 6,
  374. label: 'pending close',
  375. },
  376. {
  377. value: 3,
  378. label: 'pending reminder',
  379. },
  380. ],
  381. },
  382. pending_time: {
  383. show: false,
  384. },
  385. priority_id: {
  386. options: [
  387. {
  388. value: 1,
  389. label: '1 low',
  390. },
  391. {
  392. value: 2,
  393. label: '2 normal',
  394. },
  395. {
  396. value: 3,
  397. label: '3 high',
  398. },
  399. ],
  400. },
  401. },
  402. flags: {
  403. newArticlePresent: false,
  404. },
  405. },
  406. })
  407. const view = await visitView('/tickets/1')
  408. const articles = await view.findAllByRole('article')
  409. await view.events.click(
  410. await within(articles[0]).findByRole('button', { name: 'Reply' }),
  411. )
  412. await view.events.type(
  413. view.getByRole('textbox', { name: 'Text' }),
  414. 'Foo email',
  415. )
  416. await getNode('form-ticket-edit')?.settled
  417. await view.events.click(view.getByRole('button', { name: 'Update' }))
  418. const calls = await waitForTicketUpdateMutationCalls()
  419. expect(calls?.at(-1)?.variables).toEqual(
  420. expect.objectContaining({
  421. input: expect.objectContaining({
  422. article: expect.objectContaining({ body: 'Foo email' }),
  423. }),
  424. }),
  425. )
  426. })
  427. it('forwards to an article', async () => {
  428. mockTicketQuery({
  429. ticket: createDummyTicket({
  430. group: {
  431. id: convertToGraphQLId('Group', 1),
  432. emailAddress: {
  433. name: 'Zammad Helpdesk',
  434. emailAddress: 'zammad@localhost',
  435. },
  436. },
  437. articleType: 'email',
  438. defaultPolicy: {
  439. update: true,
  440. agentReadAccess: true,
  441. },
  442. }),
  443. })
  444. mockTicketArticlesQuery({
  445. articles: {
  446. totalCount: 1,
  447. edges: [
  448. {
  449. node: createDummyArticle({
  450. articleType: 'email',
  451. internal: false,
  452. }),
  453. },
  454. ],
  455. },
  456. })
  457. mockFormUpdaterQuery({
  458. formUpdater: {
  459. fields: {
  460. group_id: {
  461. options: [
  462. {
  463. value: 1,
  464. label: 'Users',
  465. },
  466. {
  467. value: 2,
  468. label: 'test group',
  469. },
  470. ],
  471. },
  472. owner_id: {
  473. options: [
  474. {
  475. value: 3,
  476. label: 'Test Admin Agent',
  477. },
  478. ],
  479. },
  480. state_id: {
  481. options: [
  482. {
  483. value: 4,
  484. label: 'closed',
  485. },
  486. {
  487. value: 2,
  488. label: 'open',
  489. },
  490. {
  491. value: 6,
  492. label: 'pending close',
  493. },
  494. {
  495. value: 3,
  496. label: 'pending reminder',
  497. },
  498. ],
  499. },
  500. pending_time: {
  501. show: false,
  502. },
  503. priority_id: {
  504. options: [
  505. {
  506. value: 1,
  507. label: '1 low',
  508. },
  509. {
  510. value: 2,
  511. label: '2 normal',
  512. },
  513. {
  514. value: 3,
  515. label: '3 high',
  516. },
  517. ],
  518. },
  519. },
  520. flags: {
  521. newArticlePresent: false,
  522. },
  523. },
  524. })
  525. const view = await visitView('/tickets/1')
  526. const articles = await view.findAllByRole('article')
  527. await view.events.click(
  528. await within(articles[0]).findByRole('button', {
  529. name: 'Action menu button',
  530. }),
  531. )
  532. await view.events.click(
  533. await view.findByRole('button', {
  534. name: 'Forward',
  535. }),
  536. )
  537. const to = view.getByLabelText('To')
  538. await view.events.click(to)
  539. mockAutocompleteSearchRecipientQuery({
  540. autocompleteSearchRecipient: [],
  541. })
  542. await view.events.type(
  543. within(to).getByRole('searchbox'),
  544. 'nicole.braun@zammad.org',
  545. )
  546. await waitForAutocompleteSearchRecipientQueryCalls()
  547. await view.events.click(
  548. view.getByRole('button', { name: 'add new email address' }),
  549. )
  550. await getNode('form-ticket-edit')?.settled
  551. await view.events.click(view.getByRole('button', { name: 'Update' }))
  552. const calls = await waitForTicketUpdateMutationCalls()
  553. expect(calls?.at(-1)?.variables).toEqual(
  554. expect.objectContaining({
  555. input: expect.objectContaining({
  556. article: expect.objectContaining({
  557. body: expect.stringContaining('---Begin forwarded message:---'),
  558. }),
  559. }),
  560. }),
  561. )
  562. })
  563. it('discards unsaved changes', async () => {
  564. mockApplicationConfig({
  565. ui_ticket_zoom_article_note_new_internal: true,
  566. })
  567. mockTicketQuery({
  568. ticket: createDummyTicket({
  569. articleType: 'phone',
  570. defaultPolicy: {
  571. update: true,
  572. agentReadAccess: true,
  573. },
  574. }),
  575. })
  576. const view = await visitView('/tickets/1')
  577. await view.events.click(
  578. view.getByRole('button', { name: 'Add phone call' }),
  579. )
  580. expect(
  581. await view.findByRole('heading', { level: 2, name: 'Reply' }),
  582. ).toBeInTheDocument()
  583. await view.events.type(
  584. view.getByRole('textbox', { name: 'Text' }),
  585. 'Foo note',
  586. )
  587. await view.events.click(
  588. view.getByRole('button', { name: 'Discard your unsaved changes' }),
  589. )
  590. const confirmDialog = await view.findByRole('dialog')
  591. expect(confirmDialog).toBeInTheDocument()
  592. await view.events.click(
  593. within(confirmDialog).getByRole('button', { name: 'Discard Changes' }),
  594. )
  595. expect(
  596. view.queryByRole('textbox', { name: 'Text' }),
  597. ).not.toBeInTheDocument()
  598. })
  599. it('discards reply form and it keeps the ticket attribute fields state', async () => {
  600. mockTicketQuery({
  601. ticket: createDummyTicket({
  602. articleType: 'phone',
  603. defaultPolicy: {
  604. update: true,
  605. agentReadAccess: true,
  606. },
  607. }),
  608. })
  609. mockTicketArticlesQuery({
  610. articles: {
  611. totalCount: 1,
  612. edges: [
  613. {
  614. node: createDummyArticle({
  615. articleType: 'phone',
  616. internal: false,
  617. }),
  618. },
  619. ],
  620. },
  621. })
  622. mockFormUpdaterQuery({
  623. formUpdater: {
  624. fields: {
  625. group_id: {
  626. options: [
  627. {
  628. value: 1,
  629. label: 'Users',
  630. },
  631. {
  632. value: 2,
  633. label: 'test group',
  634. },
  635. ],
  636. },
  637. owner_id: {
  638. options: [
  639. {
  640. value: 3,
  641. label: 'Test Admin Agent',
  642. },
  643. ],
  644. },
  645. state_id: {
  646. options: [
  647. {
  648. value: 4,
  649. label: 'closed',
  650. },
  651. {
  652. value: 2,
  653. label: 'open',
  654. },
  655. {
  656. value: 6,
  657. label: 'pending close',
  658. },
  659. {
  660. value: 3,
  661. label: 'pending reminder',
  662. },
  663. ],
  664. },
  665. pending_time: {
  666. show: false,
  667. },
  668. priority_id: {
  669. options: [
  670. {
  671. value: 1,
  672. label: '1 low',
  673. },
  674. {
  675. value: 2,
  676. label: '2 normal',
  677. },
  678. {
  679. value: 3,
  680. label: '3 high',
  681. },
  682. ],
  683. },
  684. },
  685. flags: {
  686. newArticlePresent: false,
  687. },
  688. },
  689. })
  690. const view = await visitView('/tickets/1')
  691. // Discard changes inside the reply form
  692. await view.events.click(
  693. view.getByRole('button', { name: 'Add phone call' }),
  694. )
  695. expect(
  696. await view.findByRole('heading', { level: 2, name: 'Reply' }),
  697. ).toBeInTheDocument()
  698. // Sets dirty set for a ticket attribute
  699. await view.events.click(view.getByLabelText('State'))
  700. await view.events.click(
  701. await view.findByRole('option', { name: 'closed' }),
  702. )
  703. await view.events.click(
  704. view.getByRole('button', { name: 'Discard unsaved reply' }),
  705. )
  706. expect(
  707. await view.findByRole('dialog', { name: 'Unsaved Changes' }),
  708. ).toBeInTheDocument()
  709. await view.events.click(
  710. view.getByRole('button', { name: 'Discard Changes' }),
  711. )
  712. // Verify that ticket attributes state is not lost
  713. expect(view.getByLabelText('State')).toHaveTextContent('closed')
  714. })
  715. // TODO: Currently we have a problem in our resetForm-Function but also Formkit has an bug inside the own reset handling
  716. // (null / false will currently ignored when setting back the initial value).
  717. // So we will improve our own reset function and create an issue on FormKit side to fix this.
  718. it.skip('discards complete form with an reply and afterwards only the reply directly', async () => {
  719. mockTicketQuery({
  720. ticket: createDummyTicket({
  721. group: {
  722. id: convertToGraphQLId('Group', 1),
  723. emailAddress: {
  724. name: 'Zammad Helpdesk',
  725. emailAddress: 'zammad@localhost',
  726. },
  727. },
  728. defaultPolicy: {
  729. update: true,
  730. agentReadAccess: true,
  731. },
  732. }),
  733. })
  734. mockTicketArticlesQuery({
  735. articles: {
  736. totalCount: 1,
  737. edges: [
  738. {
  739. node: createDummyArticle({
  740. articleType: 'phone',
  741. internal: false,
  742. }),
  743. },
  744. ],
  745. },
  746. })
  747. mockFormUpdaterQuery({
  748. formUpdater: {
  749. fields: {
  750. group_id: {
  751. options: [
  752. {
  753. value: 1,
  754. label: 'Users',
  755. },
  756. {
  757. value: 2,
  758. label: 'test group',
  759. },
  760. ],
  761. },
  762. owner_id: {
  763. options: [
  764. {
  765. value: 3,
  766. label: 'Test Admin Agent',
  767. },
  768. ],
  769. },
  770. state_id: {
  771. options: [
  772. {
  773. value: 4,
  774. label: 'closed',
  775. },
  776. {
  777. value: 2,
  778. label: 'open',
  779. },
  780. {
  781. value: 6,
  782. label: 'pending close',
  783. },
  784. {
  785. value: 3,
  786. label: 'pending reminder',
  787. },
  788. ],
  789. },
  790. pending_time: {
  791. show: false,
  792. },
  793. priority_id: {
  794. options: [
  795. {
  796. value: 1,
  797. label: '1 low',
  798. },
  799. {
  800. value: 2,
  801. label: '2 normal',
  802. },
  803. {
  804. value: 3,
  805. label: '3 high',
  806. },
  807. ],
  808. },
  809. },
  810. flags: {
  811. newArticlePresent: false,
  812. },
  813. },
  814. })
  815. const view = await visitView('/tickets/1')
  816. // Discard changes inside the reply form
  817. await view.events.click(view.getByRole('button', { name: 'Add reply' }))
  818. await view.events.click(
  819. await view.findByRole('button', {
  820. name: 'Discard your unsaved changes',
  821. }),
  822. )
  823. expect(
  824. await view.findByRole('dialog', { name: 'Unsaved Changes' }),
  825. ).toBeInTheDocument()
  826. await view.events.click(
  827. view.getByRole('button', { name: 'Discard Changes' }),
  828. )
  829. expect(
  830. view.queryByRole('button', {
  831. name: 'Discard your unsaved changes',
  832. }),
  833. ).not.toBeInTheDocument()
  834. await view.events.click(view.getByRole('button', { name: 'Add reply' }))
  835. await view.events.click(
  836. view.getByRole('button', { name: 'Discard unsaved reply' }),
  837. )
  838. expect(
  839. await view.findByRole('dialog', { name: 'Unsaved Changes' }),
  840. ).toBeInTheDocument()
  841. await view.events.click(
  842. view.getByRole('button', { name: 'Discard Changes' }),
  843. )
  844. expect(
  845. view.queryByRole('button', {
  846. name: 'Discard your unsaved changes',
  847. }),
  848. ).not.toBeInTheDocument()
  849. })
  850. })
  851. })