2018-07-03 09:37:59 -04:00
|
|
|
/**
|
|
|
|
* Tests DataApiMediator
|
|
|
|
*
|
2019-08-30 09:41:33 -04:00
|
|
|
* Copyright (C) 2010-2019 R-T Specialty, LLC.
|
2018-07-03 09:37:59 -04:00
|
|
|
*
|
|
|
|
* This file is part of the Liza Data Collection Framework
|
|
|
|
*
|
|
|
|
* Liza is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const { expect } = require( 'chai' );
|
2018-07-17 11:39:08 -04:00
|
|
|
|
|
|
|
const {
|
|
|
|
client: { dapi: { DataApiMediator: Sut } },
|
|
|
|
dapi: { MissingDataError },
|
|
|
|
} = require( '../../../' );
|
2018-07-03 09:37:59 -04:00
|
|
|
|
|
|
|
|
|
|
|
describe( "DataApiMediator", () =>
|
|
|
|
{
|
|
|
|
it( "returns self on #monitor", () =>
|
|
|
|
{
|
|
|
|
const dapi_manager = createStubDapiManager();
|
|
|
|
const sut = Sut( {}, {}, {} );
|
|
|
|
|
|
|
|
expect( sut.monitor( dapi_manager ) ).to.equal( sut );
|
|
|
|
} );
|
|
|
|
|
|
|
|
|
|
|
|
describe( "updateFieldData event", () =>
|
|
|
|
{
|
|
|
|
it( "ignores unknown fields", () =>
|
|
|
|
{
|
|
|
|
const dapi_manager = createStubDapiManager();
|
|
|
|
|
|
|
|
const getQuote = () => ( {
|
|
|
|
getDataByName: () => {},
|
|
|
|
setDataByName: () => {},
|
|
|
|
} );
|
|
|
|
|
|
|
|
const ui = createStubUi( {} ); // no field groups
|
2018-07-17 11:39:08 -04:00
|
|
|
const sut = Sut( ui, {}, {}, getQuote ).monitor( dapi_manager );
|
2018-07-03 09:37:59 -04:00
|
|
|
|
|
|
|
dapi_manager.emit( 'updateFieldData', '', 0, {}, {} );
|
|
|
|
} );
|
|
|
|
|
|
|
|
[
|
|
|
|
{
|
|
|
|
label: "keeps existing value if in result set (first index)",
|
|
|
|
name: 'foo',
|
|
|
|
index: 0,
|
2018-07-17 15:28:01 -04:00
|
|
|
value: { foo: [ "first", "second" ] },
|
2018-07-17 11:39:08 -04:00
|
|
|
expected: {
|
|
|
|
foo: [ "first" ],
|
|
|
|
dest1: [ "src1data" ],
|
|
|
|
dest2: [ "src2data" ],
|
|
|
|
},
|
2018-07-03 09:37:59 -04:00
|
|
|
|
|
|
|
val_label: [
|
|
|
|
{ value: "first result", label: "first" },
|
|
|
|
],
|
|
|
|
|
2018-07-17 11:39:08 -04:00
|
|
|
results: {
|
|
|
|
first: { src1: "src1data", src2: "src2data" },
|
|
|
|
second: {},
|
|
|
|
},
|
|
|
|
|
|
|
|
expansion: [ {
|
|
|
|
dest1: [ "src1data" ],
|
|
|
|
dest2: [ "src2data" ],
|
|
|
|
} ],
|
2018-07-03 09:37:59 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "keeps existing value if in result set (second index)",
|
|
|
|
name: 'bar',
|
|
|
|
index: 1,
|
2018-07-17 15:28:01 -04:00
|
|
|
value: { bar: [ "first", "second" ] },
|
2018-07-17 11:39:08 -04:00
|
|
|
expected: {
|
|
|
|
bar: [ , "second" ],
|
|
|
|
dest1: [ , "src1data_2" ],
|
|
|
|
dest2: [ , "src2data_2" ],
|
|
|
|
},
|
2018-07-03 09:37:59 -04:00
|
|
|
|
|
|
|
val_label: [
|
|
|
|
{ value: "first result", label: "first" },
|
|
|
|
{ value: "second result", label: "second" },
|
|
|
|
],
|
|
|
|
|
2018-07-17 11:39:08 -04:00
|
|
|
results: {
|
|
|
|
first: {},
|
|
|
|
second: { src1: "src1data_2", src2: "src2data_2" },
|
|
|
|
},
|
|
|
|
|
|
|
|
expansion: [ , {
|
|
|
|
dest1: [ , "src1data_2" ],
|
|
|
|
dest2: [ , "src2data_2" ],
|
|
|
|
} ],
|
2018-07-03 09:37:59 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "keeps existing value if in result set (all indexes)",
|
|
|
|
name: 'bar',
|
|
|
|
index: -1,
|
2018-07-17 15:28:01 -04:00
|
|
|
value: { bar: [ "first", "second" ] },
|
2018-07-17 11:39:08 -04:00
|
|
|
expected: {
|
|
|
|
bar: [ "first", "second" ],
|
|
|
|
dest1: [ "src1data", "src1data_2" ],
|
|
|
|
dest2: [ "src2data", "src2data_2" ],
|
|
|
|
},
|
2018-07-03 09:37:59 -04:00
|
|
|
|
|
|
|
val_label: [
|
|
|
|
{ value: "first result", label: "first" },
|
|
|
|
{ value: "second result", label: "second" },
|
|
|
|
],
|
|
|
|
|
2018-07-17 11:39:08 -04:00
|
|
|
results: {
|
|
|
|
first: { src1: "src1data", src2: "src2data" },
|
|
|
|
second: { src1: "src1data_2", src2: "src2data_2" },
|
|
|
|
},
|
|
|
|
|
|
|
|
expansion: [
|
|
|
|
{
|
|
|
|
dest1: [ "src1data" ],
|
|
|
|
dest2: [ "src2data" ],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
dest1: [ , "src1data_2" ],
|
|
|
|
dest2: [ , "src2data_2" ],
|
|
|
|
},
|
|
|
|
],
|
2018-07-03 09:37:59 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
label: "uses first value of result if existing not in result set (first index)",
|
|
|
|
name: 'foo',
|
|
|
|
index: 0,
|
2018-07-17 15:28:01 -04:00
|
|
|
value: { foo: [ "does not", "exist" ] },
|
2018-07-17 11:39:08 -04:00
|
|
|
expected: {
|
|
|
|
foo: [ "first result" ],
|
|
|
|
desta: [ "src1data" ],
|
|
|
|
destb: [ "src2data" ],
|
|
|
|
},
|
2018-07-03 09:37:59 -04:00
|
|
|
|
|
|
|
val_label: [
|
|
|
|
{ value: "first result", label: "first" },
|
|
|
|
{ value: "second result", label: "second" },
|
|
|
|
],
|
|
|
|
|
2018-07-17 11:39:08 -04:00
|
|
|
results: {
|
|
|
|
first: { src1: "src1data", src2: "src2data" },
|
|
|
|
second: {},
|
|
|
|
},
|
|
|
|
|
|
|
|
expansion: [ {
|
|
|
|
desta: [ "src1data" ],
|
|
|
|
destb: [ "src2data" ],
|
|
|
|
} ],
|
2018-07-03 09:37:59 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "uses first value of result if existing not in result set (second index)",
|
|
|
|
name: 'foo',
|
|
|
|
index: 1,
|
2018-07-17 15:28:01 -04:00
|
|
|
value: { foo: [ "does not", "exist" ] },
|
2018-07-17 11:39:08 -04:00
|
|
|
expected: {
|
|
|
|
foo: [ , "first result" ],
|
|
|
|
desta: [ , "src1data" ],
|
|
|
|
destb: [ , "src2data" ],
|
|
|
|
},
|
2018-07-03 09:37:59 -04:00
|
|
|
|
|
|
|
val_label: [
|
|
|
|
{ value: "first result", label: "first" },
|
|
|
|
{ value: "second result", label: "second" },
|
|
|
|
],
|
|
|
|
|
2018-07-17 11:39:08 -04:00
|
|
|
results: {
|
|
|
|
first: { src1: "src1data", src2: "src2data" },
|
|
|
|
second: {},
|
|
|
|
},
|
|
|
|
|
|
|
|
expansion: [ , {
|
|
|
|
desta: [ , "src1data" ],
|
|
|
|
destb: [ , "src2data" ],
|
|
|
|
} ],
|
2018-07-03 09:37:59 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "uses first value of result if existing not in result set (all indexes)",
|
|
|
|
name: 'foo',
|
|
|
|
index: -1,
|
2018-07-17 15:28:01 -04:00
|
|
|
value: { foo: [ "does not", "exist" ] },
|
2018-07-17 11:39:08 -04:00
|
|
|
expected: {
|
|
|
|
foo: [ "first result", "first result" ],
|
|
|
|
desta: [ "src1data", "src1data" ],
|
|
|
|
destb: [ "src1data", "src2data" ],
|
|
|
|
},
|
2018-07-03 09:37:59 -04:00
|
|
|
|
|
|
|
val_label: [
|
|
|
|
{ value: "first result", label: "first" },
|
|
|
|
{ value: "second result", label: "second" },
|
|
|
|
],
|
|
|
|
|
2018-07-17 11:39:08 -04:00
|
|
|
results: {
|
|
|
|
first: { src1: "src1data", src2: "src2data" },
|
|
|
|
second: {},
|
|
|
|
},
|
|
|
|
|
|
|
|
expansion: [
|
|
|
|
{
|
|
|
|
desta: [ "src1data" ],
|
|
|
|
destb: [ "src1data" ],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desta: [ , "src1data" ],
|
|
|
|
destb: [ , "src2data" ],
|
|
|
|
},
|
|
|
|
],
|
2018-07-03 09:37:59 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
label: "uses empty string if empty result set (first index)",
|
|
|
|
name: 'foo',
|
|
|
|
index: 0,
|
2018-07-17 15:28:01 -04:00
|
|
|
value: { foo: [ "foo" ] },
|
2018-07-17 11:39:08 -04:00
|
|
|
expected: {
|
|
|
|
foo: [ "" ],
|
|
|
|
dest1: [ "" ],
|
|
|
|
},
|
2018-07-03 09:37:59 -04:00
|
|
|
|
|
|
|
val_label: [],
|
|
|
|
results: {},
|
2018-07-17 11:39:08 -04:00
|
|
|
expansion: [ {
|
|
|
|
dest1: [ "" ],
|
|
|
|
} ],
|
2018-07-03 09:37:59 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "uses empty string if empty result set (second index)",
|
|
|
|
name: 'foo',
|
|
|
|
index: 1,
|
2018-07-17 15:28:01 -04:00
|
|
|
value: { foo: [ "foo", "bar" ] },
|
2018-07-17 11:39:08 -04:00
|
|
|
expected: {
|
|
|
|
foo: [ , "" ],
|
|
|
|
dest1: [ , "" ],
|
|
|
|
},
|
2018-07-03 09:37:59 -04:00
|
|
|
|
|
|
|
val_label: [],
|
|
|
|
results: {},
|
2018-07-17 11:39:08 -04:00
|
|
|
expansion: [ , {
|
|
|
|
dest1: [ , "" ],
|
|
|
|
} ],
|
2018-07-03 09:37:59 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "uses empty string if empty result set (all indexes)",
|
|
|
|
name: 'foo',
|
|
|
|
index: -1,
|
2018-07-17 15:28:01 -04:00
|
|
|
value: { foo: [ "foo", "bar" ] },
|
2018-07-17 11:39:08 -04:00
|
|
|
expected: {
|
|
|
|
foo: [ "", "" ],
|
|
|
|
dest1: [ "", "" ],
|
|
|
|
dest2: [ "", "" ],
|
|
|
|
},
|
2018-07-03 09:37:59 -04:00
|
|
|
|
|
|
|
val_label: [],
|
|
|
|
results: {},
|
2018-07-17 11:39:08 -04:00
|
|
|
expansion: [
|
|
|
|
{
|
|
|
|
dest1: [ "" ],
|
|
|
|
dest2: [ "" ],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
dest1: [ , "" ],
|
|
|
|
dest2: [ , "" ],
|
|
|
|
},
|
|
|
|
],
|
2018-07-03 09:37:59 -04:00
|
|
|
},
|
2018-07-17 15:28:01 -04:00
|
|
|
|
|
|
|
{
|
|
|
|
label: "does not auto-expand into non-empty fields",
|
|
|
|
name: 'foo',
|
|
|
|
index: 0,
|
|
|
|
value: {
|
|
|
|
foo: [ "first", "second" ],
|
2018-12-17 13:25:51 -05:00
|
|
|
label: [ "populated label" ], // exception to the rule
|
2018-07-17 15:28:01 -04:00
|
|
|
dest1: [ "leave alone" ],
|
|
|
|
dest2: [ "" ],
|
|
|
|
},
|
|
|
|
expected: {
|
|
|
|
foo: [ "first" ],
|
2018-12-17 13:25:51 -05:00
|
|
|
|
|
|
|
// labels should _always_ be populated, since they're
|
|
|
|
// considered to be part of the actual value, not a
|
|
|
|
// user-modifiable destination field
|
|
|
|
label: [ "first label" ],
|
|
|
|
|
2018-07-17 15:28:01 -04:00
|
|
|
// dest1 missing because it is already populated
|
|
|
|
dest2: [ "src2data" ],
|
|
|
|
},
|
|
|
|
|
|
|
|
val_label: [
|
2018-12-17 13:25:51 -05:00
|
|
|
{
|
|
|
|
value: "first result",
|
|
|
|
label: "first label",
|
|
|
|
label_id: 'label',
|
|
|
|
},
|
2018-07-17 15:28:01 -04:00
|
|
|
],
|
|
|
|
|
|
|
|
results: {
|
|
|
|
first: { src1: "src1data", src2: "src2data" },
|
|
|
|
second: {},
|
|
|
|
},
|
|
|
|
|
|
|
|
expansion: [ {
|
|
|
|
dest1: [ "src1data" ],
|
|
|
|
dest2: [ "src2data" ],
|
2018-12-17 13:25:51 -05:00
|
|
|
label: [ "first label" ],
|
2018-07-17 15:28:01 -04:00
|
|
|
} ],
|
|
|
|
}
|
2018-07-17 11:39:08 -04:00
|
|
|
].forEach( ( {
|
|
|
|
label, name, index, value, expected, val_label, results, expansion
|
|
|
|
} ) =>
|
2018-07-03 09:37:59 -04:00
|
|
|
{
|
|
|
|
it( label, done =>
|
|
|
|
{
|
2018-08-10 13:30:39 -04:00
|
|
|
let set_options = false;
|
|
|
|
let stack_cleared = false;
|
2018-07-03 09:37:59 -04:00
|
|
|
|
2018-07-17 11:39:08 -04:00
|
|
|
const quote = {
|
2018-07-03 09:37:59 -04:00
|
|
|
getDataByName( given_name )
|
|
|
|
{
|
2018-07-17 15:28:01 -04:00
|
|
|
return value[ given_name ];
|
2018-07-03 09:37:59 -04:00
|
|
|
},
|
|
|
|
|
2018-07-06 11:57:10 -04:00
|
|
|
setData( given_data )
|
2018-07-03 09:37:59 -04:00
|
|
|
{
|
2018-08-10 13:30:39 -04:00
|
|
|
// we should have allowed the stack to clear first
|
|
|
|
expect( stack_cleared ).to.be.true;
|
|
|
|
|
2018-07-03 09:37:59 -04:00
|
|
|
expect( given_data ).to.deep.equal( expected );
|
|
|
|
|
|
|
|
// should have called setOptions by now
|
|
|
|
expect( set_options ).to.be.true;
|
|
|
|
|
|
|
|
done();
|
|
|
|
},
|
2018-07-17 11:39:08 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
const getQuote = () => quote;
|
2018-07-03 09:37:59 -04:00
|
|
|
|
2018-07-17 11:39:08 -04:00
|
|
|
const dapi_manager = createStubDapiManager( expansion );
|
|
|
|
|
|
|
|
// this isn't a valid map, but comparing the objects will
|
|
|
|
// ensure that the map is actually used
|
|
|
|
const dapimap = { foo: {}, bar: {} };
|
|
|
|
|
|
|
|
dapi_manager.getDataExpansion = (
|
|
|
|
given_name, given_index, given_quote, given_map,
|
|
|
|
predictive, diff
|
|
|
|
) =>
|
|
|
|
{
|
|
|
|
expect( given_name ).to.equal( name );
|
|
|
|
expect( given_quote ).to.equal( quote );
|
|
|
|
expect( given_map ).to.deep.equal( dapimap );
|
|
|
|
expect( predictive ).to.be.false;
|
|
|
|
expect( diff ).to.deep.equal( {} );
|
|
|
|
|
|
|
|
return expansion[ given_index ];
|
|
|
|
};
|
2018-07-03 09:37:59 -04:00
|
|
|
|
|
|
|
const field_groups = {
|
|
|
|
[name]: {
|
|
|
|
setOptions( given_name, given_index, given_data, given_cur )
|
|
|
|
{
|
2018-08-10 15:25:29 -04:00
|
|
|
expect( stack_cleared ).to.be.true;
|
|
|
|
|
2018-07-03 09:37:59 -04:00
|
|
|
// index is implicitly tested by the given_cur line
|
|
|
|
expect( given_name ).to.equal( name );
|
|
|
|
expect( given_data ).to.deep.equal( val_label );
|
2018-07-17 15:28:01 -04:00
|
|
|
expect( given_cur ).to.equal( value[ given_name ][ given_index ] );
|
2018-07-03 09:37:59 -04:00
|
|
|
|
|
|
|
set_options = true;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2018-07-17 11:39:08 -04:00
|
|
|
const ui = createStubUi( field_groups );
|
|
|
|
|
|
|
|
const sut = Sut( ui, {}, { [name]: dapimap }, getQuote )
|
|
|
|
.monitor( dapi_manager );
|
2018-07-03 09:37:59 -04:00
|
|
|
|
|
|
|
dapi_manager.emit(
|
|
|
|
'updateFieldData', name, index, val_label, results
|
|
|
|
);
|
2018-08-10 13:30:39 -04:00
|
|
|
|
|
|
|
// #setData should be triggered after the stack clears to
|
|
|
|
// #mitigate issues with hooks causing too much / infinite
|
|
|
|
// #recursion on the bucket on the same stack
|
|
|
|
stack_cleared = true;
|
2018-07-03 09:37:59 -04:00
|
|
|
} );
|
|
|
|
} );
|
2018-07-17 11:39:08 -04:00
|
|
|
|
|
|
|
|
|
|
|
it( 'does not perform expansion if data are not available', done =>
|
|
|
|
{
|
|
|
|
const dapi_manager = createStubDapiManager();
|
|
|
|
|
|
|
|
dapi_manager.getDataExpansion = () =>
|
|
|
|
{
|
|
|
|
throw MissingDataError(
|
|
|
|
'this should happen, but should be caught'
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const name = 'foo';
|
|
|
|
const value = 'bar';
|
|
|
|
|
|
|
|
const getQuote = () => ( {
|
|
|
|
getDataByName: () => [ value ],
|
|
|
|
setData( given_data )
|
|
|
|
{
|
|
|
|
// only the value should be set with no expansion data
|
|
|
|
expect( given_data ).to.deep.equal( {
|
|
|
|
[name]: [ value ],
|
|
|
|
} );
|
|
|
|
|
|
|
|
done();
|
|
|
|
},
|
|
|
|
} );
|
|
|
|
|
|
|
|
const field_groups = { [name]: { setOptions() {} } };
|
|
|
|
|
|
|
|
const ui = createStubUi( field_groups );
|
|
|
|
const sut = Sut( ui, {}, {}, getQuote ).monitor( dapi_manager );
|
|
|
|
|
|
|
|
const val_label = [
|
|
|
|
{ value: value, label: "bar" },
|
|
|
|
];
|
|
|
|
|
|
|
|
dapi_manager.emit( 'updateFieldData', name, 0, val_label, {} );
|
|
|
|
} );
|
2018-07-03 09:37:59 -04:00
|
|
|
} );
|
|
|
|
|
|
|
|
|
|
|
|
describe( "on clearFieldData event", () =>
|
|
|
|
{
|
|
|
|
it( "ignores unknown fields", () =>
|
|
|
|
{
|
|
|
|
const dapi_manager = createStubDapiManager();
|
|
|
|
|
|
|
|
const field_groups = {}; // no groups
|
|
|
|
|
|
|
|
const ui = createStubUi( field_groups );
|
2018-07-17 11:39:08 -04:00
|
|
|
const sut = Sut( ui, {}, {} ).monitor( dapi_manager );
|
2018-07-03 09:37:59 -04:00
|
|
|
|
|
|
|
dapi_manager.emit( 'clearFieldData', 'unknown', 0 );
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( "clears field", done =>
|
|
|
|
{
|
|
|
|
const dapi_manager = createStubDapiManager();
|
|
|
|
|
|
|
|
const name = 'foo';
|
|
|
|
const index = 3;
|
|
|
|
|
|
|
|
const field_groups = {
|
|
|
|
[name]: {
|
|
|
|
clearOptions( given_name, given_index )
|
|
|
|
{
|
|
|
|
expect( given_name ).to.equal( name );
|
|
|
|
expect( given_index ).to.equal( index );
|
|
|
|
|
|
|
|
done();
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const ui = createStubUi( field_groups );
|
2018-07-17 11:39:08 -04:00
|
|
|
const sut = Sut( ui, {}, {} ).monitor( dapi_manager );
|
2018-07-03 09:37:59 -04:00
|
|
|
|
|
|
|
dapi_manager.emit( 'clearFieldData', name, index );
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
|
|
|
|
|
|
|
describe( "on fieldLoaded event", () =>
|
|
|
|
{
|
|
|
|
it( "clears failures for field", done =>
|
|
|
|
{
|
|
|
|
const dapi_manager = createStubDapiManager();
|
|
|
|
|
|
|
|
const name = 'bar';
|
|
|
|
const index = 2;
|
|
|
|
|
|
|
|
const data_validator = {
|
|
|
|
clearFailures( data )
|
|
|
|
{
|
|
|
|
expect( data[ name ] ).to.deep.equal( [ index ] );
|
|
|
|
done();
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const ui = {}; // unused by this event
|
2018-07-17 11:39:08 -04:00
|
|
|
const sut = Sut( ui, data_validator, {} ).monitor( dapi_manager );
|
2018-07-03 09:37:59 -04:00
|
|
|
|
|
|
|
dapi_manager.emit( 'fieldLoaded', name, index );
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
|
|
|
|
|
|
|
function createStubDapiManager()
|
|
|
|
{
|
|
|
|
const callbacks = {};
|
|
|
|
|
|
|
|
return {
|
|
|
|
on( name, callback )
|
|
|
|
{
|
|
|
|
callbacks[ name ] = callback;
|
|
|
|
},
|
|
|
|
|
|
|
|
emit( name )
|
|
|
|
{
|
|
|
|
// we don't support rest yet in our version of node
|
|
|
|
const data = Array.prototype.slice.call( arguments, 1 );
|
|
|
|
|
|
|
|
callbacks[ name ].apply( null, data );
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function createStubUi( field_groups )
|
|
|
|
{
|
|
|
|
return {
|
|
|
|
getCurrentStep: () => ( {
|
|
|
|
getElementGroup: name => field_groups[ name ]
|
|
|
|
} )
|
|
|
|
};
|
|
|
|
}
|