feat: refs #7065 created unit tests for UserPanel
This commit is contained in:
parent
2f40b77f0b
commit
5f75d3a0f1
|
@ -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' });
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue