feat: #7065 created unit tests for UserPanel #1260

Merged
provira merged 15 commits from 7065-testUserPanel into dev 2025-02-04 06:03:50 +00:00
1 changed files with 61 additions and 0 deletions

View File

@ -0,0 +1,61 @@
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';
describe('UserPanel', () => {
Review

Tengo dudas de esta linea

Tengo dudas de esta linea
let wrapper;
let vm;
let state;
beforeEach(() => {
wrapper = createWrapper(UserPanel, {});
state = useState();
state.setUser({
id: 115,
name: 'itmanagement',
provira marked this conversation as resolved
Review

Porque en WagonCreate no creas variable?
Dentro del expect usas axios.patch

Porque en WagonCreate no creas variable? Dentro del expect usas axios.patch
nickname: 'itManagementNick',
provira marked this conversation as resolved
Review

estas haciendo mock o spy? Quizas el nombre de la variable no es la mejor

estas haciendo mock o spy? Quizas el nombre de la variable no es la mejor
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(axios.patch).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 () => {
const userLanguage = 'es';
await vm.saveLanguage(userLanguage);
expect(axios.patch).toHaveBeenCalledWith('/VnUsers/115', { lang: userLanguage });
expect(vm.user.lang).toBe(userLanguage);
vm.updatePreferences();
expect(vm.locale).toBe(userLanguage);
});
it('should update user data', async () => {
provira marked this conversation as resolved
Review

revisa a ver si puedes repetir menos veces 'es'

revisa a ver si puedes repetir menos veces 'es'
const key = 'name';
const value = 'itboss';
await vm.saveUserData(key, value);
expect(axios.post).toHaveBeenCalledWith('UserConfigs/setUserConfig', { [key]: value });
});
});