@@ -38,7 +37,6 @@
-
-
diff --git a/src/pages/SplashPage.vue b/src/pages/SplashPage.vue
index 43b4fa983..bec0b025e 100644
--- a/src/pages/SplashPage.vue
+++ b/src/pages/SplashPage.vue
@@ -30,11 +30,11 @@ import { Notify } from 'quasar';
import { useI18n } from 'vue-i18n';
import { useRoute, useRouter } from 'vue-router';
import { onMounted } from 'vue';
-import { initPlugins } from 'src/composables/PluginManager';
+import { getPlugins, initPlugins } from 'src/composables/PluginManager';
import PluginEvent from 'src/composables/events/PluginEvent';
import * as UserService from 'src/services/UserService';
-const { t } = useI18n();
+const i18n = useI18n();
const route = useRoute();
const router = useRouter();
@@ -52,7 +52,7 @@ async function initUser() {
.catch(() => {
Notify.create({
type: 'negative',
- message: t('errors.authentication.fetchingUserInformation'),
+ message: i18n.t('errors.authentication.fetchingUserInformation'),
html: true,
});
}),
@@ -60,16 +60,33 @@ async function initUser() {
.catch(() => {
Notify.create({
type: 'negative',
- message: t('errors.authentication.fetchingUserPermissions'),
+ message: i18n.t('errors.authentication.fetchingUserPermissions'),
html: true,
});
}),
]);
}
+/**
+ * Initialize translation of plugins.
+ */
+function initPluginsI18n() {
+ i18n.availableLocales.forEach((local) => {
+ const newMessages = {};
+
+ getPlugins().forEach((plugin) => {
+ newMessages[plugin.data.name] = plugin.configuration.i18n[local];
+ });
+
+ i18n.mergeLocaleMessage(local, newMessages);
+ });
+}
+
onMounted(async () => {
await initUser();
await initPlugins();
+ initPluginsI18n();
+
PluginEvent.InitEvent.next();
// Wait 2s to avoid blinking effect and let user admire our beautiful splash screen.
diff --git a/tests/unit/components/drawer/ConsoleFooter.spec.js b/tests/unit/components/drawer/ConsoleFooter.spec.js
index e09c1f5db..55845158b 100644
--- a/tests/unit/components/drawer/ConsoleFooter.spec.js
+++ b/tests/unit/components/drawer/ConsoleFooter.spec.js
@@ -1,13 +1,30 @@
import { installQuasarPlugin } from '@quasar/quasar-app-extension-testing-unit-jest';
import { shallowMount } from '@vue/test-utils';
import ConsoleFooter from 'src/components/drawer/ConsoleFooter.vue';
+import LogEvent from 'src/composables/events/LogEvent';
installQuasarPlugin();
+jest.mock('src/composables/events/LogEvent', () => ({
+ FileLogEvent: {
+ subscribe: jest.fn(),
+ },
+}));
+
describe('Test component: ConsoleFooter', () => {
let wrapper;
+ let fileLogEventSubscription;
+ let fileLogEventUnsubscribe;
beforeEach(() => {
+ fileLogEventSubscription = jest.fn();
+ fileLogEventUnsubscribe = jest.fn();
+
+ LogEvent.FileLogEvent.subscribe.mockImplementation(() => {
+ fileLogEventSubscription();
+ return { unsubscribe: fileLogEventUnsubscribe };
+ });
+
wrapper = shallowMount(ConsoleFooter, {
props: {
errors: [{
@@ -33,4 +50,27 @@ describe('Test component: ConsoleFooter', () => {
expect(wrapper.vm.selectedTab).toEqual(null);
});
});
+
+ describe('Test function updateFileLogs', () => {
+ it('should update logs on call', () => {
+ expect(wrapper.vm.logs).toEqual([]);
+
+ wrapper.vm.updateFileLogs(['test']);
+ expect(wrapper.vm.logs).toEqual(['test']);
+ });
+ });
+
+ describe('Test hook function: onMounted', () => {
+ it('should subscribe to FileLogEvent', () => {
+ expect(fileLogEventSubscription).toHaveBeenCalledTimes(1);
+ });
+ });
+
+ describe('Test hook function: onUnmounted', () => {
+ it('should unsubscribe to FileLogEvent', () => {
+ expect(fileLogEventUnsubscribe).toHaveBeenCalledTimes(0);
+ wrapper.unmount();
+ expect(fileLogEventUnsubscribe).toHaveBeenCalledTimes(1);
+ });
+ });
});
diff --git a/tests/unit/components/editor/MonacoEditor.spec.js b/tests/unit/components/editor/MonacoEditor.spec.js
index b9b6c6705..9f5f838a5 100644
--- a/tests/unit/components/editor/MonacoEditor.spec.js
+++ b/tests/unit/components/editor/MonacoEditor.spec.js
@@ -5,13 +5,24 @@ import MonacoEditor from 'components/editor/MonacoEditor.vue';
import Project from 'src/composables/Project';
import GitEvent from 'src/composables/events/GitEvent';
import FileEvent from 'src/composables/events/FileEvent';
+import LogEvent from 'src/composables/events/LogEvent';
installQuasarPlugin();
+jest.mock('vue-i18n', () => ({
+ useI18n: () => ({
+ t: (t) => t,
+ }),
+}));
+
jest.mock('monaco-editor', () => ({
__esModule: true,
editor: {
- create: jest.fn(),
+ create: jest.fn(() => ({
+ getModel: jest.fn(() => 'model'),
+ })),
+ setModelMarkers: jest.fn(),
+ getModel: jest.fn(() => 'model'),
},
languages: {
register: jest.fn(),
@@ -30,8 +41,15 @@ jest.mock('src/composables/Git', () => ({
getStatus: jest.fn(() => Promise.resolve([{ path: 'file.js' }])),
}));
+jest.mock('src/composables/events/LogEvent', () => ({
+ FileLogEvent: {
+ next: jest.fn(),
+ },
+}));
+
jest.mock('src/composables/PluginManager', () => ({
initMonacoLanguages: jest.fn(() => 'test'),
+ analyzeFile: jest.fn(() => []),
getPlugins: jest.fn(() => [{
data: {
name: 'test1',
@@ -89,7 +107,7 @@ jest.mock('src/composables/events/FileEvent', () => ({
},
}));
-describe('Tess component: MonacoEditor', () => {
+describe('Test component: MonacoEditor', () => {
let wrapper;
let checkoutSubscribe;
let checkoutUnsubscribe;
@@ -101,6 +119,7 @@ describe('Tess component: MonacoEditor', () => {
const dispose = jest.fn();
const layout = jest.fn();
const setValue = jest.fn();
+ const getModel = jest.fn();
const onDidChangeModelContent = jest.fn();
const writeProjectFileMock = jest.fn(() => Promise.resolve());
@@ -110,6 +129,7 @@ describe('Tess component: MonacoEditor', () => {
setValue,
layout,
onDidChangeModelContent,
+ getModel,
}));
Project.writeProjectFile.mockImplementation(writeProjectFileMock);
@@ -175,6 +195,14 @@ describe('Tess component: MonacoEditor', () => {
});
});
+ describe('Test function: updateMarkers', () => {
+ it('should emit event and set markers', () => {
+ wrapper.vm.updateMarkers('path', 'content');
+
+ expect(LogEvent.FileLogEvent.next).toBeCalledWith([]);
+ });
+ });
+
describe('Test function: updateEditorLayout', () => {
it('should be called', () => {
expect(layout).toHaveBeenCalledTimes(0);
diff --git a/tests/unit/components/inputs/InputWrapper.spec.js b/tests/unit/components/inputs/InputWrapper.spec.js
index 9bd4eb233..5a6852cab 100644
--- a/tests/unit/components/inputs/InputWrapper.spec.js
+++ b/tests/unit/components/inputs/InputWrapper.spec.js
@@ -29,7 +29,9 @@ describe('Test component: InputWrapper', () => {
name: 'referenceTest',
definition: {
type: 'Reference',
- rules: {},
+ rules: {
+ values: [],
+ },
},
},
plugin: {},
@@ -47,7 +49,9 @@ describe('Test component: InputWrapper', () => {
name: 'referenceTest',
definition: {
type: 'Reference',
- rules: {},
+ rules: {
+ values: [],
+ },
},
});
});
@@ -86,7 +90,7 @@ describe('Test component: InputWrapper', () => {
const attribute = {
definition: {
rules: {
- values: [],
+ values: ['test'],
},
},
};
@@ -97,7 +101,9 @@ describe('Test component: InputWrapper', () => {
const attribute = {
definition: {
type: 'typeInDefinition',
- rules: {},
+ rules: {
+ values: [],
+ },
},
};
expect(wrapper.vm.getAttributeType(attribute)).toEqual('typeInDefinition');
diff --git a/tests/unit/components/table/ErrorsTable.spec.js b/tests/unit/components/table/ErrorsTable.spec.js
index 4500a0f16..b090419b2 100644
--- a/tests/unit/components/table/ErrorsTable.spec.js
+++ b/tests/unit/components/table/ErrorsTable.spec.js
@@ -39,39 +39,28 @@ describe('Test component: ErrorsTable', () => {
});
describe('Test computed: columns', () => {
- it('should equals columnsComputed', () => {
- const field = () => 'field';
- const columnsComputed = [
- {
- name: 'severity',
- align: 'left',
- label: 'footer.consoleFooter.errorsTable.severity',
- field: 'severity',
- style: 'width: 2rem',
- },
- {
- name: 'line',
- align: 'center',
- label: 'footer.consoleFooter.errorsTable.line',
- field,
- style: 'width: 2rem',
- },
- {
- name: 'column',
- align: 'center',
- label: 'footer.consoleFooter.errorsTable.column',
- field,
- style: 'width: 2rem',
- },
- {
- name: 'message',
- align: 'left',
- label: 'footer.consoleFooter.errorsTable.message',
- field: 'message',
- },
- ];
+ it('should have valid columns for diagram page', async () => {
+ await wrapper.setProps({
+ editorType: 'diagram',
+ });
- expect(JSON.stringify(wrapper.vm.columns)).toEqual(JSON.stringify(columnsComputed));
+ expect(wrapper.vm.columns.length).toEqual(4);
+ expect(wrapper.vm.columns[0].name).toEqual('severity');
+ expect(wrapper.vm.columns[1].name).toEqual('component');
+ expect(wrapper.vm.columns[2].name).toEqual('attribute');
+ expect(wrapper.vm.columns[3].name).toEqual('message');
+ });
+
+ it('should have valid columns for text page', async () => {
+ await wrapper.setProps({
+ editorType: 'text',
+ });
+
+ expect(wrapper.vm.columns.length).toEqual(4);
+ expect(wrapper.vm.columns[0].name).toEqual('severity');
+ expect(wrapper.vm.columns[1].name).toEqual('line');
+ expect(wrapper.vm.columns[2].name).toEqual('column');
+ expect(wrapper.vm.columns[3].name).toEqual('message');
});
});
});
diff --git a/tests/unit/composables/PluginManager.spec.js b/tests/unit/composables/PluginManager.spec.js
index 3950111cf..b2ad986b0 100644
--- a/tests/unit/composables/PluginManager.spec.js
+++ b/tests/unit/composables/PluginManager.spec.js
@@ -1,6 +1,6 @@
import * as PluginManager from 'src/composables/PluginManager';
import { deleteProjectFile, writeProjectFile, setFiles } from 'src/composables/Project';
-import { FileInformation } from 'leto-modelizer-plugin-core';
+import { FileInformation, FileInput } from 'leto-modelizer-plugin-core';
jest.mock('src/plugins', () => ({
test: class {
@@ -12,6 +12,7 @@ jest.mock('src/plugins', () => ({
links: [],
},
components: [],
+ parseLogs: [],
};
this.configuration = {
tags: [{
@@ -26,6 +27,7 @@ jest.mock('src/plugins', () => ({
}],
extraResources: [],
};
+ this.parse = jest.fn();
}
// eslint-disable-next-line class-methods-use-this
@@ -60,6 +62,7 @@ jest.mock('src/plugins', () => ({
links: [],
},
components: [],
+ parseLogs: [],
};
this.configuration = {
tags: [{
@@ -74,6 +77,7 @@ jest.mock('src/plugins', () => ({
}],
extraResources: [],
};
+ this.parse = jest.fn();
}
// eslint-disable-next-line class-methods-use-this
@@ -221,79 +225,18 @@ describe('Test composable: PluginManager', () => {
describe('Test function: initPlugins', () => {
it('should instantiate all plugins', async () => {
await PluginManager.initPlugins();
- expect(PluginManager.getPlugins()).toEqual([{
- data: {
- name: 'test',
- definitions: {
- links: [],
- components: [],
- },
- components: [],
- },
- configuration: {
- tags: [{
- type: 'category',
- value: 'a',
- }, {
- type: 'category',
- value: 'd',
- }, {
- type: 'category',
- value: 'e',
- }],
- extraResources: [],
- },
- }, {
- data: {
- name: 'test2',
- definitions: {
- links: [],
- components: [],
- },
- components: [],
- },
- configuration: {
- tags: [{
- type: 'category',
- value: 'a',
- }, {
- type: 'category',
- value: 'd',
- }, {
- type: 'category',
- value: 'e',
- }],
- extraResources: [],
- },
- }]);
+
+ const plugins = PluginManager.getPlugins();
+
+ expect(plugins.length).toEqual(2);
+ expect(plugins[0].data.name).toEqual('test');
+ expect(plugins[1].data.name).toEqual('test2');
});
});
describe('Test function: getPluginByName', () => {
it('should return the plugin according to the given name', () => {
- expect(PluginManager.getPluginByName('test')).toEqual({
- data: {
- name: 'test',
- definitions: {
- links: [],
- components: [],
- },
- components: [],
- },
- configuration: {
- tags: [{
- type: 'category',
- value: 'a',
- }, {
- type: 'category',
- value: 'd',
- }, {
- type: 'category',
- value: 'e',
- }],
- extraResources: [],
- },
- });
+ expect(PluginManager.getPluginByName('test').data.name).toEqual('test');
});
});
@@ -472,13 +415,17 @@ describe('Test composable: PluginManager', () => {
configuration: {
isFolderTypeDiagram: false,
},
+ data: {
+ parseLogs: [],
+ },
};
expect(plugin.parse).toHaveBeenCalledTimes(0);
- await PluginManager.initComponents('projectName', plugin, 'plugin/model');
+ const logs = await PluginManager.initComponents('projectName', plugin, 'plugin/model');
expect(plugin.parse).toHaveBeenCalledTimes(1);
+ expect(logs).toEqual([]);
});
it('should call setFiles if isFolderTypeDiagram is true', async () => {
@@ -488,13 +435,36 @@ describe('Test composable: PluginManager', () => {
configuration: {
isFolderTypeDiagram: true,
},
+ data: {
+ parseLogs: [],
+ },
};
expect(setFiles).toHaveBeenCalledTimes(0);
- await PluginManager.initComponents('projectName', plugin, '');
+ const logs = await PluginManager.initComponents('projectName', plugin, '');
expect(setFiles).toHaveBeenCalledTimes(1);
+ expect(logs).toEqual([]);
+ });
+ });
+
+ describe('Test function: analyzeFile', () => {
+ it('should return logs', async () => {
+ await PluginManager.initPlugins();
+
+ const plugin = PluginManager.getPlugins()[0];
+ const input = new FileInput({
+ path: 'test1/test2/test3.tf',
+ content: 'test',
+ });
+
+ expect(PluginManager.analyzeFile(input)).toEqual([]);
+ expect(plugin.parse).toBeCalledWith(
+ { path: 'test1/test2' },
+ { path: 'test1/leto-modelizer.config.json' },
+ [{ content: 'test', path: 'test1/test2/test3.tf' }],
+ );
});
});
diff --git a/tests/unit/composables/events/LogEvent.spec.js b/tests/unit/composables/events/LogEvent.spec.js
new file mode 100644
index 000000000..7840028d4
--- /dev/null
+++ b/tests/unit/composables/events/LogEvent.spec.js
@@ -0,0 +1,9 @@
+import { Subject } from 'rxjs';
+import LogEvent from 'src/composables/events/LogEvent';
+
+describe('Test composable: LogEvent', () => {
+ it('should export a Subject', () => {
+ expect(LogEvent.FileLogEvent).toBeDefined();
+ expect(LogEvent.FileLogEvent).toEqual(new Subject());
+ });
+});
diff --git a/tests/unit/layouts/ModelizerDrawLayout.spec.js b/tests/unit/layouts/ModelizerDrawLayout.spec.js
index 942a15826..78ded8c4e 100644
--- a/tests/unit/layouts/ModelizerDrawLayout.spec.js
+++ b/tests/unit/layouts/ModelizerDrawLayout.spec.js
@@ -4,6 +4,7 @@ import { shallowMount } from '@vue/test-utils';
import ModelizerDrawLayout from 'src/layouts/ModelizerDrawLayout.vue';
import PluginManager from 'src/composables/PluginManager';
import TemplateManager from 'src/composables/TemplateManager';
+import LogEvent from 'src/composables/events/LogEvent';
installQuasarPlugin({
plugins: [Notify],
@@ -28,6 +29,12 @@ jest.mock('vue-router', () => ({
}),
}));
+jest.mock('src/composables/events/LogEvent', () => ({
+ FileLogEvent: {
+ next: jest.fn(),
+ },
+}));
+
jest.mock('src/composables/PluginManager', () => ({
getPluginByName: jest.fn(() => ({
data: {
@@ -50,7 +57,7 @@ jest.mock('src/composables/PluginManager', () => ({
parse: jest.fn(),
draw: jest.fn(),
})),
- initComponents: jest.fn(() => Promise.resolve()),
+ initComponents: jest.fn(() => Promise.resolve([])),
}));
jest.mock('src/composables/TemplateManager', () => ({
@@ -117,6 +124,7 @@ describe('Test page component: ModelizerDrawLayout', () => {
key: 'testTemplate',
plugin: 'pluginName',
}]);
+ expect(LogEvent.FileLogEvent.next).toBeCalledWith([]);
});
it('should emit a negative notification on error after failing to retrieve templates', async () => {
diff --git a/tests/unit/layouts/ModelizerTextLayout.spec.js b/tests/unit/layouts/ModelizerTextLayout.spec.js
index 060f52a86..5dec4affc 100644
--- a/tests/unit/layouts/ModelizerTextLayout.spec.js
+++ b/tests/unit/layouts/ModelizerTextLayout.spec.js
@@ -80,12 +80,6 @@ describe('Test component: ModelizerTextLayout', () => {
expect(wrapper.vm.projectName).toEqual('project-00000000');
});
});
-
- describe('Test ref: parseErrors', () => {
- it('should match []', () => {
- expect(wrapper.vm.parseErrors).toEqual([]);
- });
- });
});
describe('Test function: onSelectFileTab', () => {
diff --git a/tests/unit/pages/SplashPage.spec.js b/tests/unit/pages/SplashPage.spec.js
index 6ee65b535..7dc0bdf1c 100644
--- a/tests/unit/pages/SplashPage.spec.js
+++ b/tests/unit/pages/SplashPage.spec.js
@@ -6,18 +6,32 @@ import PluginManager from 'src/composables/PluginManager';
import { initUserInformation, initUserPermissions } from 'src/services/UserService';
import { setActivePinia, createPinia } from 'pinia';
import { Notify } from 'quasar';
+import { useI18n } from 'vue-i18n';
installQuasarPlugin();
jest.mock('vue-i18n', () => ({
- useI18n: () => ({
+ useI18n: jest.fn(() => ({
t: (t) => t,
- }),
+ mergeLocaleMessage: jest.fn(),
+ availableLocales: ['en-US'],
+ })),
}));
jest.mock('src/composables/PluginManager', () => ({
initPlugins: () => Promise.resolve(),
- getPlugins: jest.fn(),
+ getPlugins: jest.fn(() => [{
+ data: {
+ name: 'test',
+ },
+ configuration: {
+ i18n: {
+ 'en-US': {
+ test: 'test',
+ },
+ },
+ },
+ }]),
}));
jest.mock('src/composables/events/PluginEvent', () => ({
@@ -53,7 +67,19 @@ describe('Test component: SplashPage', () => {
beforeEach(() => {
PluginManager.getPlugins.mockImplementation(() => [
- { data: { deleteAllEventLogsBefore: jest.fn(() => {}) } },
+ {
+ data: {
+ deleteAllEventLogsBefore: jest.fn(() => {}),
+ name: 'plugin-test',
+ },
+ configuration: {
+ i18n: {
+ 'en-US': {
+ test: 'test',
+ },
+ },
+ },
+ },
]);
setActivePinia(createPinia());
@@ -82,6 +108,30 @@ describe('Test component: SplashPage', () => {
});
});
+ describe('Test function: initPluginsI18n', () => {
+ it('should update translations', () => {
+ const mergeLocaleMessage = jest.fn();
+
+ useI18n.mockImplementation(() => ({
+ t: (t) => t,
+ mergeLocaleMessage,
+ availableLocales: ['en-US'],
+ }));
+
+ wrapper = shallowMount(SplashPage, {
+ global: {
+ stubs: {
+ qIcon: true,
+ },
+ },
+ });
+
+ wrapper.vm.initPluginsI18n();
+
+ expect(mergeLocaleMessage).toBeCalledWith('en-US', { 'plugin-test': { test: 'test' } });
+ });
+ });
+
describe('Test function: initUser', () => {
beforeEach(() => {
initUserInformation.mockClear();