feat(engine): Added getPageId action method test.

This commit is contained in:
Sandile 2022-02-15 16:21:04 +02:00
parent 5802217d3c
commit 602e114040

View File

@ -0,0 +1,100 @@
/*
Copyright 2020-2021 Lowdefy, Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import testContext from '../../test/testContext.js';
const lowdefy = {
_internal: {
actions: {
Action: ({ methods: { getPageId }, params }) => {
return getPageId(params);
},
},
blockComponents: {
Button: { meta: { category: 'display' } },
},
},
};
const RealDate = Date;
const mockDate = jest.fn(() => ({ date: 0 }));
mockDate.now = jest.fn(() => 0);
// Comment out to use console
console.log = () => {};
console.error = () => {};
beforeEach(() => {
global.Date = mockDate;
});
afterAll(() => {
global.Date = RealDate;
});
test('getPageId no params', async () => {
const rootBlock = {
blockId: 'root',
meta: {
category: 'container',
},
areas: {
content: {
blocks: [
{
id: 'button',
blockId: 'button',
type: 'Button',
meta: {
category: 'display',
valueType: 'string',
},
events: {
onClick: [
{
id: 'a',
type: 'Action',
},
],
},
},
],
},
},
};
const context = await testContext({
lowdefy,
rootBlock,
});
const button = context._internal.RootBlocks.map['button'];
const res = await button.triggerEvent({ name: 'onClick' });
expect(res).toEqual({
blockId: 'button',
bounced: false,
endTimestamp: { date: 0 },
event: undefined,
eventName: 'onClick',
responses: {
a: {
response: 'root',
index: 0,
type: 'Action',
},
},
startTimestamp: { date: 0 },
success: true,
});
});