Skip to content

Commit

Permalink
npm run prettier:format
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonvarga committed Feb 7, 2025
1 parent 0652539 commit 6fc1765
Show file tree
Hide file tree
Showing 9 changed files with 635 additions and 556 deletions.
84 changes: 48 additions & 36 deletions resources/js/tests/FieldConditionsConverter.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Converter from '../components/field-conditions/Converter.js';
global._ = require('underscore');

const FieldConditionsConverter = new Converter;
const FieldConditionsConverter = new Converter();

test('it converts from blueprint format', () => {
let converted = FieldConditionsConverter.fromBlueprint({
Expand All @@ -11,95 +11,107 @@ test('it converts from blueprint format', () => {
});

let expected = [
{field: 'name', operator: 'not', value: 'joe'},
{field: 'age', operator: 'equals', value: '13'},
{field: 'email', operator: 'equals', value: '[email protected]'}
{ field: 'name', operator: 'not', value: 'joe' },
{ field: 'age', operator: 'equals', value: '13' },
{ field: 'email', operator: 'equals', value: '[email protected]' },
];

expect(converted).toEqual(expected);
});

test('it converts from blueprint format and applies prefixes', () => {
let converted = FieldConditionsConverter.fromBlueprint({
name: 'isnt joe',
age: 13,
email: 'equals [email protected]',
}, 'nested_');
let converted = FieldConditionsConverter.fromBlueprint(
{
name: 'isnt joe',
age: 13,
email: 'equals [email protected]',
},
'nested_',
);

let expected = [
{field: 'nested_name', operator: 'not', value: 'joe'},
{field: 'nested_age', operator: 'equals', value: '13'},
{field: 'nested_email', operator: 'equals', value: '[email protected]'}
{ field: 'nested_name', operator: 'not', value: 'joe' },
{ field: 'nested_age', operator: 'equals', value: '13' },
{ field: 'nested_email', operator: 'equals', value: '[email protected]' },
];

expect(converted).toEqual(expected);
});

test('it converts from blueprint format and does not apply prefix to field conditions with root syntax', () => {
let converted = FieldConditionsConverter.fromBlueprint({
'name': 'isnt joe',
'$root.title': 'not empty',
}, 'nested_');
let converted = FieldConditionsConverter.fromBlueprint(
{
name: 'isnt joe',
'$root.title': 'not empty',
},
'nested_',
);

let expected = [
{field: 'nested_name', operator: 'not', value: 'joe'},
{field: '$root.title', operator: 'not', value: 'empty'}
{ field: 'nested_name', operator: 'not', value: 'joe' },
{ field: '$root.title', operator: 'not', value: 'empty' },
];

expect(converted).toEqual(expected);
});

test('it converts from blueprint format and does not apply prefix to field conditions with legacy root syntax for backwards compatibility', () => {
let converted = FieldConditionsConverter.fromBlueprint({
'name': 'isnt joe',
'root.title': 'not empty',
}, 'nested_');
let converted = FieldConditionsConverter.fromBlueprint(
{
name: 'isnt joe',
'root.title': 'not empty',
},
'nested_',
);

let expected = [
{field: 'nested_name', operator: 'not', value: 'joe'},
{field: 'root.title', operator: 'not', value: 'empty'}
{ field: 'nested_name', operator: 'not', value: 'joe' },
{ field: 'root.title', operator: 'not', value: 'empty' },
];

expect(converted).toEqual(expected);
});

test('it converts from blueprint format and does not apply prefix to field conditions with parent syntax', () => {
let converted = FieldConditionsConverter.fromBlueprint({
'name': 'isnt joe',
'$parent.title': 'not empty',
}, 'nested_');
let converted = FieldConditionsConverter.fromBlueprint(
{
name: 'isnt joe',
'$parent.title': 'not empty',
},
'nested_',
);

let expected = [
{field: 'nested_name', operator: 'not', value: 'joe'},
{field: '$parent.title', operator: 'not', value: 'empty'}
{ field: 'nested_name', operator: 'not', value: 'joe' },
{ field: '$parent.title', operator: 'not', value: 'empty' },
];

expect(converted).toEqual(expected);
});

test('it converts to blueprint format', () => {
let converted = FieldConditionsConverter.toBlueprint([
{field: 'name', operator: 'isnt', value: 'joe'},
{field: 'age', operator: '==', value: '13'}
{ field: 'name', operator: 'isnt', value: 'joe' },
{ field: 'age', operator: '==', value: '13' },
]);

let expected = {
name: 'isnt joe',
age: '== 13'
age: '== 13',
};

expect(converted).toEqual(expected);
});

test('it converts and trims properly with empty operators', () => {
let converted = FieldConditionsConverter.toBlueprint([
{field: 'name', operator: '', value: 'joe'},
{field: 'age', operator: null, value: '13'}
{ field: 'name', operator: '', value: 'joe' },
{ field: 'age', operator: null, value: '13' },
]);

let expected = {
name: 'joe',
age: '13'
age: '13',
};

expect(converted).toEqual(expected);
Expand Down
30 changes: 22 additions & 8 deletions resources/js/tests/FieldConditionsParentResolver.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import ParentResolver from '../components/field-conditions/ParentResolver.js';

let resolve = function (currentFieldPath, pathWithParent) {
return new ParentResolver(currentFieldPath).resolve(pathWithParent);
}
};

test('it resolves from group to top level', () => {
expect(resolve('group.field', '$parent.name')).toEqual('$root.name');
Expand Down Expand Up @@ -58,11 +58,25 @@ test('it resolves from deeply nested mix of everything all the way up to top lev
let fromField = 'group.replicator.1.group.bard.4.grid.0.group.group.replicator.6.field';

expect(resolve(fromField, '$parent.name')).toEqual('$root.group.replicator.1.group.bard.4.grid.0.group.group.name');
expect(resolve(fromField, '$parent.$parent.name')).toEqual('$root.group.replicator.1.group.bard.4.grid.0.group.name');
expect(resolve(fromField, '$parent.$parent.$parent.name')).toEqual('$root.group.replicator.1.group.bard.4.grid.0.name');
expect(resolve(fromField, '$parent.$parent.$parent.$parent.name')).toEqual('$root.group.replicator.1.group.bard.4.name');
expect(resolve(fromField, '$parent.$parent.$parent.$parent.$parent.name')).toEqual('$root.group.replicator.1.group.name');
expect(resolve(fromField, '$parent.$parent.$parent.$parent.$parent.$parent.name')).toEqual('$root.group.replicator.1.name');
expect(resolve(fromField, '$parent.$parent.$parent.$parent.$parent.$parent.$parent.name')).toEqual('$root.group.name');
expect(resolve(fromField, '$parent.$parent.$parent.$parent.$parent.$parent.$parent.$parent.name')).toEqual('$root.name');
expect(resolve(fromField, '$parent.$parent.name')).toEqual(
'$root.group.replicator.1.group.bard.4.grid.0.group.name',
);
expect(resolve(fromField, '$parent.$parent.$parent.name')).toEqual(
'$root.group.replicator.1.group.bard.4.grid.0.name',
);
expect(resolve(fromField, '$parent.$parent.$parent.$parent.name')).toEqual(
'$root.group.replicator.1.group.bard.4.name',
);
expect(resolve(fromField, '$parent.$parent.$parent.$parent.$parent.name')).toEqual(
'$root.group.replicator.1.group.name',
);
expect(resolve(fromField, '$parent.$parent.$parent.$parent.$parent.$parent.name')).toEqual(
'$root.group.replicator.1.name',
);
expect(resolve(fromField, '$parent.$parent.$parent.$parent.$parent.$parent.$parent.name')).toEqual(
'$root.group.name',
);
expect(resolve(fromField, '$parent.$parent.$parent.$parent.$parent.$parent.$parent.$parent.name')).toEqual(
'$root.name',
);
});
Loading

0 comments on commit 6fc1765

Please sign in to comment.