Commit ceb67e5e authored by MARCO Jonathan's avatar MARCO Jonathan
Browse files

Start the tests writting

parent ffbfaf3c
......@@ -26,4 +26,14 @@ module.exports = {
parserOptions: {
parser: 'babel-eslint',
},
overrides: [
{
files: [
'**/__tests__/*.{j,t}s?(x)'
],
env: {
mocha: true
}
}
]
};
......@@ -19,3 +19,7 @@ yarn-error.log*
*.njsproj
*.sln
*.sw*
# tests
coverage
.nyc_output
module.exports = {
'check-coverage': false,
'per-file': true,
'skip-full': true,
all: true,
include: [
'src/**/*.{js,vue}',
],
exclude: [
'src/*.js',
'**/index.js',
'src/plugins/*',
],
reporter: [
'lcov',
'text',
'text-summary',
],
extension: [
'.js',
'.vue',
],
}
......@@ -5,12 +5,13 @@
"author": "Unistra - DNUM",
"scripts": {
"serve": "vue-cli-service serve --mode dev",
"test:unit": "vue-cli-service test:unit",
"lint": "vue-cli-service lint",
"build:local": "vue-cli-service build --mode local",
"build:preprod": "vue-cli-service build --mode preprod",
"build:prod": "vue-cli-service build --mode prod",
"build:test": "vue-cli-service build --mode test"
"build:test": "vue-cli-service build --mode test",
"test:unit": "vue-cli-service test:unit",
"test:unit:coverage": "nyc vue-cli-service test:unit"
},
"main": "src/plugin.js",
"dependencies": {
......
......@@ -50,7 +50,10 @@ const addField = ({ commit, rootState, getters, dispatch }, payload) => {
// Crée la locale par défaut s'il n'en existe pas du tout
if (Object.keys(locales).length === 0) {
dispatch('createNewLocale', defaultLocale);
dispatch('createNewLocale', {
value: defaultLocale,
rtl: false,
});
} else {
// Ajoute le champ dans les locales s'il y a une ou des locales
const settings = rootState.formBuilder.controls.controls[fieldWithoutId.component].settingsModalTabs;
......@@ -305,7 +308,7 @@ const update = ({ commit, state }) => {
Object.keys(state.internationalization.locales)
.forEach(locale => {
const { rtl, ...translations } = state.internationalization.locales[locale];
const versionId = response.data.version_id
const versionId = response.data.version_id;
_axios.patch(`/api/i18n/${locale}/version/${versionId}/`, {
locale,
rtl,
......
......@@ -30,7 +30,7 @@ import _ from 'lodash';
* @property {Number} versionId - Version number.
* @return {Form}
*/
const getDefaultState = () => ({
export const getDefaultState = () => ({
fields: {},
form: {
form_id: 0,
......
......@@ -11,15 +11,16 @@ const defaultLocale = process.env.VUE_APP_DEFAULT_LOCALE;
* @param {String} newLocale.rtl
*/
const createNewLocale = ({ commit, state, rootGetters, getters }, { value: newLocaleName, rtl }) => {
commit('CREATE_NEW_LOCALE', { newLocaleName, rtl });
commit('CREATE_NEW_LOCALE', {
newLocaleName,
rtl,
});
for (const id in state.fields) {
if (state.fields.hasOwnProperty(id)) {
const internationalizationOptions = rootGetters['formBuilder/controls/getControlById'](
state.fields[id].component,
)
.settingsModalTabs
.find(tab => tab.component === 'UsfTabInternationalization');
).settingsModalTabs.find(tab => tab.component === 'UsfTabInternationalization');
// Add options in new locale created
if (internationalizationOptions) {
......
export const checkboxField = {
'component': 'UsfCheckboxSwitch',
'type': 'checkbox',
'exist': true,
'visible': true,
'parentId': 'root',
'id': 'zfes6zoun1k',
};
export const emptyLocaleFr = { fr_FR: { rtl: false } };
export const localeFrWithMinField = {
fr_FR: {
rtl: false,
zfes6zoun1k: {
hint: '',
label: '',
},
},
};
import moxios from 'moxios';
import { _axios } from '@/plugins/axios';
import store from '@/store';
import { getDefaultState } from '@/store/modules/form/utils';
import { expect } from 'chai';
import { checkboxField } from '../fixtures/fields';
import { emptyLocaleFr, localeFrWithMinField } from '../fixtures/locale';
describe('store/internationalization', () => {
beforeEach(() => {
moxios.install(_axios);
store.state.form = getDefaultState();
});
afterEach(() => {
moxios.uninstall(_axios);
});
describe('createNewLocale', () => {
it('should create new locale empty if no field in state', () => {
store.dispatch('form/createNewLocale', {
value: 'fr_FR',
rtl: false,
});
expect(store.getters['form/getLocales']).to.be.eql(emptyLocaleFr);
expect(Object.keys(store.state.form.internationalization.locales).length).to.be.equal(1);
expect(
Object.keys(store.state.form.internationalization.locales['fr_FR']).length
).to.be.equal(1);
});
it('should create new locale with min object if one min field in state', () => {
store.state.form.fields[checkboxField.id] = checkboxField;
store.dispatch('form/createNewLocale', {
value: 'fr_FR',
rtl: false,
});
expect(store.getters['form/getLocales']).to.be.eql(localeFrWithMinField);
expect(Object.keys(store.state.form.internationalization.locales).length).to.be.equal(1);
expect(
Object.keys(store.state.form.internationalization.locales['fr_FR']).length
).to.be.equal(2);
});
});
});
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment