mirror of
https://github.com/lowdefy/lowdefy.git
synced 2025-02-05 13:59:56 +08:00
feat(actions-core): Added Message action test.
This commit is contained in:
parent
b67e77d56c
commit
0404c0d326
@ -0,0 +1,75 @@
|
||||
/*
|
||||
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 './testContext.js';
|
||||
import Message from './Message.js';
|
||||
|
||||
const mockActionMethod = jest.fn();
|
||||
|
||||
const lowdefy = {
|
||||
_internal: {
|
||||
actions: {
|
||||
Message: (props) => Message({ ...props, methods: { message: mockActionMethod } }),
|
||||
},
|
||||
blockComponents: {
|
||||
Button: { meta: { category: 'display' } },
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
mockActionMethod.mockReset();
|
||||
});
|
||||
|
||||
test('Message action invocation', async () => {
|
||||
const rootBlock = {
|
||||
id: 'block:root:root:0',
|
||||
blockId: 'root',
|
||||
meta: {
|
||||
category: 'container',
|
||||
},
|
||||
areas: {
|
||||
content: {
|
||||
blocks: [
|
||||
{
|
||||
id: 'button',
|
||||
blockId: 'button',
|
||||
type: 'Button',
|
||||
meta: {
|
||||
category: 'display',
|
||||
},
|
||||
events: {
|
||||
onClick: [
|
||||
{
|
||||
id: 'action',
|
||||
type: 'Message',
|
||||
params: 'call',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
};
|
||||
const context = await testContext({
|
||||
lowdefy,
|
||||
rootBlock,
|
||||
});
|
||||
const button = context._internal.RootBlocks.map['button'];
|
||||
await button.triggerEvent({ name: 'onClick' });
|
||||
expect(mockActionMethod.mock.calls).toEqual([['call']]);
|
||||
});
|
Loading…
Reference in New Issue
Block a user