Skip to content

Commit 2eeae63

Browse files
Updated test files (#477)
* Updated test files - Updated test files Signed-off-by: Vedangi Mittal <[email protected]> * Rebase fix - Rebase fix * Lint fix - Lint fix * Fixed space - Fixed space --------- Signed-off-by: Vedangi Mittal <[email protected]>
1 parent 8f7142e commit 2eeae63

File tree

7 files changed

+76
-1683
lines changed

7 files changed

+76
-1683
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.DS_Store
22
node_modules
33
/dist
4-
/docs/.vuepress/dist
4+
/docs/.vitepress/dist
55

66
# local env files
77
.env.local

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ npm install
4444
npm run serve
4545
```
4646

47-
### Run Documentation Locally (Vuepress static site generation)
47+
### Run Documentation Locally (Vitepress static site generation)
4848
```
4949
npm run docs:serve
5050
```

src/components/AppNavigation/AppNavigation.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ watch(isNavigationOpen, () => {
105105
106106
const checkForUserData = () => {
107107
if (!currentUser.value) {
108-
userManagementStore.getUsers();
108+
userManagementStore.getUsers().catch((error) => {
109+
console.log(error);
110+
});
109111
globalStore.getCurrentUser();
110112
}
111113
};

tests/unit/AppHeader.spec.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,30 @@ import stores from '@/store';
55
import AppHeader from '@/components/AppHeader/AppHeader.vue';
66
import eventBus from '@/eventBus';
77

8-
vi.mock('vue-router', () => ({
9-
useRouter: () => ({
10-
push: vi.fn(),
11-
}),
12-
}));
8+
vi.mock('vue-router', async () => {
9+
const actual = await vi.importActual('vue-router');
10+
return {
11+
...actual,
12+
useRouter: () => ({
13+
push: vi.fn(),
14+
}),
15+
};
16+
});
1317

1418
describe('AppHeader.vue', () => {
1519
let wrapper;
1620
let globalStore;
1721
let eventLogStore;
1822
let authStore;
19-
2023
beforeEach(() => {
2124
const pinia = createPinia();
2225
setActivePinia(pinia);
23-
2426
globalStore = stores.GlobalStore();
2527
eventLogStore = stores.EventLogStore();
2628
authStore = stores.AuthenticationStore();
27-
2829
globalStore.getSystemInfo = vi.fn();
2930
eventLogStore.getEventLogData = vi.fn();
3031
authStore.resetStoreState = vi.fn();
31-
3232
wrapper = mount(AppHeader, {
3333
global: {
3434
plugins: [pinia],
@@ -84,7 +84,6 @@ describe('AppHeader.vue', () => {
8484
wrapper.vm.getSystemInfo();
8585
expect(globalStore.getSystemInfo).toHaveBeenCalled();
8686
});
87-
8887
it('getEvents should dispatch eventLog/getEventLogData', () => {
8988
wrapper.vm.getEvents();
9089
expect(eventLogStore.getEventLogData).toHaveBeenCalled();

tests/unit/AppNavigation.spec.js

Lines changed: 55 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,77 @@ import { createRouter, createWebHistory } from 'vue-router';
44
import { createPinia, setActivePinia } from 'pinia';
55
import AppNavigation from '@/components/AppNavigation/AppNavigation.vue';
66
import eventBus from '@/eventBus';
7+
import stores from '@/store';
8+
9+
vi.mock('@/components/AppNavigation/AppNavigationData', () => {
10+
return () => ({
11+
navigationItems: [
12+
{
13+
id: 'dashboard',
14+
label: 'Dashboard',
15+
route: '/dashboard',
16+
icon: 'icon-dashboard',
17+
},
18+
{
19+
id: 'settings',
20+
label: 'Settings',
21+
icon: 'icon-settings',
22+
children: [
23+
{
24+
id: 'users',
25+
label: 'Users',
26+
route: '/settings/users',
27+
},
28+
{
29+
id: 'network',
30+
label: 'Network',
31+
route: '/settings/network',
32+
},
33+
],
34+
},
35+
],
36+
});
37+
});
738

839
describe('AppNavigation.vue', () => {
940
let wrapper;
10-
41+
let globalStore;
1142
const router = createRouter({
1243
history: createWebHistory(),
1344
routes: [],
1445
});
15-
1646
beforeEach(() => {
1747
const pinia = createPinia();
1848
setActivePinia(pinia);
19-
49+
globalStore = stores.GlobalStore();
50+
vi.spyOn(globalStore, 'modelTypeGetter', 'get').mockReturnValue(
51+
'TestModel',
52+
);
53+
vi.spyOn(globalStore, 'hmcManagedGetter', 'get').mockReturnValue(true);
54+
vi.spyOn(globalStore, 'currentUserGetter', 'get').mockReturnValue({
55+
username: 'testuser',
56+
});
2057
wrapper = mount(AppNavigation, {
2158
global: {
2259
plugins: [router, pinia],
60+
stubs: {
61+
'icon-dashboard': true,
62+
'icon-settings': true,
63+
'icon-chevron-up': true,
64+
},
2365
mocks: {
2466
$t: (key) => key,
2567
},
2668
},
2769
});
2870
});
2971

30-
it('should exist', async () => {
72+
it('should exist', () => {
3173
expect(wrapper.exists()).toBe(true);
3274
});
3375

3476
it('should render correctly', () => {
35-
expect(wrapper.element).toMatchSnapshot();
77+
expect(wrapper.find('.nav-container').exists()).toBe(true);
3678
});
3779

3880
it('should render with nav-container open', () => {
@@ -53,12 +95,16 @@ describe('AppNavigation.vue', () => {
5395
});
5496

5597
it('toggle-navigation event should toggle isNavigation data prop value', async () => {
56-
wrapper.vm.isNavigationOpen = false;
57-
eventBus.emit('toggle-navigation');
98+
eventBus.emit('loading-bar-status', true);
5899
await wrapper.vm.$nextTick();
59-
expect(wrapper.vm.isNavigationOpen).toBe(true);
60100
eventBus.emit('toggle-navigation');
61101
await wrapper.vm.$nextTick();
62-
expect(wrapper.vm.isNavigationOpen).toBe(false);
102+
const navOverlay = wrapper.find('#nav-overlay');
103+
expect(navOverlay.exists()).toBe(true);
104+
const spy = vi.spyOn(eventBus, 'emit');
105+
await navOverlay.trigger('click');
106+
await wrapper.vm.$nextTick();
107+
expect(spy).toHaveBeenCalledWith('change-is-navigation-open', false);
108+
spy.mockRestore();
63109
});
64110
});

0 commit comments

Comments
 (0)