-
-
Notifications
You must be signed in to change notification settings - Fork 554
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
060bdac
commit abf6421
Showing
10 changed files
with
636 additions
and
557 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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({ | ||
|
@@ -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); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.