11import { beforeEach , describe , expect , it } from "vitest" ;
22import { shallowMount } from "@vue/test-utils" ;
33import { createStore } from "vuex" ;
4- import App2 from "@/App.vue" ; // Adjust path if necessary
4+ import App from "@/App.vue" ; // Adjust path if necessary
55
66// Dummy components to act as stubs
77const HeaderComp = { template : '<div class="header-stub"></div>' } ;
88const FooterComp = { template : '<div class="footer-stub"></div>' } ;
99const Jumbotron = { template : '<div class="jumbotron-stub"></div>' } ;
10- const NavigationDrawer = { template : '<div class="nav-drawer-stub"></div>' } ;
1110const PublicMessages = { template : '<div class="messages-stub"></div>' } ;
1211
12+ const NavigationDrawer = {
13+ name : "v-navigation-drawer" ,
14+ template : '<div class="v-navigation-drawer-stub"><slot /></div>' ,
15+ props : [ "modelValue" , "location" ] ,
16+ emits : [ "update:modelValue" ] ,
17+ } ;
18+
1319describe ( "App.vue" , ( ) => {
1420 let store ;
1521 let stateUI ;
@@ -50,8 +56,8 @@ describe("App.vue", () => {
5056 } ;
5157 } ) ;
5258
53- const createWrapper = ( overrides = { } ) => {
54- return shallowMount ( App2 , {
59+ const createWrapper = ( ) => {
60+ return shallowMount ( App , {
5561 global : {
5662 plugins : [ store ] ,
5763 mocks : {
@@ -61,21 +67,18 @@ describe("App.vue", () => {
6167 HeaderComp,
6268 FooterComp,
6369 Jumbotron,
64- NavigationDrawer,
6570 PublicMessages,
6671 "router-view" : true ,
6772 "v-app" : { template : "<div><slot /></div>" } ,
68- "v-navigation-drawer" : { template : "<div><slot /></div>" } ,
73+ "v-navigation-drawer" : NavigationDrawer ,
6974 "v-alert" : { template : '<div class="v-alert"><slot /></div>' } ,
7075 } ,
71- ...overrides ,
7276 } ,
7377 } ) ;
7478 } ;
7579
7680 it ( "renders the core layout components always" , ( ) => {
7781 const wrapper = createWrapper ( ) ;
78-
7982 expect ( wrapper . findComponent ( HeaderComp ) . exists ( ) ) . toBe ( true ) ;
8083 expect ( wrapper . findComponent ( Jumbotron ) . exists ( ) ) . toBe ( true ) ;
8184 expect ( wrapper . findComponent ( PublicMessages ) . exists ( ) ) . toBe ( true ) ;
@@ -84,11 +87,8 @@ describe("App.vue", () => {
8487 } ) ;
8588
8689 it ( "shows the read-only alert when readOnlyMode is true" , ( ) => {
87- // Update state for this specific test
8890 stateIntrospection . readOnlyMode = true ;
89-
9091 const wrapper = createWrapper ( ) ;
91-
9292 const alert = wrapper . find ( ".v-alert" ) ;
9393 expect ( alert . exists ( ) ) . toBe ( true ) ;
9494 expect ( alert . text ( ) ) . toContain (
@@ -98,29 +98,37 @@ describe("App.vue", () => {
9898
9999 it ( "does NOT show the read-only alert when readOnlyMode is false" , ( ) => {
100100 stateIntrospection . readOnlyMode = false ;
101-
102101 const wrapper = createWrapper ( ) ;
103-
104102 const alert = wrapper . find ( ".v-alert" ) ;
105103 expect ( alert . exists ( ) ) . toBe ( false ) ;
106104 } ) ;
107105
108106 it ( "renders navigation drawer only when screen is mdAndDown" , ( ) => {
109- // Mock mobile view
110107 vuetifyMock . display . mdAndDown = true ;
111-
112108 const wrapper = createWrapper ( ) ;
113-
114- // Check if the drawer component is rendered
115109 expect ( wrapper . findComponent ( NavigationDrawer ) . exists ( ) ) . toBe ( true ) ;
116110 } ) ;
117111
118- it ( "does NOT render navigation drawer when screen is larger than md" , ( ) => {
119- // Mock desktop view
120- vuetifyMock . display . mdAndDown = false ;
112+ it ( "updates drawerVisibilityState when the drawer emits an update event" , async ( ) => {
113+ stateUI . UIGeneralStatus . drawerVisibilityState = true ;
114+ vuetifyMock . display . mdAndDown = true ;
121115
122116 const wrapper = createWrapper ( ) ;
117+ let drawer = wrapper . findComponent ( NavigationDrawer ) ;
118+ await drawer . vm . $emit ( "update:modelValue" , false ) ;
119+ expect ( stateUI . UIGeneralStatus . drawerVisibilityState ) . toBe ( false ) ;
120+ } ) ;
123121
122+ it ( "does NOT render navigation drawer when screen is larger than md" , ( ) => {
123+ vuetifyMock . display . mdAndDown = false ;
124+ const wrapper = createWrapper ( ) ;
124125 expect ( wrapper . findComponent ( NavigationDrawer ) . exists ( ) ) . toBe ( false ) ;
125126 } ) ;
127+
128+ it ( "executes the updated hook when reactive data changes" , async ( ) => {
129+ const wrapper = createWrapper ( ) ;
130+ await wrapper . setData ( { title : "Trigger Update" } ) ;
131+ await wrapper . vm . $nextTick ( ) ;
132+ expect ( wrapper . exists ( ) ) . toBe ( true ) ;
133+ } ) ;
126134} ) ;
0 commit comments