diff --git a/.vscode/settings.json b/.vscode/settings.json
index 53e94ed898..3dcb9b1d64 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -11,5 +11,8 @@
"fileMatch": ["cypress.json"],
"url": "https://on.cypress.io/cypress.schema.json"
}
- ]
+ ],
+ "[javascript]": {
+ "editor.defaultFormatter": "vscode.typescript-language-features"
+ }
}
diff --git a/src/boot/i18n.js b/src/boot/i18n.js
index aa450c2795..e8f4203b9f 100644
--- a/src/boot/i18n.js
+++ b/src/boot/i18n.js
@@ -2,12 +2,14 @@ import { boot } from 'quasar/wrappers';
import { createI18n } from 'vue-i18n';
import messages from 'src/i18n';
-export default boot(({ app }) => {
- const i18n = createI18n({
- locale: 'en',
- messages,
- });
+const i18n = createI18n({
+ locale: 'en',
+ messages,
+});
+export default boot(({ app }) => {
// Set i18n instance on app
app.use(i18n);
});
+
+export { i18n };
\ No newline at end of file
diff --git a/src/components/UserPanel.vue b/src/components/UserPanel.vue
index 2e357698c4..6accb30ec8 100644
--- a/src/components/UserPanel.vue
+++ b/src/components/UserPanel.vue
@@ -1,3 +1,51 @@
+
+
@@ -34,7 +82,7 @@
{{ user.nickname }}
-
@{{ user.username }}
+
@{{ user.name }}
-
-
diff --git a/src/components/__tests__/UserPanel.spec.js b/src/components/__tests__/UserPanel.spec.js
index 1640a3a0e6..542921ec65 100644
--- a/src/components/__tests__/UserPanel.spec.js
+++ b/src/components/__tests__/UserPanel.spec.js
@@ -1,11 +1,17 @@
import { describe, expect, it, jest } from '@jest/globals';
import { installQuasarPlugin } from '@quasar/quasar-app-extension-testing-unit-jest';
-import { mount } from '@vue/test-utils';
+import { mount, flushPromises } from '@vue/test-utils';
+import axios from 'axios';
import { i18n } from 'src/boot/i18n';
import UserPanel from '../UserPanel.vue';
+import { Notify } from 'quasar';
// Specify here Quasar config you'll need to test your component
-installQuasarPlugin();
+installQuasarPlugin({
+ plugins: {
+ Notify
+ }
+});
const mockPush = jest.fn();
jest.mock('vue-router', () => ({
@@ -14,15 +20,48 @@ jest.mock('vue-router', () => ({
}),
}));
-describe('UserPanel', () => {
- it('should have the function logout defined', () => {
- const wrapper = mount(UserPanel, {
- global: {
- plugins: [i18n]
- }
- });
- const { vm } = wrapper;
+function createWrapper(component) {
+ const wrapper = mount(component, {
+ global: {
+ plugins: [i18n]
+ }
+ });
+ const vm = wrapper.vm;
- expect(vm.logout).toBeDefined();
+ return { vm, wrapper };
+}
+
+describe('UserPanel', () => {
+ describe('onMounted', () => {
+ it('should define the user into state', async () => {
+ const userMock = {
+ user: {
+ id: 1,
+ name: 'myName',
+ nickname: 'myNickName'
+ }
+ }
+ jest.spyOn(axios, 'get').mockResolvedValue(userMock);
+ const { vm } = createWrapper(UserPanel);
+
+ await flushPromises()
+
+ const expectedUser = expect.objectContaining(userMock.user)
+ expect(vm.state.getUser().value).toEqual(expectedUser);
+ });
+
+ it('should logout and notify the expected error', async () => {
+ jest.spyOn(axios, 'get').mockRejectedValue(new Error('error'));
+
+ const { vm } = createWrapper(UserPanel);
+
+ jest.spyOn(vm.quasar, 'notify');
+
+ await flushPromises()
+
+ expect(vm.quasar.notify).toHaveBeenCalledWith(expect.objectContaining(
+ { 'type': 'negative' }
+ ));
+ });
});
});
diff --git a/src/composables/useState.js b/src/composables/useState.js
index df121398ef..2f182d6514 100644
--- a/src/composables/useState.js
+++ b/src/composables/useState.js
@@ -2,7 +2,7 @@ import { ref, computed } from 'vue';
const user = ref({
id: 0,
- username: '',
+ name: '',
nickname: '',
});
@@ -13,7 +13,7 @@ export function useState() {
return computed(() => {
return {
id: user.value.id,
- username: user.value.username,
+ name: user.value.name,
nickname: user.value.nickname,
};
});
@@ -22,7 +22,7 @@ export function useState() {
function setUser(data) {
user.value = {
id: data.id,
- username: data.username,
+ name: data.name,
nickname: data.nickname,
};
}