mirror of
https://github.com/strapi/strapi.git
synced 2025-11-16 01:57:56 +00:00
Merge pull request #10591 from strapi/v4/db-fix-ctb-tests
Fix FormModal reducer tests
This commit is contained in:
commit
f831c72dd7
@ -1,6 +1,7 @@
|
|||||||
import { fromJS, List } from 'immutable';
|
import { fromJS, List } from 'immutable';
|
||||||
import pluralize from 'pluralize';
|
import pluralize from 'pluralize';
|
||||||
import { snakeCase } from 'lodash';
|
import { snakeCase } from 'lodash';
|
||||||
|
import getRelationType from '../../utils/getRelationType';
|
||||||
import makeUnique from '../../utils/makeUnique';
|
import makeUnique from '../../utils/makeUnique';
|
||||||
import { createComponentUid } from './utils/createUid';
|
import { createComponentUid } from './utils/createUid';
|
||||||
import { shouldPluralizeName, shouldPluralizeTargetAttribute } from './utils/relations';
|
import { shouldPluralizeName, shouldPluralizeTargetAttribute } from './utils/relations';
|
||||||
@ -61,30 +62,33 @@ const reducer = (state = initialState, action) => {
|
|||||||
},
|
},
|
||||||
} = action;
|
} = action;
|
||||||
// Special case for the admin user...
|
// Special case for the admin user...
|
||||||
let didChangeNatureBecauseOfRestrictedRelation = false;
|
let didChangeRelationTypeBecauseOfRestrictedRelation = false;
|
||||||
let changedRelationType = null;
|
let changedRelationType = null;
|
||||||
|
|
||||||
return obj
|
return obj
|
||||||
.update('target', () => value)
|
.update('target', () => value)
|
||||||
.update('relation', currentRelation => {
|
.update('relation', currentRelation => {
|
||||||
|
const currentRelationType = getRelationType(
|
||||||
|
currentRelation,
|
||||||
|
obj.get('targetAttribute')
|
||||||
|
);
|
||||||
|
|
||||||
// Don't change the relation type if the allowed relations are not restricted
|
// Don't change the relation type if the allowed relations are not restricted
|
||||||
// TODO: replace with an obj { relation: 'x', bidirctional: true|false } when BE ready
|
// TODO: replace with an obj { relation: 'x', bidirctional: true|false } when BE ready
|
||||||
if (targetContentTypeAllowedRelations === null) {
|
if (targetContentTypeAllowedRelations === null) {
|
||||||
return currentRelation;
|
return currentRelation;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!targetContentTypeAllowedRelations.includes(currentRelation)) {
|
if (!targetContentTypeAllowedRelations.includes(currentRelationType)) {
|
||||||
const relationToSet = targetContentTypeAllowedRelations[0];
|
const relationToSet = targetContentTypeAllowedRelations[0];
|
||||||
didChangeNatureBecauseOfRestrictedRelation = true;
|
didChangeRelationTypeBecauseOfRestrictedRelation = true;
|
||||||
changedRelationType = relationToSet;
|
changedRelationType = relationToSet;
|
||||||
|
|
||||||
if (relationToSet === 'oneWay') {
|
if (relationToSet === 'oneWay') {
|
||||||
// TODO change targetAttribute
|
|
||||||
return 'oneToOne';
|
return 'oneToOne';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (relationToSet === 'manyWay') {
|
if (relationToSet === 'manyWay') {
|
||||||
// TODO change targetAttribute
|
|
||||||
return 'oneToMany';
|
return 'oneToMany';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,7 +98,7 @@ const reducer = (state = initialState, action) => {
|
|||||||
return currentRelation;
|
return currentRelation;
|
||||||
})
|
})
|
||||||
.update('name', () => {
|
.update('name', () => {
|
||||||
if (didChangeNatureBecauseOfRestrictedRelation) {
|
if (didChangeRelationTypeBecauseOfRestrictedRelation) {
|
||||||
return pluralize(
|
return pluralize(
|
||||||
snakeCase(selectedContentTypeFriendlyName),
|
snakeCase(selectedContentTypeFriendlyName),
|
||||||
shouldPluralizeName(changedRelationType)
|
shouldPluralizeName(changedRelationType)
|
||||||
@ -116,7 +120,7 @@ const reducer = (state = initialState, action) => {
|
|||||||
|
|
||||||
// Case when we need to change the relation to oneWay (ex: admin user)
|
// Case when we need to change the relation to oneWay (ex: admin user)
|
||||||
if (
|
if (
|
||||||
didChangeNatureBecauseOfRestrictedRelation &&
|
didChangeRelationTypeBecauseOfRestrictedRelation &&
|
||||||
['oneWay', 'manyWay'].includes(changedRelationType)
|
['oneWay', 'manyWay'].includes(changedRelationType)
|
||||||
) {
|
) {
|
||||||
return null;
|
return null;
|
||||||
@ -124,7 +128,7 @@ const reducer = (state = initialState, action) => {
|
|||||||
|
|
||||||
return pluralize(
|
return pluralize(
|
||||||
snakeCase(oneThatIsCreatingARelationWithAnother),
|
snakeCase(oneThatIsCreatingARelationWithAnother),
|
||||||
shouldPluralizeTargetAttribute(obj.get('nature'))
|
shouldPluralizeTargetAttribute(obj.get('relation'))
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -62,7 +62,7 @@ describe('CTB | components | FormModal | reducer | actions', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe(actions.ON_CHANGE, () => {
|
describe(actions.ON_CHANGE, () => {
|
||||||
it('Should update the modifiedData object correctly if it is not relation', () => {
|
it('Should update the modifiedData object correctly', () => {
|
||||||
const action = {
|
const action = {
|
||||||
type: actions.ON_CHANGE,
|
type: actions.ON_CHANGE,
|
||||||
keys: ['name'],
|
keys: ['name'],
|
||||||
@ -74,214 +74,6 @@ describe('CTB | components | FormModal | reducer | actions', () => {
|
|||||||
expect(reducer(state, action)).toEqual(expected);
|
expect(reducer(state, action)).toEqual(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should handle the nature change correctly from oneWay to manyToMany', () => {
|
|
||||||
const state = initialState.setIn(
|
|
||||||
['modifiedData'],
|
|
||||||
fromJS({
|
|
||||||
name: 'category test',
|
|
||||||
nature: 'oneWay',
|
|
||||||
targetAttribute: '-',
|
|
||||||
target: 'application::category.category',
|
|
||||||
unique: false,
|
|
||||||
dominant: null,
|
|
||||||
columnName: null,
|
|
||||||
targetColumnName: null,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
const action = {
|
|
||||||
type: actions.ON_CHANGE,
|
|
||||||
keys: ['nature'],
|
|
||||||
value: 'manyToMany',
|
|
||||||
targetContentType: 'application::category.category',
|
|
||||||
oneThatIsCreatingARelationWithAnother: 'address',
|
|
||||||
};
|
|
||||||
const expected = state
|
|
||||||
.setIn(['modifiedData', 'nature'], 'manyToMany')
|
|
||||||
.setIn(['modifiedData', 'dominant'], true)
|
|
||||||
.setIn(['modifiedData', 'name'], 'category_tests')
|
|
||||||
.setIn(['modifiedData', 'targetAttribute'], 'addresses');
|
|
||||||
|
|
||||||
expect(reducer(state, action)).toEqual(expected);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Should handle the nature change correctly from manyToMany to oneWay', () => {
|
|
||||||
const state = initialState.setIn(
|
|
||||||
['modifiedData'],
|
|
||||||
fromJS({
|
|
||||||
name: 'category_tests',
|
|
||||||
nature: 'manyToMany',
|
|
||||||
targetAttribute: 'addresses',
|
|
||||||
target: 'application::category.category',
|
|
||||||
unique: false,
|
|
||||||
dominant: true,
|
|
||||||
columnName: null,
|
|
||||||
targetColumnName: 'test',
|
|
||||||
})
|
|
||||||
);
|
|
||||||
const action = {
|
|
||||||
type: actions.ON_CHANGE,
|
|
||||||
keys: ['nature'],
|
|
||||||
value: 'oneWay',
|
|
||||||
targetContentType: 'application::category.category',
|
|
||||||
oneThatIsCreatingARelationWithAnother: 'address',
|
|
||||||
};
|
|
||||||
const expected = state
|
|
||||||
.setIn(['modifiedData', 'nature'], 'oneWay')
|
|
||||||
.setIn(['modifiedData', 'dominant'], null)
|
|
||||||
.setIn(['modifiedData', 'name'], 'category_test')
|
|
||||||
.setIn(['modifiedData', 'targetAttribute'], '-')
|
|
||||||
.setIn(['modifiedData', 'targetColumnName'], null);
|
|
||||||
|
|
||||||
expect(reducer(state, action)).toEqual(expected);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Should handle the nature change correctly from oneToOne to oneToMany', () => {
|
|
||||||
const state = initialState.setIn(
|
|
||||||
['modifiedData'],
|
|
||||||
fromJS({
|
|
||||||
name: 'category_test',
|
|
||||||
nature: 'oneToOne',
|
|
||||||
targetAttribute: 'address',
|
|
||||||
target: 'application::category.category',
|
|
||||||
unique: false,
|
|
||||||
dominant: null,
|
|
||||||
columnName: null,
|
|
||||||
targetColumnName: 'test',
|
|
||||||
})
|
|
||||||
);
|
|
||||||
const action = {
|
|
||||||
type: actions.ON_CHANGE,
|
|
||||||
keys: ['nature'],
|
|
||||||
value: 'oneToMany',
|
|
||||||
targetContentType: 'application::category.category',
|
|
||||||
oneThatIsCreatingARelationWithAnother: 'address',
|
|
||||||
};
|
|
||||||
const expected = state
|
|
||||||
.setIn(['modifiedData', 'nature'], 'oneToMany')
|
|
||||||
.setIn(['modifiedData', 'name'], 'category_tests');
|
|
||||||
|
|
||||||
expect(reducer(state, action)).toEqual(expected);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Should handle the target change correctly for a one side relation (oneWay, manyWay)', () => {
|
|
||||||
const state = initialState.setIn(
|
|
||||||
['modifiedData'],
|
|
||||||
fromJS({
|
|
||||||
name: 'category test',
|
|
||||||
nature: 'oneWay',
|
|
||||||
targetAttribute: '-',
|
|
||||||
target: 'application::category.category',
|
|
||||||
unique: false,
|
|
||||||
dominant: null,
|
|
||||||
columnName: null,
|
|
||||||
targetColumnName: null,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
const action = {
|
|
||||||
type: actions.ON_CHANGE,
|
|
||||||
keys: ['target'],
|
|
||||||
value: 'application::address.address',
|
|
||||||
oneThatIsCreatingARelationWithAnother: 'address',
|
|
||||||
selectedContentTypeFriendlyName: 'address',
|
|
||||||
targetContentTypeAllowedRelations: null,
|
|
||||||
};
|
|
||||||
const expected = state
|
|
||||||
.setIn(['modifiedData', 'target'], 'application::address.address')
|
|
||||||
.setIn(['modifiedData', 'name'], 'address');
|
|
||||||
|
|
||||||
expect(reducer(state, action)).toEqual(expected);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Should handle the target change correctly for the manyToMany relation', () => {
|
|
||||||
const state = initialState.setIn(
|
|
||||||
['modifiedData'],
|
|
||||||
fromJS({
|
|
||||||
name: 'categories',
|
|
||||||
nature: 'manyToMany',
|
|
||||||
targetAttribute: 'addresses',
|
|
||||||
target: 'application::category.category',
|
|
||||||
unique: false,
|
|
||||||
dominant: true,
|
|
||||||
columnName: null,
|
|
||||||
targetColumnName: null,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
const action = {
|
|
||||||
type: actions.ON_CHANGE,
|
|
||||||
keys: ['target'],
|
|
||||||
value: 'application::country.country',
|
|
||||||
oneThatIsCreatingARelationWithAnother: 'address',
|
|
||||||
selectedContentTypeFriendlyName: 'country',
|
|
||||||
targetContentTypeAllowedRelations: null,
|
|
||||||
};
|
|
||||||
const expected = state
|
|
||||||
.setIn(['modifiedData', 'target'], 'application::country.country')
|
|
||||||
.setIn(['modifiedData', 'name'], 'countries');
|
|
||||||
|
|
||||||
expect(reducer(state, action)).toEqual(expected);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Should handle the target change correctly if the target has restricted relations and the nature is not correct', () => {
|
|
||||||
const state = initialState.setIn(
|
|
||||||
['modifiedData'],
|
|
||||||
fromJS({
|
|
||||||
name: 'categories',
|
|
||||||
nature: 'manyToMany',
|
|
||||||
targetAttribute: 'addresses',
|
|
||||||
target: 'application::category.category',
|
|
||||||
unique: false,
|
|
||||||
dominant: true,
|
|
||||||
columnName: null,
|
|
||||||
targetColumnName: null,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
const action = {
|
|
||||||
type: actions.ON_CHANGE,
|
|
||||||
keys: ['target'],
|
|
||||||
value: 'application::country.country',
|
|
||||||
oneThatIsCreatingARelationWithAnother: 'address',
|
|
||||||
selectedContentTypeFriendlyName: 'country',
|
|
||||||
targetContentTypeAllowedRelations: ['oneWay'],
|
|
||||||
};
|
|
||||||
const expected = state
|
|
||||||
.setIn(['modifiedData', 'target'], 'application::country.country')
|
|
||||||
.setIn(['modifiedData', 'name'], 'country')
|
|
||||||
.setIn(['modifiedData', 'targetAttribute'], '-')
|
|
||||||
.setIn(['modifiedData', 'nature'], 'oneWay');
|
|
||||||
|
|
||||||
expect(reducer(state, action)).toEqual(expected);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Should handle the target change correctly if the target has restricted relations and the nature is correct', () => {
|
|
||||||
const state = initialState.setIn(
|
|
||||||
['modifiedData'],
|
|
||||||
fromJS({
|
|
||||||
name: 'categories',
|
|
||||||
nature: 'manyWay',
|
|
||||||
targetAttribute: 'addresses',
|
|
||||||
target: 'application::category.category',
|
|
||||||
unique: false,
|
|
||||||
dominant: true,
|
|
||||||
columnName: null,
|
|
||||||
targetColumnName: null,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
const action = {
|
|
||||||
type: actions.ON_CHANGE,
|
|
||||||
keys: ['target'],
|
|
||||||
value: 'application::country.country',
|
|
||||||
oneThatIsCreatingARelationWithAnother: 'address',
|
|
||||||
selectedContentTypeFriendlyName: 'country',
|
|
||||||
targetContentTypeAllowedRelations: ['oneWay', 'manyWay'],
|
|
||||||
};
|
|
||||||
const expected = state
|
|
||||||
.setIn(['modifiedData', 'target'], 'application::country.country')
|
|
||||||
.setIn(['modifiedData', 'name'], 'countries')
|
|
||||||
.setIn(['modifiedData', 'targetAttribute'], '-');
|
|
||||||
|
|
||||||
expect(reducer(state, action)).toEqual(expected);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should remove the default value if the type of date input type has been changed', () => {
|
it('should remove the default value if the type of date input type has been changed', () => {
|
||||||
const state = initialState.setIn(
|
const state = initialState.setIn(
|
||||||
['modifiedData'],
|
['modifiedData'],
|
||||||
@ -406,6 +198,200 @@ describe('CTB | components | FormModal | reducer | actions', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('ON_CHANGE_RELATION_TARGET', () => {
|
||||||
|
it('Should handle the target change correctly for a one side relation (oneWay, manyWay)', () => {
|
||||||
|
const state = initialState.setIn(
|
||||||
|
['modifiedData'],
|
||||||
|
fromJS({
|
||||||
|
name: 'category test',
|
||||||
|
relation: 'oneToOne',
|
||||||
|
targetAttribute: null,
|
||||||
|
target: 'application::category.category',
|
||||||
|
type: 'relation',
|
||||||
|
})
|
||||||
|
);
|
||||||
|
const action = {
|
||||||
|
type: actions.ON_CHANGE_RELATION_TARGET,
|
||||||
|
target: {
|
||||||
|
value: 'application::address.address',
|
||||||
|
oneThatIsCreatingARelationWithAnother: 'address',
|
||||||
|
selectedContentTypeFriendlyName: 'address',
|
||||||
|
targetContentTypeAllowedRelations: null,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
const expected = state
|
||||||
|
.setIn(['modifiedData', 'target'], 'application::address.address')
|
||||||
|
.setIn(['modifiedData', 'name'], 'address');
|
||||||
|
|
||||||
|
expect(reducer(state, action)).toEqual(expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Should handle the target change correctly for the manyToMany relation', () => {
|
||||||
|
const state = initialState.setIn(
|
||||||
|
['modifiedData'],
|
||||||
|
fromJS({
|
||||||
|
name: 'categories',
|
||||||
|
relation: 'manyToMany',
|
||||||
|
targetAttribute: 'addresses',
|
||||||
|
target: 'application::category.category',
|
||||||
|
type: 'relation',
|
||||||
|
})
|
||||||
|
);
|
||||||
|
const action = {
|
||||||
|
type: actions.ON_CHANGE_RELATION_TARGET,
|
||||||
|
target: {
|
||||||
|
value: 'application::country.country',
|
||||||
|
oneThatIsCreatingARelationWithAnother: 'address',
|
||||||
|
selectedContentTypeFriendlyName: 'country',
|
||||||
|
targetContentTypeAllowedRelations: null,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
const expected = state
|
||||||
|
.setIn(['modifiedData', 'target'], 'application::country.country')
|
||||||
|
.setIn(['modifiedData', 'name'], 'countries');
|
||||||
|
|
||||||
|
expect(reducer(state, action)).toEqual(expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Should handle the target change correctly if the target has restricted relations and the relation type is not correct', () => {
|
||||||
|
const state = initialState.setIn(
|
||||||
|
['modifiedData'],
|
||||||
|
fromJS({
|
||||||
|
name: 'categories',
|
||||||
|
relation: 'manyToMany',
|
||||||
|
targetAttribute: 'addresses',
|
||||||
|
target: 'application::category.category',
|
||||||
|
type: 'relation',
|
||||||
|
})
|
||||||
|
);
|
||||||
|
const action = {
|
||||||
|
type: actions.ON_CHANGE_RELATION_TARGET,
|
||||||
|
target: {
|
||||||
|
value: 'application::country.country',
|
||||||
|
oneThatIsCreatingARelationWithAnother: 'address',
|
||||||
|
selectedContentTypeFriendlyName: 'country',
|
||||||
|
targetContentTypeAllowedRelations: ['oneWay'],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
const expected = state
|
||||||
|
.setIn(['modifiedData', 'target'], 'application::country.country')
|
||||||
|
.setIn(['modifiedData', 'name'], 'country')
|
||||||
|
.setIn(['modifiedData', 'targetAttribute'], null)
|
||||||
|
.setIn(['modifiedData', 'relation'], 'oneToOne');
|
||||||
|
|
||||||
|
expect(reducer(state, action)).toEqual(expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Should handle the target change correctly if the target has restricted relations and the relation type is correct', () => {
|
||||||
|
const state = initialState.setIn(
|
||||||
|
['modifiedData'],
|
||||||
|
fromJS({
|
||||||
|
name: 'categories',
|
||||||
|
relation: 'oneToMany',
|
||||||
|
targetAttribute: null,
|
||||||
|
target: 'application::category.category',
|
||||||
|
type: 'relation',
|
||||||
|
})
|
||||||
|
);
|
||||||
|
const action = {
|
||||||
|
type: actions.ON_CHANGE_RELATION_TARGET,
|
||||||
|
target: {
|
||||||
|
value: 'application::country.country',
|
||||||
|
oneThatIsCreatingARelationWithAnother: 'address',
|
||||||
|
selectedContentTypeFriendlyName: 'country',
|
||||||
|
targetContentTypeAllowedRelations: ['oneWay', 'manyWay'],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
const expected = state
|
||||||
|
.setIn(['modifiedData', 'target'], 'application::country.country')
|
||||||
|
.setIn(['modifiedData', 'name'], 'countries')
|
||||||
|
.setIn(['modifiedData', 'targetAttribute'], null);
|
||||||
|
|
||||||
|
expect(reducer(state, action)).toEqual(expected);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('ON_CHANGE_RELATION_TYPE', () => {
|
||||||
|
it('Should handle the relation type change correctly from oneWay to manyToMany', () => {
|
||||||
|
const state = initialState.setIn(
|
||||||
|
['modifiedData'],
|
||||||
|
fromJS({
|
||||||
|
name: 'category test',
|
||||||
|
relation: 'oneToOne',
|
||||||
|
targetAttribute: null,
|
||||||
|
target: 'application::category.category',
|
||||||
|
type: 'relation',
|
||||||
|
})
|
||||||
|
);
|
||||||
|
const action = {
|
||||||
|
type: actions.ON_CHANGE_RELATION_TYPE,
|
||||||
|
target: {
|
||||||
|
value: 'manyToMany',
|
||||||
|
|
||||||
|
oneThatIsCreatingARelationWithAnother: 'address',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
const expected = state
|
||||||
|
.setIn(['modifiedData', 'relation'], 'manyToMany')
|
||||||
|
.setIn(['modifiedData', 'name'], 'category_tests')
|
||||||
|
.setIn(['modifiedData', 'targetAttribute'], 'addresses');
|
||||||
|
|
||||||
|
expect(reducer(state, action)).toEqual(expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Should handle the relation type change correctly from manyToMany to oneWay', () => {
|
||||||
|
const state = initialState.setIn(
|
||||||
|
['modifiedData'],
|
||||||
|
fromJS({
|
||||||
|
name: 'category_tests',
|
||||||
|
relation: 'manyToMany',
|
||||||
|
targetAttribute: 'addresses',
|
||||||
|
target: 'application::category.category',
|
||||||
|
type: 'relation',
|
||||||
|
})
|
||||||
|
);
|
||||||
|
const action = {
|
||||||
|
type: actions.ON_CHANGE_RELATION_TYPE,
|
||||||
|
target: {
|
||||||
|
value: 'oneWay',
|
||||||
|
oneThatIsCreatingARelationWithAnother: 'address',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const expected = state
|
||||||
|
.setIn(['modifiedData', 'relation'], 'oneToOne')
|
||||||
|
.setIn(['modifiedData', 'name'], 'category_test')
|
||||||
|
.setIn(['modifiedData', 'targetAttribute'], null);
|
||||||
|
|
||||||
|
expect(reducer(state, action)).toEqual(expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Should handle the relation type change correctly from oneToOne to oneToMany', () => {
|
||||||
|
const state = initialState.setIn(
|
||||||
|
['modifiedData'],
|
||||||
|
fromJS({
|
||||||
|
name: 'category_test',
|
||||||
|
relation: 'oneToOne',
|
||||||
|
targetAttribute: 'address',
|
||||||
|
target: 'application::category.category',
|
||||||
|
type: 'relation',
|
||||||
|
})
|
||||||
|
);
|
||||||
|
const action = {
|
||||||
|
type: actions.ON_CHANGE_RELATION_TYPE,
|
||||||
|
target: {
|
||||||
|
value: 'oneToMany',
|
||||||
|
oneThatIsCreatingARelationWithAnother: 'address',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
const expected = state
|
||||||
|
.setIn(['modifiedData', 'relation'], 'oneToMany')
|
||||||
|
.setIn(['modifiedData', 'name'], 'category_tests');
|
||||||
|
|
||||||
|
expect(reducer(state, action)).toEqual(expected);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('RESET_PROPS', () => {
|
describe('RESET_PROPS', () => {
|
||||||
it('Should return the initialState', () => {
|
it('Should return the initialState', () => {
|
||||||
const state = initialState.setIn(['modifiedData'], 'test');
|
const state = initialState.setIn(['modifiedData'], 'test');
|
||||||
@ -691,20 +677,17 @@ describe('CTB | components | FormModal | reducer | actions', () => {
|
|||||||
nameToSetForRelation: 'address test',
|
nameToSetForRelation: 'address test',
|
||||||
targetUid: 'application::address.address',
|
targetUid: 'application::address.address',
|
||||||
isEditing: false,
|
isEditing: false,
|
||||||
modifiedDataToSetForEditing: { name: null, targetAttribute: '-' },
|
modifiedDataToSetForEditing: { name: null },
|
||||||
step: null,
|
step: null,
|
||||||
};
|
};
|
||||||
const expected = initialState.set(
|
const expected = initialState.set(
|
||||||
'modifiedData',
|
'modifiedData',
|
||||||
fromJS({
|
fromJS({
|
||||||
name: 'address_test',
|
name: 'address_test',
|
||||||
nature: 'oneWay',
|
relation: 'oneToOne',
|
||||||
targetAttribute: '-',
|
targetAttribute: null,
|
||||||
target: 'application::address.address',
|
target: 'application::address.address',
|
||||||
unique: false,
|
type: 'relation',
|
||||||
dominant: null,
|
|
||||||
columnName: null,
|
|
||||||
targetColumnName: null,
|
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,24 @@
|
|||||||
|
import getRelationType from '../getRelationType';
|
||||||
|
|
||||||
|
describe('CTB | utils | getRelationType', () => {
|
||||||
|
it('Should return oneWay', () => {
|
||||||
|
const relation = 'oneToOne';
|
||||||
|
|
||||||
|
expect(getRelationType(relation, null)).toEqual('oneWay');
|
||||||
|
expect(getRelationType(relation, undefined)).toEqual('oneWay');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Should return manyWay', () => {
|
||||||
|
const relation = 'oneToMany';
|
||||||
|
|
||||||
|
expect(getRelationType(relation, null)).toEqual('manyWay');
|
||||||
|
expect(getRelationType(relation, undefined)).toEqual('manyWay');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Should return the relation when the target attribute is defined', () => {
|
||||||
|
const relation = 'test';
|
||||||
|
|
||||||
|
expect(getRelationType(relation, 'test')).toEqual('test');
|
||||||
|
expect(getRelationType(relation, 'test')).toEqual('test');
|
||||||
|
});
|
||||||
|
});
|
||||||
Loading…
x
Reference in New Issue
Block a user