11import { createPinia , setActivePinia } from "pinia" ;
2- import { DOMWrapper , flushPromises , mount } from "@vue/test-utils" ;
2+ import { DOMWrapper , flushPromises , mount , VueWrapper } from "@vue/test-utils" ;
33import { createVuetify } from "vuetify" ;
4- import { expect , describe , it , beforeEach , vi } from "vitest" ;
4+ import { expect , describe , it , beforeEach , vi , afterEach } from "vitest" ;
55import Welcome from "@/components/Welcome/Welcome.vue" ;
66import { SnackbarPlugin } from "@/plugins/snackbar" ;
77import useNamespacesStore from "@/store/modules/namespaces" ;
@@ -25,6 +25,7 @@ const mockNamespace = {
2525} ;
2626
2727describe ( "Welcome" , ( ) => {
28+ let wrapper : VueWrapper < InstanceType < typeof Welcome > > ;
2829 const vuetify = createVuetify ( ) ;
2930 setActivePinia ( createPinia ( ) ) ;
3031 const namespacesStore = useNamespacesStore ( ) ;
@@ -34,33 +35,37 @@ describe("Welcome", () => {
3435 vi . spyOn ( Storage . prototype , "getItem" ) . mockReturnValue ( "{}" ) ;
3536 vi . spyOn ( Storage . prototype , "setItem" ) ;
3637 namespacesStore . currentNamespace = mockNamespace ;
37-
38+ namespacesStore . namespaceList = [ mockNamespace ] ;
3839 statsStore . stats = {
3940 registered_devices : 0 ,
4041 pending_devices : 0 ,
4142 rejected_devices : 0 ,
4243 online_devices : 0 ,
4344 active_sessions : 0 ,
4445 } ;
46+
47+ wrapper = mount ( Welcome , { global : { plugins : [ vuetify , SnackbarPlugin ] } } ) ;
4548 } ) ;
4649
47- const mountWrapper = ( hasNamespaces : boolean ) => {
48- return mount ( Welcome , {
49- global : { plugins : [ vuetify , SnackbarPlugin ] } ,
50- props : { hasNamespaces } ,
51- } ) ;
52- } ;
50+ afterEach ( ( ) => { wrapper . unmount ( ) ; } ) ;
5351
54- it ( "Does not render when hasNamespaces is false" , async ( ) => {
55- mountWrapper ( false ) ;
52+ it ( "Enables 'Next' (confirm) button when the user sets up a device on step 2" , async ( ) => {
5653 await flushPromises ( ) ;
54+
55+ wrapper . vm . currentStep = 2 ;
56+ wrapper . vm . hasDeviceDetected = true ;
57+ wrapper . vm . showDialog = true ;
58+
59+ await flushPromises ( ) ;
60+
5761 const dialog = new DOMWrapper ( document . body ) ;
58- expect ( dialog . find ( '[data-test="welcome-window"]' ) . exists ( ) ) . toBe ( false ) ;
62+ const confirmButton = dialog . find ( '[data-test="confirm-btn"]' ) ;
63+ expect ( confirmButton . exists ( ) ) . toBe ( true ) ;
64+ expect ( ( confirmButton . element as HTMLButtonElement ) . disabled ) . toBe ( false ) ;
5965 } ) ;
6066
6167 it ( "Does not render when namespace has already been shown" , async ( ) => {
6268 vi . spyOn ( Storage . prototype , "getItem" ) . mockReturnValue ( '{"test-tenant":true}' ) ;
63- mountWrapper ( true ) ;
6469
6570 await flushPromises ( ) ;
6671
@@ -71,27 +76,16 @@ describe("Welcome", () => {
7176 it ( "Does not render when namespace has devices" , async ( ) => {
7277 statsStore . stats . registered_devices = 1 ;
7378
74- mountWrapper ( true ) ;
75-
7679 await flushPromises ( ) ;
7780
7881 const dialog = new DOMWrapper ( document . body ) ;
7982 expect ( dialog . find ( '[data-test="welcome-window"]' ) . exists ( ) ) . toBe ( false ) ;
8083 } ) ;
8184
82- it ( "Enables 'Next' (confirm) button when the user sets up a device on step 2" , async ( ) => {
83- const wrapper = mountWrapper ( true ) ;
84- await flushPromises ( ) ;
85-
86- wrapper . vm . currentStep = 2 ;
87- wrapper . vm . hasDeviceDetected = true ;
88- wrapper . vm . showDialog = true ;
89-
85+ it ( "Does not render when hasNamespaces is false" , async ( ) => {
86+ namespacesStore . namespaceList = [ ] ;
9087 await flushPromises ( ) ;
91-
9288 const dialog = new DOMWrapper ( document . body ) ;
93- const confirmButton = dialog . find ( '[data-test="confirm-btn"]' ) ;
94- expect ( confirmButton . exists ( ) ) . toBe ( true ) ;
95- expect ( ( confirmButton . element as HTMLButtonElement ) . disabled ) . toBe ( false ) ;
89+ expect ( dialog . find ( '[data-test="welcome-window"]' ) . exists ( ) ) . toBe ( false ) ;
9690 } ) ;
9791} ) ;
0 commit comments