Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMike Gerwitz <mike.gerwitz@rtspecialty.com>2018-07-17 15:28:01 -0400
committerMike Gerwitz <mike.gerwitz@rtspecialty.com>2018-07-17 15:44:37 -0400
commitabc2564d9c864dc186a002a277e64ee6a9b3be87 (patch)
treed77eabec34f169b521056ef3a21403fbe9f03660 /test
parent839952a56d76b2236a70ec2dbc5c193ecbb72504 (diff)
downloadliza-abc2564d9c864dc186a002a277e64ee6a9b3be87.tar.gz
liza-abc2564d9c864dc186a002a277e64ee6a9b3be87.tar.bz2
liza-abc2564d9c864dc186a002a277e64ee6a9b3be87.zip
DataApiMediator: Do not auto-expand into populated fields
* src/client/dapi/DataApiMediator.js (_populateWithMap): Update docblock. Ignore field during expansion if it would overwrite an existing value. * test/client/dapi/DataApiMediatorTest.js: Update tests data to include values for all bucket fields, not just `name'. Add test for new condition. DEV-3257
Diffstat (limited to 'test')
-rw-r--r--test/client/dapi/DataApiMediatorTest.js53
1 files changed, 41 insertions, 12 deletions
diff --git a/test/client/dapi/DataApiMediatorTest.js b/test/client/dapi/DataApiMediatorTest.js
index 5272fe4..fee5f56 100644
--- a/test/client/dapi/DataApiMediatorTest.js
+++ b/test/client/dapi/DataApiMediatorTest.js
@@ -62,7 +62,7 @@ describe( "DataApiMediator", () =>
label: "keeps existing value if in result set (first index)",
name: 'foo',
index: 0,
- value: [ "first", "second" ],
+ value: { foo: [ "first", "second" ] },
expected: {
foo: [ "first" ],
dest1: [ "src1data" ],
@@ -87,7 +87,7 @@ describe( "DataApiMediator", () =>
label: "keeps existing value if in result set (second index)",
name: 'bar',
index: 1,
- value: [ "first", "second" ],
+ value: { bar: [ "first", "second" ] },
expected: {
bar: [ , "second" ],
dest1: [ , "src1data_2" ],
@@ -113,7 +113,7 @@ describe( "DataApiMediator", () =>
label: "keeps existing value if in result set (all indexes)",
name: 'bar',
index: -1,
- value: [ "first", "second" ],
+ value: { bar: [ "first", "second" ] },
expected: {
bar: [ "first", "second" ],
dest1: [ "src1data", "src1data_2" ],
@@ -146,7 +146,7 @@ describe( "DataApiMediator", () =>
label: "uses first value of result if existing not in result set (first index)",
name: 'foo',
index: 0,
- value: [ "does not", "exist" ],
+ value: { foo: [ "does not", "exist" ] },
expected: {
foo: [ "first result" ],
desta: [ "src1data" ],
@@ -172,7 +172,7 @@ describe( "DataApiMediator", () =>
label: "uses first value of result if existing not in result set (second index)",
name: 'foo',
index: 1,
- value: [ "does not", "exist" ],
+ value: { foo: [ "does not", "exist" ] },
expected: {
foo: [ , "first result" ],
desta: [ , "src1data" ],
@@ -198,7 +198,7 @@ describe( "DataApiMediator", () =>
label: "uses first value of result if existing not in result set (all indexes)",
name: 'foo',
index: -1,
- value: [ "does not", "exist" ],
+ value: { foo: [ "does not", "exist" ] },
expected: {
foo: [ "first result", "first result" ],
desta: [ "src1data", "src1data" ],
@@ -231,7 +231,7 @@ describe( "DataApiMediator", () =>
label: "uses empty string if empty result set (first index)",
name: 'foo',
index: 0,
- value: [ "foo" ],
+ value: { foo: [ "foo" ] },
expected: {
foo: [ "" ],
dest1: [ "" ],
@@ -247,7 +247,7 @@ describe( "DataApiMediator", () =>
label: "uses empty string if empty result set (second index)",
name: 'foo',
index: 1,
- value: [ "foo", "bar" ],
+ value: { foo: [ "foo", "bar" ] },
expected: {
foo: [ , "" ],
dest1: [ , "" ],
@@ -263,7 +263,7 @@ describe( "DataApiMediator", () =>
label: "uses empty string if empty result set (all indexes)",
name: 'foo',
index: -1,
- value: [ "foo", "bar" ],
+ value: { foo: [ "foo", "bar" ] },
expected: {
foo: [ "", "" ],
dest1: [ "", "" ],
@@ -283,6 +283,36 @@ describe( "DataApiMediator", () =>
},
],
},
+
+ {
+ label: "does not auto-expand into non-empty fields",
+ name: 'foo',
+ index: 0,
+ value: {
+ foo: [ "first", "second" ],
+ dest1: [ "leave alone" ],
+ dest2: [ "" ],
+ },
+ expected: {
+ foo: [ "first" ],
+ // dest1 missing because it is already populated
+ dest2: [ "src2data" ],
+ },
+
+ val_label: [
+ { value: "first result", label: "first" },
+ ],
+
+ results: {
+ first: { src1: "src1data", src2: "src2data" },
+ second: {},
+ },
+
+ expansion: [ {
+ dest1: [ "src1data" ],
+ dest2: [ "src2data" ],
+ } ],
+ }
].forEach( ( {
label, name, index, value, expected, val_label, results, expansion
} ) =>
@@ -294,8 +324,7 @@ describe( "DataApiMediator", () =>
const quote = {
getDataByName( given_name )
{
- expect( given_name ).to.equal( name );
- return value;
+ return value[ given_name ];
},
setData( given_data )
@@ -338,7 +367,7 @@ describe( "DataApiMediator", () =>
// index is implicitly tested by the given_cur line
expect( given_name ).to.equal( name );
expect( given_data ).to.deep.equal( val_label );
- expect( given_cur ).to.equal( value[ given_index ] );
+ expect( given_cur ).to.equal( value[ given_name ][ given_index ] );
set_options = true;
},