Skip to content

Commit

Permalink
fix(engine): testContext to build config and use getContext.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gervwyk committed May 27, 2022
1 parent f4c0f76 commit 4539d6f
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 38 deletions.
9 changes: 9 additions & 0 deletions packages/engine/test/testActions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { CallMethod as CallMethod } from '@lowdefy/actions-core/actions';
import { Link as Link } from '@lowdefy/actions-core/actions';
import { SetState as SetState } from '@lowdefy/actions-core/actions';

export default {
CallMethod,
Link,
SetState,
};
102 changes: 64 additions & 38 deletions packages/engine/test/testContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,56 +14,82 @@
limitations under the License.
*/

import { WebParser } from '@lowdefy/operators';
import buildTestPage from '@lowdefy/build/buildTestPage';

import Actions from '../src/Actions.js';
import Blocks from '../src/Blocks.js';
import Requests from '../src/Requests.js';
import State from '../src/State.js';
import getContext from '../src/getContext.js';
import testOperators from './testOperators.js';
import testActions from './testActions.js';

const testContext = ({ lowdefy, operators, rootBlock, initState = {} }) => {
const testContext = async ({ lowdefy, pageConfig, blocks = {} }) => {
const testLowdefy = {
contexts: {},
inputs: { test: {} },
urlQuery: {},
...lowdefy,
_internal: {
displayMessage: () => () => undefined,
displayMessage: () => () => {},
updateBlock: () => {},
...lowdefy._internal,
operators: testOperators,
actions: testActions,
blockComponents: {
TextInput: {
meta: {
category: 'input',
valueType: 'string',
},
},
Box: {
meta: {
category: 'container',
},
},
Button: {
meta: {
category: 'display',
},
},
List: {
meta: {
category: 'list',
valueType: 'array',
},
},
Paragraph: {
meta: {
category: 'display',
},
},
Switch: {
meta: {
category: 'input',
valueType: 'boolean',
},
},
MultipleSelector: {
meta: {
category: 'input',
valueType: 'array',
},
},
NumberInput: {
meta: {
category: 'input',
valueType: 'number',
},
},
...blocks,
},
},
};
const ctx = {
id: 'test',
pageId: rootBlock.blockId,
eventLog: [],
requests: {},
state: {},
_internal: {
lowdefy: testLowdefy,
rootBlock,
},
};
const _internal = ctx._internal;
_internal.parser = new WebParser({ context: ctx, contexts: {}, operators: operators || {} });
_internal.State = new State(ctx);
_internal.Actions = new Actions(ctx);
_internal.Requests = new Requests(ctx);
_internal.RootBlocks = new Blocks({
areas: _internal.rootBlock.areas,
context: ctx,
const buildConfig = buildTestPage({ pageConfig });
const ctx = getContext({
lowdefy: testLowdefy,
config: buildConfig,
resetContext: { reset: true, setReset: () => {} },
});
_internal.RootBlocks.init();
_internal.update = () => {
_internal.RootBlocks.update();
};
if (initState) {
Object.keys(initState).forEach((key) => {
_internal.State.set(key, initState[key]);
});
_internal.RootBlocks.reset();
}
_internal.update();
_internal.State.freezeState();
await ctx._internal.runOnInit(() => {});
await ctx._internal.runOnInitAsync(() => {});
return ctx;
};

Expand Down
14 changes: 14 additions & 0 deletions packages/engine/test/testOperators.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { _not as _not } from '@lowdefy/operators-js/operators/client';
import { _eq as _eq } from '@lowdefy/operators-js/operators/client';
import { _type as _type } from '@lowdefy/operators-js/operators/client';
import { _state as _state } from '@lowdefy/operators-js/operators/client';
import { _regex as _regex } from '@lowdefy/operators-js/operators/client';
import { _mql as _mql } from '@lowdefy/operators-mql/operators/client';

export default {
_eq,
_not,
_type,
_state,
_regex,
};

0 comments on commit 4539d6f

Please sign in to comment.