@@ -2,44 +2,44 @@ import { mount } from "@vue/test-utils";
22import { afterEach , beforeEach , describe , expect , it } from "vitest" ;
33import { nextTick } from "vue" ;
44
5- import ConfirmDialog from "./ConfirmDialog.vue " ;
5+ import { ConfirmDialog as confirmService , setConfirmDialogComponentRef } from "@/composables/confirmDialog " ;
66
7- type ConfirmDialogVM = InstanceType < typeof ConfirmDialog > ;
7+ import ConfirmDialogComponent from "./ ConfirmDialog.vue" ;
88
99describe ( "ConfirmDialog" , ( ) => {
1010 let wrapper : ReturnType < typeof mount > ;
11- let vm : ConfirmDialogVM ;
1211
1312 beforeEach ( ( ) => {
14- wrapper = mount ( ConfirmDialog as object , { attachTo : document . body } ) ;
15- vm = wrapper . vm as unknown as ConfirmDialogVM ;
13+ wrapper = mount ( ConfirmDialogComponent as object , { attachTo : document . body } ) ;
14+ setConfirmDialogComponentRef ( wrapper . vm as unknown as InstanceType < typeof ConfirmDialogComponent > ) ;
1615 } ) ;
1716
1817 afterEach ( ( ) => {
18+ setConfirmDialogComponentRef ( null ) ;
1919 wrapper . destroy ( ) ;
2020 document . body . innerHTML = "" ;
2121 } ) ;
2222
2323 it ( "resolves true when OK is clicked" , async ( ) => {
24- const promise = vm . confirm ( "Are you sure?" ) ;
24+ const promise = confirmService . confirm ( "Are you sure?" ) ;
2525 await wrapper . find ( '[data-description="confirm dialog ok"]' ) . trigger ( "click" ) ;
2626 expect ( await promise ) . toBe ( true ) ;
2727 } ) ;
2828
2929 it ( "resolves false when Cancel is clicked" , async ( ) => {
30- const promise = vm . confirm ( "Are you sure?" ) ;
30+ const promise = confirmService . confirm ( "Are you sure?" ) ;
3131 await wrapper . find ( '[data-description="confirm dialog cancel"]' ) . trigger ( "click" ) ;
3232 expect ( await promise ) . toBe ( false ) ;
3333 } ) ;
3434
3535 it ( "resolves null when dialog is dismissed (closed without choosing)" , async ( ) => {
36- const promise = vm . confirm ( "Are you sure?" ) ;
36+ const promise = confirmService . confirm ( "Are you sure?" ) ;
3737 wrapper . find ( "dialog" ) . element . dispatchEvent ( new Event ( "close" ) ) ;
3838 expect ( await promise ) . toBe ( null ) ;
3939 } ) ;
4040
4141 it ( "renders message and respects custom options" , async ( ) => {
42- vm . confirm ( "Delete this item?" , { title : "Confirm deletion" , okText : "Delete" } ) ;
42+ confirmService . confirm ( "Delete this item?" , { title : "Confirm deletion" , okText : "Delete" } ) ;
4343 await nextTick ( ) ;
4444 const dialogText = wrapper . find ( "dialog" ) . text ( ) ;
4545 expect ( dialogText ) . toContain ( "Delete this item?" ) ;
@@ -48,8 +48,8 @@ describe("ConfirmDialog", () => {
4848 } ) ;
4949
5050 it ( "resolves first pending promise as false on concurrent call" , async ( ) => {
51- const first = vm . confirm ( "First message" ) ;
52- const second = vm . confirm ( "Second message" ) ;
51+ const first = confirmService . confirm ( "First message" ) ;
52+ const second = confirmService . confirm ( "Second message" ) ;
5353 expect ( await first ) . toBe ( false ) ;
5454 // resolve second cleanly
5555 await wrapper . find ( '[data-description="confirm dialog cancel"]' ) . trigger ( "click" ) ;
@@ -58,7 +58,7 @@ describe("ConfirmDialog", () => {
5858
5959 it ( "resolves false when abort signal fires" , async ( ) => {
6060 const controller = new AbortController ( ) ;
61- const promise = vm . confirm ( "Are you sure?" , { signal : controller . signal } ) ;
61+ const promise = confirmService . confirm ( "Are you sure?" , { signal : controller . signal } ) ;
6262 controller . abort ( ) ;
6363 expect ( await promise ) . toBe ( false ) ;
6464 } ) ;
0 commit comments