diff --git a/src/components/Navbar.vue b/src/components/Navbar.vue index 778fda213..53bf6ca14 100644 --- a/src/components/Navbar.vue +++ b/src/components/Navbar.vue @@ -1,8 +1,10 @@ + + diff --git a/src/components/__tests__/UserPanel.spec.js b/src/components/__tests__/UserPanel.spec.js index 3d5182890..4283ce3ab 100644 --- a/src/components/__tests__/UserPanel.spec.js +++ b/src/components/__tests__/UserPanel.spec.js @@ -10,38 +10,47 @@ jest.mock('vue-router', () => ({ }), })); -describe('UserPanel', () => { - describe('onMounted', () => { - it.only('should define the user into state', async () => { - const userMock = { - user: { - id: 1, - name: 'myName', - nickname: 'myNickName' - }, - roles: [] - } - jest.spyOn(axios, 'get').mockResolvedValue({ data: userMock }); - const { vm } = createWrapper(UserPanel); +describe('UserPanel onMounted()', () => { + it('should define the user into state', async () => { + const userMock = { + user: { + id: 1, + name: 'myName', + nickname: 'myNickName', + lang: 'en', + userConfig: { + darkMode: 'false' + } + }, + roles: [] + } + const expectedUserData = { + id: 1, + name: 'myName', + nickname: 'myNickName', + lang: 'en', + darkMode: 'false' + } - await flushPromises() + jest.spyOn(axios, 'get').mockResolvedValue({ data: userMock }); + const { vm } = createWrapper(UserPanel); - const expectedUser = expect.objectContaining(userMock.user) - expect(vm.state.getUser().value).toEqual(expectedUser); - }); + await flushPromises() - it('should logout and notify the expected error', async () => { - jest.spyOn(axios, 'get').mockRejectedValue(new Error('error')); + expect(vm.state.getUser().value).toEqual(expectedUserData); + }); - const { vm } = createWrapper(UserPanel); + it('should logout and notify the expected error', async () => { + jest.spyOn(axios, 'get').mockRejectedValue(new Error('error')); - jest.spyOn(vm.quasar, 'notify'); + const { vm } = createWrapper(UserPanel); - await flushPromises() + jest.spyOn(vm.quasar, 'notify'); - expect(vm.quasar.notify).toHaveBeenCalledWith(expect.objectContaining( - { 'type': 'negative' } - )); - }); + await flushPromises() + + expect(vm.quasar.notify).toHaveBeenCalledWith(expect.objectContaining( + { 'type': 'negative' } + )); }); }); diff --git a/src/composables/__tests__/useRole.spec.js b/src/composables/__tests__/useRole.spec.js index bf2129107..562456669 100644 --- a/src/composables/__tests__/useRole.spec.js +++ b/src/composables/__tests__/useRole.spec.js @@ -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'] jest.spyOn(axios, 'get').mockResolvedValue({ - data: { roles: rolesData, user: expectedUser } + data: { roles: rolesData, user: fetchedUser } }); jest.spyOn(role.state, 'setUser'); diff --git a/src/composables/__tests__/useSession.spec.js b/src/composables/__tests__/useSession.spec.js index 52b31f59c..387c34fae 100644 --- a/src/composables/__tests__/useSession.spec.js +++ b/src/composables/__tests__/useSession.spec.js @@ -36,11 +36,15 @@ describe('session', () => { id: 999, name: `T'Challa`, nickname: 'Black Panther', + lang: 'en', + darkMode: false, } const expectedUser = { id: 0, name: '', nickname: '', + lang: '', + darkMode: null, } let user = state.getUser(); @@ -60,20 +64,29 @@ describe('session', () => { }); describe('login', () => { - it('should fetch the user roles and then set token in the sessionStorage', async () => { - const rolesData = [ - { - role: { - name: 'salesPerson' - } - }, - { - role: { - name: 'admin' - } + const expectedUser = { + id: 999, + name: `T'Challa`, + nickname: 'Black Panther', + lang: 'en', + userConfig: { + darkMode: false, + } + } + const rolesData = [ + { + role: { + name: 'salesPerson' } - ]; - const expectedUser = { id: 1 } + }, + { + role: { + name: 'admin' + } + } + ]; + + it('should fetch the user roles and then set token in the sessionStorage', async () => { const expectedRoles = ['salesPerson', 'admin'] jest.spyOn(axios, 'get').mockResolvedValue({ 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 () => { - - const rolesData = [ - { - role: { - name: 'salesPerson' - } - }, - { - role: { - name: 'admin' - } - } - ]; - const expectedUser = { id: 1 } const expectedRoles = ['salesPerson', 'admin'] jest.spyOn(axios, 'get').mockResolvedValue({ data: { roles: rolesData, user: expectedUser } diff --git a/src/composables/useRole.js b/src/composables/useRole.js index a34e81a81..84e46b319 100644 --- a/src/composables/useRole.js +++ b/src/composables/useRole.js @@ -8,7 +8,14 @@ export function useRole() { const { data } = await axios.get('/api/accounts/acl'); const roles = data.roles.map(userRoles => userRoles.role.name); - state.setUser(data.user); + const userData = { + id: data.user.id, + name: data.user.name, + nickname: data.user.nickname, + lang: data.user.lang || 'es', + darkMode: data.user.userConfig.darkMode, + } + state.setUser(userData); state.setRoles(roles); } diff --git a/src/composables/useSession.js b/src/composables/useSession.js index d897b0dd7..62cb8a28b 100644 --- a/src/composables/useSession.js +++ b/src/composables/useSession.js @@ -30,6 +30,8 @@ export function useSession() { id: 0, name: '', nickname: '', + lang: '', + darkMode: null, }); } diff --git a/src/composables/useState.js b/src/composables/useState.js index 78ff4257f..d4f7994bc 100644 --- a/src/composables/useState.js +++ b/src/composables/useState.js @@ -4,6 +4,8 @@ const user = ref({ id: 0, name: '', nickname: '', + lang: '', + darkMode: null, }); const roles = ref([]); @@ -17,6 +19,8 @@ export function useState() { id: user.value.id, name: user.value.name, nickname: user.value.nickname, + lang: user.value.lang, + darkMode: user.value.darkMode, }; }); } @@ -26,6 +30,8 @@ export function useState() { id: data.id, name: data.name, nickname: data.nickname, + lang: data.lang, + darkMode: data.darkMode, }; } diff --git a/src/i18n/en/index.js b/src/i18n/en/index.js index 5f2ad232d..a80db2882 100644 --- a/src/i18n/en/index.js +++ b/src/i18n/en/index.js @@ -4,6 +4,12 @@ export default { es: 'Spanish', en: 'English', }, + collapseMenu: 'Collapse left menu', + backToDashboard: 'Return to dashboard', + notifications: 'Notifications', + userPanel: 'User panel', + theme: 'Theme', + logOut: 'Log out', }, errors: { statusUnauthorized: 'Access denied', diff --git a/src/i18n/es/index.js b/src/i18n/es/index.js index 79bd9f448..14353a5a6 100644 --- a/src/i18n/es/index.js +++ b/src/i18n/es/index.js @@ -4,6 +4,12 @@ export default { es: 'Español', en: 'Inglés', }, + collapseMenu: 'Contraer menú lateral', + backToDashboard: 'Volver al tablón', + notifications: 'Notificaciones', + userPanel: 'Panel de usuario', + theme: 'Tema', + logOut: 'Cerrar sesión', }, errors: { statusUnauthorized: 'Acceso denegado', diff --git a/src/pages/Login/Login.vue b/src/pages/Login/Login.vue index a49222ab4..4166c10b0 100644 --- a/src/pages/Login/Login.vue +++ b/src/pages/Login/Login.vue @@ -1,6 +1,6 @@