-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #351 from kendraio/develop
Production release with comparison block and service worker flag
- Loading branch information
Showing
19 changed files
with
1,117 additions
and
291 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
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 |
---|---|---|
@@ -0,0 +1,205 @@ | ||
import { loadFlowCode } from '../support/helper'; | ||
// tslint:disable: quotemark | ||
/// <reference types="Cypress" /> | ||
|
||
describe('Comparison Block Capabilities', () => { | ||
|
||
// Working default | ||
it('has a default result', () => { | ||
loadFlowCode([ | ||
{ | ||
"type": "mapping", | ||
"mapping": "{source:`one`, one:`one`, two:`two` }" | ||
}, | ||
{ | ||
"type":"comparison", | ||
"valueGetter":'data.source', | ||
"default":'default' | ||
}, | ||
{ | ||
"type":'debug' | ||
} | ||
]); | ||
cy.contains('default'); | ||
|
||
}); | ||
|
||
// basic matching | ||
|
||
it('returns a value for a matching comparison', () =>{ | ||
loadFlowCode([ | ||
{ | ||
"type": "mapping", | ||
"mapping": "{ source:`one`, one:`one`, two:`two` }" | ||
}, | ||
{ | ||
"type":"comparison", | ||
"valueGetter":'data.source', | ||
"default":'default', | ||
"comparisons": [ | ||
{ | ||
operator:'==', | ||
target:'one', | ||
output:'one' | ||
} | ||
] | ||
}, | ||
{ | ||
"type":'debug' | ||
} | ||
]); | ||
cy.contains('one'); | ||
}); | ||
|
||
|
||
|
||
|
||
// value and jmespath targets | ||
|
||
it('returns a jmespath value for a matching comparison', () =>{ | ||
loadFlowCode([ | ||
{ | ||
"type": "mapping", | ||
"mapping": "{ source:`one`, one:`one`, two:`two`, path:`one` }" | ||
}, | ||
{ | ||
"type":"comparison", | ||
"valueGetter":'data.source', | ||
"default":'default', | ||
"comparisons": [ | ||
{ | ||
operator:'==', | ||
target:'data.path', | ||
targetType:'jmespath', | ||
output:'path' | ||
} | ||
] | ||
}, | ||
{ | ||
"type":'debug' | ||
} | ||
]); | ||
cy.contains('path'); | ||
}); | ||
|
||
|
||
// multiple comparisons | ||
|
||
it('keeps processing comparisons until it finds a matching comparison', () =>{ | ||
loadFlowCode([ | ||
{ | ||
"type": "mapping", | ||
"mapping": "{ source:`two`, one:`one`, two:`two` }" | ||
}, | ||
{ | ||
"type":"comparison", | ||
"valueGetter":'data.source', | ||
"default":'default', | ||
"comparisons": [ | ||
{ | ||
operator:'==', | ||
target:'one', | ||
output:'first' | ||
}, | ||
{ | ||
operator:'==', | ||
target:'two', | ||
output:'second' | ||
} | ||
] | ||
}, | ||
{ | ||
"type":'debug' | ||
} | ||
]); | ||
cy.contains('second'); | ||
}); | ||
|
||
|
||
// invalid comparison definitions | ||
|
||
it('ignores badly formed comparisons', () =>{ | ||
loadFlowCode([ | ||
{ | ||
"type": "mapping", | ||
"mapping": "{ source:`two`, one:`one`, two:`two` }" | ||
}, | ||
{ | ||
"type":"comparison", | ||
"valueGetter":'data.source', | ||
"default":'default', | ||
"comparisons": [ | ||
{ | ||
operator:'==', | ||
target:'', | ||
output:'first' | ||
}, | ||
{ | ||
operator:'==', | ||
target:'two', | ||
output:'second' | ||
} | ||
] | ||
}, | ||
{ | ||
"type":'debug' | ||
} | ||
]); | ||
cy.contains('second'); | ||
}); | ||
|
||
// nothing there | ||
|
||
it('can cope with a non-existent source value', () =>{ | ||
loadFlowCode([ | ||
{ | ||
"type": "mapping", | ||
"mapping": "{ source:`two`, one:`one`, two:`two` }" | ||
}, | ||
{ | ||
"type":"comparison", | ||
"valueGetter":'data.null', | ||
"default":'default', | ||
"comparisons": [ | ||
{ | ||
operator:'null', | ||
output:'null' | ||
} | ||
] | ||
}, | ||
{ | ||
"type":'debug' | ||
} | ||
]); | ||
cy.contains('null'); | ||
}); | ||
|
||
it('allows jmespath default values', () =>{ | ||
loadFlowCode([ | ||
{ | ||
"type": "mapping", | ||
"mapping": "{ source:`two`, one:`first`, two:`second` }" | ||
}, | ||
{ | ||
"type": "comparison", | ||
"valueGetter": "data.source", | ||
"default": "data.two", | ||
"defaultType": "jmespath", | ||
"comparisons": [ | ||
{ | ||
"operator": "typeof", | ||
"target": "array", | ||
"targetType": "value", | ||
"output": "one", | ||
"outputType": "value" | ||
} | ||
] | ||
}, | ||
{ | ||
"type":'debug' | ||
} | ||
]); | ||
cy.contains('second'); | ||
}); | ||
|
||
}); |
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 |
---|---|---|
@@ -0,0 +1,79 @@ | ||
Comparison | ||
========== | ||
|
||
Perform a simple operation, comparing a source value with a set of target values. | ||
|
||
The comparison block works through each of a set of operations, and when | ||
it finds a successful match, returns the specified output. | ||
|
||
Once a match is found, processing stops. If no match is found, a default is returned. | ||
|
||
The output of the block will replace "data". | ||
|
||
Configuration | ||
------------- | ||
|
||
The comparison block is configured by a custom form. | ||
|
||
(General) Value Types | ||
++++++++++++++++++++++ | ||
|
||
The comparison block assumes that target, output and default values are strings by default. | ||
However, it is possible to specify that these are JMESPath values, which means that | ||
they will be passed through the mapper to retrieve data, or perform additional operations. | ||
|
||
Block Setup | ||
+++++++++++ | ||
|
||
Source | ||
^^^^^^ | ||
|
||
The source that we will be comparing against. This is a JMESpath expression. | ||
|
||
Default | ||
^^^^^^^ | ||
|
||
If no match is set, the default is returned. | ||
|
||
|
||
Comparison definitions | ||
++++++++++++++++++++++ | ||
|
||
Operator | ||
^^^^^^^^ | ||
|
||
What operation should be performed. '==', '>','<' etc. | ||
Some operators require a target, to be compared with, others simply work on the source. | ||
|
||
Target | ||
^^^^^^ | ||
If the operator requires a second value to compare with, a target needs to be specified. | ||
|
||
|
||
Output | ||
^^^^^^ | ||
On a successful match, the output for the comparison is returned. | ||
|
||
|
||
|
||
Default config | ||
-------------- | ||
Under the hood, this is the default block config JSON. | ||
|
||
.. code-block:: json | ||
{ | ||
type: 'comparison', | ||
valueGetter: 'data', | ||
default: 'NO', | ||
defaultType: 'value', | ||
comparisons: [ | ||
{ | ||
operator: '==', | ||
target:'OK', | ||
targetType:'value', | ||
output:'YES', | ||
outputType:'value' | ||
} | ||
] | ||
} |
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.