This commit is contained in:
parent
fcdc69d7c8
commit
7ece059610
|
@ -1,10 +1,9 @@
|
|||
import { setActivePinia, createPinia } from 'pinia';
|
||||
import { ref } from 'vue';
|
||||
import { describe, beforeEach, afterEach, it, expect, vi } from 'vitest';
|
||||
import { describe, beforeEach, afterEach, it, expect, vi, beforeAll } from 'vitest';
|
||||
import { useNavigationStore } from '../useNavigationStore';
|
||||
import axios from 'axios';
|
||||
// import { axios } from 'app/test/vitest/helper';
|
||||
// vi.mock('axios');
|
||||
|
||||
let store;
|
||||
|
||||
vi.mock('src/router/modules', () => [
|
||||
{ name: 'Item', meta: {} },
|
||||
|
@ -15,6 +14,7 @@ vi.mock('src/router/modules', () => [
|
|||
vi.mock('src/filters', () => ({
|
||||
toLowerCamel: vi.fn((name) => name.toLowerCase()),
|
||||
}));
|
||||
|
||||
const modulesMock = [
|
||||
{
|
||||
name: 'Item',
|
||||
|
@ -41,6 +41,7 @@ const modulesMock = [
|
|||
isPinned: false,
|
||||
},
|
||||
];
|
||||
|
||||
const pinnedModulesMock = [
|
||||
{
|
||||
name: 'Item',
|
||||
|
@ -51,7 +52,7 @@ const pinnedModulesMock = [
|
|||
isPinned: true,
|
||||
},
|
||||
];
|
||||
let store;
|
||||
|
||||
describe('useNavigationStore', () => {
|
||||
beforeEach(() => {
|
||||
setActivePinia(createPinia());
|
||||
|
@ -70,8 +71,6 @@ describe('useNavigationStore', () => {
|
|||
|
||||
it('should return modules with correct structure', () => {
|
||||
const store = useNavigationStore();
|
||||
// store.pinnedModules = ref(['item']);
|
||||
|
||||
const modules = store.getModules();
|
||||
|
||||
expect(modules.value).toEqual(modulesMock);
|
||||
|
@ -79,8 +78,6 @@ describe('useNavigationStore', () => {
|
|||
|
||||
it('should return pinned modules', () => {
|
||||
const store = useNavigationStore();
|
||||
// store.pinnedModules = ref(['item']);
|
||||
|
||||
const pinnedModules = store.getPinnedModules();
|
||||
|
||||
expect(pinnedModules.value).toEqual(pinnedModulesMock);
|
||||
|
@ -88,6 +85,7 @@ describe('useNavigationStore', () => {
|
|||
|
||||
it('should toggle pinned modules', () => {
|
||||
const store = useNavigationStore();
|
||||
|
||||
store.togglePinned('item');
|
||||
store.togglePinned('shelving');
|
||||
expect(store.pinnedModules).toEqual(['item', 'shelving']);
|
||||
|
@ -97,23 +95,10 @@ describe('useNavigationStore', () => {
|
|||
});
|
||||
|
||||
it('should fetch pinned modules', async () => {
|
||||
// vi.mock('axios', () => ({
|
||||
// get: vi.fn(() =>
|
||||
// Promise.resolve({
|
||||
// data: [{ id: 1, workerFk: 9, moduleFk: 'item', position: 1 }],
|
||||
// }),
|
||||
// ),
|
||||
// }));
|
||||
vi.spyOn(axios, 'get').mockResolvedValue({
|
||||
data: [{ id: 1, workerFk: 9, moduleFk: 'order', position: 1 }],
|
||||
});
|
||||
const store = useNavigationStore();
|
||||
// vi.spyOn(axios, 'get').mockResolvedValue({
|
||||
|
||||
// });
|
||||
// store.togglePinned('shelving');
|
||||
// store.togglePinned('shelving');
|
||||
|
||||
await store.fetchPinned();
|
||||
|
||||
expect(store.pinnedModules).toEqual(['order']);
|
||||
|
@ -135,10 +120,6 @@ describe('useNavigationStore', () => {
|
|||
menuChildren: [{ name: 'customer', title: 'Customer', icon: 'customer' }],
|
||||
},
|
||||
};
|
||||
const parent = 'testParent';
|
||||
|
||||
// Mock de console.log para verificar la salida
|
||||
// const consoleLogSpy = vi.spyOn(console, 'log');
|
||||
|
||||
const result = store.addMenuItem(module, route, []);
|
||||
expect(result).toEqual({
|
||||
|
@ -154,16 +135,12 @@ describe('useNavigationStore', () => {
|
|||
name: 'customer',
|
||||
title: 'globals.pageTitles.Customer',
|
||||
});
|
||||
// expect(consoleLogSpy).toHaveBeenCalledWith(
|
||||
// 'Adding menu item: child1 to parent: testParent',
|
||||
// );
|
||||
});
|
||||
|
||||
it('should not add menu item if condition is not met', () => {
|
||||
const store = useNavigationStore();
|
||||
const module = 'testModule';
|
||||
const route = { meta: { hidden: true, menuchildren: {} } };
|
||||
const parent = 'testParent';
|
||||
|
||||
const result = store.addMenuItem(module, route, []);
|
||||
expect(result).toBeUndefined();
|
||||
|
|
Loading…
Reference in New Issue