11import { createPinia , setActivePinia } from "pinia" ;
22import { DOMWrapper , flushPromises , mount , VueWrapper } from "@vue/test-utils" ;
33import { createVuetify } from "vuetify" ;
4- import { expect , describe , it , beforeEach , vi , afterEach } from "vitest" ;
4+ import { expect , describe , it , vi , afterEach } from "vitest" ;
55import Welcome from "@/components/Welcome/Welcome.vue" ;
66import { SnackbarPlugin } from "@/plugins/snackbar" ;
7- import useNamespacesStore from "@/store/modules/namespaces" ;
87import useStatsStore from "@/store/modules/stats" ;
98
10- const mockNamespace = {
11- tenant_id : "test-tenant" ,
12- name : "test-namespace" ,
13- members : [ ] ,
14- max_devices : 10 ,
15- owner : "owner-id" ,
16- created_at : "" ,
17- settings : {
18- session_record : false ,
19- } ,
20- devices_accepted_count : 0 ,
21- devices_pending_count : 0 ,
22- devices_rejected_count : 0 ,
23- billing : null ,
24- type : "personal" as const ,
25- } ;
26-
279describe ( "Welcome" , ( ) => {
2810 let wrapper : VueWrapper < InstanceType < typeof Welcome > > ;
2911 const vuetify = createVuetify ( ) ;
12+ localStorage . setItem ( "tenant" , "test-tenant" ) ;
3013 setActivePinia ( createPinia ( ) ) ;
31- const namespacesStore = useNamespacesStore ( ) ;
3214 const statsStore = useStatsStore ( ) ;
15+ statsStore . fetchStats = vi . fn ( ) . mockResolvedValue ( {
16+ registered_devices : 0 ,
17+ pending_devices : 0 ,
18+ rejected_devices : 0 ,
19+ online_devices : 0 ,
20+ active_sessions : 0 ,
21+ } ) ;
3322
34- beforeEach ( ( ) => {
35- vi . spyOn ( Storage . prototype , "getItem" ) . mockReturnValue ( "{}" ) ;
36- vi . spyOn ( Storage . prototype , "setItem" ) ;
37- namespacesStore . currentNamespace = mockNamespace ;
38- namespacesStore . namespaceList = [ mockNamespace ] ;
39- statsStore . stats = {
40- registered_devices : 0 ,
41- pending_devices : 0 ,
42- rejected_devices : 0 ,
43- online_devices : 0 ,
44- active_sessions : 0 ,
45- } ;
46-
23+ const mountWrapper = ( ) => {
4724 wrapper = mount ( Welcome , { global : { plugins : [ vuetify , SnackbarPlugin ] } } ) ;
48- } ) ;
25+ } ;
4926
50- afterEach ( ( ) => { wrapper . unmount ( ) ; } ) ;
27+ afterEach ( ( ) => { wrapper ? .unmount ( ) ; } ) ;
5128
5229 it ( "Enables 'Next' (confirm) button when the user sets up a device on step 2" , async ( ) => {
30+ mountWrapper ( ) ;
5331 await flushPromises ( ) ;
5432
5533 wrapper . vm . currentStep = 2 ;
@@ -65,8 +43,8 @@ describe("Welcome", () => {
6543 } ) ;
6644
6745 it ( "Does not render when namespace has already been shown" , async ( ) => {
68- vi . spyOn ( Storage . prototype , "getItem" ) . mockReturnValue ( '{ "test-tenant":true}' ) ;
69-
46+ localStorage . setItem ( "namespacesWelcome" , "{\ "test-tenant\ ":true}" ) ;
47+ mountWrapper ( ) ;
7048 await flushPromises ( ) ;
7149
7250 const dialog = new DOMWrapper ( document . body ) ;
@@ -76,14 +54,16 @@ describe("Welcome", () => {
7654 it ( "Does not render when namespace has devices" , async ( ) => {
7755 statsStore . stats . registered_devices = 1 ;
7856
57+ mountWrapper ( ) ;
7958 await flushPromises ( ) ;
8059
8160 const dialog = new DOMWrapper ( document . body ) ;
8261 expect ( dialog . find ( '[data-test="welcome-window"]' ) . exists ( ) ) . toBe ( false ) ;
8362 } ) ;
8463
85- it ( "Does not render when hasNamespaces is false" , async ( ) => {
86- namespacesStore . namespaceList = [ ] ;
64+ it ( "Does not render when tenant ID doesn't exist" , async ( ) => {
65+ localStorage . removeItem ( "tenant" ) ;
66+ mountWrapper ( ) ;
8767 await flushPromises ( ) ;
8868 const dialog = new DOMWrapper ( document . body ) ;
8969 expect ( dialog . find ( '[data-test="welcome-window"]' ) . exists ( ) ) . toBe ( false ) ;
0 commit comments