front unit tests amends for darkMode and setUser modifications
gitea/salix-front/pipeline/head This commit looks good
Details
gitea/salix-front/pipeline/head This commit looks good
Details
This commit is contained in:
parent
345b943869
commit
913be03e94
|
@ -10,24 +10,34 @@ jest.mock('vue-router', () => ({
|
||||||
}),
|
}),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
describe('UserPanel', () => {
|
describe('UserPanel onMounted()', () => {
|
||||||
describe('onMounted', () => {
|
it('should define the user into state', async () => {
|
||||||
it.only('should define the user into state', async () => {
|
|
||||||
const userMock = {
|
const userMock = {
|
||||||
user: {
|
user: {
|
||||||
id: 1,
|
id: 1,
|
||||||
name: 'myName',
|
name: 'myName',
|
||||||
nickname: 'myNickName'
|
nickname: 'myNickName',
|
||||||
|
lang: 'en',
|
||||||
|
userConfig: {
|
||||||
|
darkMode: 'false'
|
||||||
|
}
|
||||||
},
|
},
|
||||||
roles: []
|
roles: []
|
||||||
}
|
}
|
||||||
|
const expectedUserData = {
|
||||||
|
id: 1,
|
||||||
|
name: 'myName',
|
||||||
|
nickname: 'myNickName',
|
||||||
|
lang: 'en',
|
||||||
|
darkMode: 'false'
|
||||||
|
}
|
||||||
|
|
||||||
jest.spyOn(axios, 'get').mockResolvedValue({ data: userMock });
|
jest.spyOn(axios, 'get').mockResolvedValue({ data: userMock });
|
||||||
const { vm } = createWrapper(UserPanel);
|
const { vm } = createWrapper(UserPanel);
|
||||||
|
|
||||||
await flushPromises()
|
await flushPromises()
|
||||||
|
|
||||||
const expectedUser = expect.objectContaining(userMock.user)
|
expect(vm.state.getUser().value).toEqual(expectedUserData);
|
||||||
expect(vm.state.getUser().value).toEqual(expectedUser);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should logout and notify the expected error', async () => {
|
it('should logout and notify the expected error', async () => {
|
||||||
|
@ -44,4 +54,3 @@ describe('UserPanel', () => {
|
||||||
));
|
));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
|
@ -19,10 +19,25 @@ describe('useRole', () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
const expectedUser = { id: 1 }
|
const fetchedUser = {
|
||||||
|
id: 999,
|
||||||
|
name: `T'Challa`,
|
||||||
|
nickname: 'Black Panther',
|
||||||
|
lang: 'en',
|
||||||
|
userConfig: {
|
||||||
|
darkMode: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const expectedUser = {
|
||||||
|
id: 999,
|
||||||
|
name: `T'Challa`,
|
||||||
|
nickname: 'Black Panther',
|
||||||
|
lang: 'en',
|
||||||
|
darkMode: false,
|
||||||
|
}
|
||||||
const expectedRoles = ['salesPerson', 'admin']
|
const expectedRoles = ['salesPerson', 'admin']
|
||||||
jest.spyOn(axios, 'get').mockResolvedValue({
|
jest.spyOn(axios, 'get').mockResolvedValue({
|
||||||
data: { roles: rolesData, user: expectedUser }
|
data: { roles: rolesData, user: fetchedUser }
|
||||||
});
|
});
|
||||||
|
|
||||||
jest.spyOn(role.state, 'setUser');
|
jest.spyOn(role.state, 'setUser');
|
||||||
|
|
|
@ -36,11 +36,15 @@ describe('session', () => {
|
||||||
id: 999,
|
id: 999,
|
||||||
name: `T'Challa`,
|
name: `T'Challa`,
|
||||||
nickname: 'Black Panther',
|
nickname: 'Black Panther',
|
||||||
|
lang: 'en',
|
||||||
|
darkMode: false,
|
||||||
}
|
}
|
||||||
const expectedUser = {
|
const expectedUser = {
|
||||||
id: 0,
|
id: 0,
|
||||||
name: '',
|
name: '',
|
||||||
nickname: '',
|
nickname: '',
|
||||||
|
lang: '',
|
||||||
|
darkMode: null,
|
||||||
}
|
}
|
||||||
let user = state.getUser();
|
let user = state.getUser();
|
||||||
|
|
||||||
|
@ -60,7 +64,15 @@ describe('session', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('login', () => {
|
describe('login', () => {
|
||||||
it('should fetch the user roles and then set token in the sessionStorage', async () => {
|
const expectedUser = {
|
||||||
|
id: 999,
|
||||||
|
name: `T'Challa`,
|
||||||
|
nickname: 'Black Panther',
|
||||||
|
lang: 'en',
|
||||||
|
userConfig: {
|
||||||
|
darkMode: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
const rolesData = [
|
const rolesData = [
|
||||||
{
|
{
|
||||||
role: {
|
role: {
|
||||||
|
@ -73,7 +85,8 @@ describe('session', () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
const expectedUser = { id: 1 }
|
|
||||||
|
it('should fetch the user roles and then set token in the sessionStorage', async () => {
|
||||||
const expectedRoles = ['salesPerson', 'admin']
|
const expectedRoles = ['salesPerson', 'admin']
|
||||||
jest.spyOn(axios, 'get').mockResolvedValue({
|
jest.spyOn(axios, 'get').mockResolvedValue({
|
||||||
data: { roles: rolesData, user: expectedUser }
|
data: { roles: rolesData, user: expectedUser }
|
||||||
|
@ -96,20 +109,6 @@ describe('session', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fetch the user roles and then set token in the localStorage', async () => {
|
it('should fetch the user roles and then set token in the localStorage', async () => {
|
||||||
|
|
||||||
const rolesData = [
|
|
||||||
{
|
|
||||||
role: {
|
|
||||||
name: 'salesPerson'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
role: {
|
|
||||||
name: 'admin'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
];
|
|
||||||
const expectedUser = { id: 1 }
|
|
||||||
const expectedRoles = ['salesPerson', 'admin']
|
const expectedRoles = ['salesPerson', 'admin']
|
||||||
jest.spyOn(axios, 'get').mockResolvedValue({
|
jest.spyOn(axios, 'get').mockResolvedValue({
|
||||||
data: { roles: rolesData, user: expectedUser }
|
data: { roles: rolesData, user: expectedUser }
|
||||||
|
|
|
@ -12,7 +12,7 @@ export function useRole() {
|
||||||
id: data.user.id,
|
id: data.user.id,
|
||||||
name: data.user.name,
|
name: data.user.name,
|
||||||
nickname: data.user.nickname,
|
nickname: data.user.nickname,
|
||||||
language: data.user.lang || 'es',
|
lang: data.user.lang || 'es',
|
||||||
darkMode: data.user.userConfig.darkMode,
|
darkMode: data.user.userConfig.darkMode,
|
||||||
}
|
}
|
||||||
state.setUser(userData);
|
state.setUser(userData);
|
||||||
|
|
|
@ -30,7 +30,7 @@ export function useSession() {
|
||||||
id: 0,
|
id: 0,
|
||||||
name: '',
|
name: '',
|
||||||
nickname: '',
|
nickname: '',
|
||||||
language: '',
|
lang: '',
|
||||||
darkMode: null,
|
darkMode: null,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ const user = ref({
|
||||||
id: 0,
|
id: 0,
|
||||||
name: '',
|
name: '',
|
||||||
nickname: '',
|
nickname: '',
|
||||||
language: '',
|
lang: '',
|
||||||
darkMode: null,
|
darkMode: null,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ export function useState() {
|
||||||
id: user.value.id,
|
id: user.value.id,
|
||||||
name: user.value.name,
|
name: user.value.name,
|
||||||
nickname: user.value.nickname,
|
nickname: user.value.nickname,
|
||||||
language: user.value.language,
|
lang: user.value.lang,
|
||||||
darkMode: user.value.darkMode,
|
darkMode: user.value.darkMode,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
@ -30,7 +30,7 @@ export function useState() {
|
||||||
id: data.id,
|
id: data.id,
|
||||||
name: data.name,
|
name: data.name,
|
||||||
nickname: data.nickname,
|
nickname: data.nickname,
|
||||||
language: data.lang,
|
lang: data.lang,
|
||||||
darkMode: data.darkMode,
|
darkMode: data.darkMode,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,8 +18,17 @@ describe('Login', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should successfully set the token into session', async () => {
|
it('should successfully set the token into session', async () => {
|
||||||
|
const expectedUser = {
|
||||||
|
id: 999,
|
||||||
|
name: `T'Challa`,
|
||||||
|
nickname: 'Black Panther',
|
||||||
|
lang: 'en',
|
||||||
|
userConfig: {
|
||||||
|
darkMode: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
jest.spyOn(axios, 'post').mockResolvedValue({ data: { token: 'token' } });
|
jest.spyOn(axios, 'post').mockResolvedValue({ data: { token: 'token' } });
|
||||||
jest.spyOn(axios, 'get').mockResolvedValue({ data: { roles: [], user: { id: 1 } } });
|
jest.spyOn(axios, 'get').mockResolvedValue({ data: { roles: [], user: expectedUser } });
|
||||||
jest.spyOn(vm.quasar, 'notify')
|
jest.spyOn(vm.quasar, 'notify')
|
||||||
|
|
||||||
expect(vm.session.getToken()).toEqual('');
|
expect(vm.session.getToken()).toEqual('');
|
||||||
|
|
Loading…
Reference in New Issue