8622-testToMaster #1411

Merged
alexm merged 746 commits from 8622-testToMaster into master 2025-02-18 07:54:25 +00:00
1 changed files with 67 additions and 0 deletions
Showing only changes of commit 5f75d3a0f1 - Show all commits

View File

@ -0,0 +1,67 @@
import { vi, describe, expect, it, beforeEach, beforeAll, afterEach } from 'vitest';
import { createWrapper } from 'app/test/vitest/helper';
import UserPanel from 'src/components/UserPanel.vue';
import axios from 'axios';
import { useState } from 'src/composables/useState';
vi.mock('axios');
describe('UserPanel', () => {
let wrapper;
let vm;
let state;
let axiosPatchMock;
let axiosPostMock;
beforeAll(() => {
axiosPatchMock = vi.spyOn(axios, 'patch').mockResolvedValue({});
axiosPostMock = vi.spyOn(axios, 'post').mockResolvedValue({});
});
beforeEach(() => {
wrapper = createWrapper(UserPanel, {});
state = useState();
state.setUser({
id: 115,
name: 'itmanagement',
nickname: 'itManagementNick',
lang: 'en',
darkMode: false,
companyFk: 442,
warehouseFk: 1,
});
wrapper = wrapper.wrapper;
vm = wrapper.vm;
});
afterEach(() => {
vi.clearAllMocks();
});
it('should fetch warehouses data on mounted', async () => {
const fetchData = wrapper.findComponent({ name: 'FetchData' });
expect(fetchData.props('url')).toBe('Warehouses');
expect(fetchData.props('autoLoad')).toBe(true);
});
it('should toggle dark mode correctly and update preferences', async () => {
await vm.saveDarkMode(true);
expect(axiosPatchMock).toHaveBeenCalledWith('/UserConfigs/115', { darkMode: true });
expect(vm.user.darkMode).toBe(true);
vm.updatePreferences();
expect(vm.darkMode).toBe(true);
});
it('should change user language and update preferences', async () => {
await vm.saveLanguage('es');
expect(axiosPatchMock).toHaveBeenCalledWith('/VnUsers/115', { lang: 'es' });
expect(vm.user.lang).toBe('es');
vm.updatePreferences();
expect(vm.locale).toBe('es');
});
it('should update user data', async () => {
await vm.saveUserData('name', 'itboss');
expect(axiosPostMock).toHaveBeenCalledWith('UserConfigs/setUserConfig', { ['name']: 'itboss' });
});
});