chore(actions-core): Simplify action tests.

This commit is contained in:
Sandile 2022-02-11 13:37:19 +02:00
parent 171aec380b
commit e24d40408f
11 changed files with 14 additions and 480 deletions

View File

@ -14,62 +14,15 @@
limitations under the License.
*/
import testContext from './testContext.js';
import CallMethod from './CallMethod.js';
const mockActionMethod = jest.fn();
const lowdefy = {
_internal: {
actions: {
CallMethod: (props) => CallMethod({ ...props, methods: { callMethod: mockActionMethod } }),
},
blockComponents: {
Button: { meta: { category: 'display' } },
},
},
};
beforeEach(() => {
mockActionMethod.mockReset();
});
test('CallMethod 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: 'CallMethod',
params: 'call',
},
],
},
},
],
},
},
};
const context = await testContext({
lowdefy,
rootBlock,
});
const button = context._internal.RootBlocks.map['button'];
await button.triggerEvent({ name: 'onClick' });
CallMethod({ methods: { callMethod: mockActionMethod }, params: 'call' });
expect(mockActionMethod.mock.calls).toEqual([['call']]);
});

View File

@ -14,62 +14,15 @@
limitations under the License.
*/
import testContext from './testContext.js';
import Login from './Login.js';
const mockActionMethod = jest.fn();
const lowdefy = {
_internal: {
actions: {
Login: (props) => Login({ ...props, methods: { login: mockActionMethod } }),
},
blockComponents: {
Button: { meta: { category: 'display' } },
},
},
};
beforeEach(() => {
mockActionMethod.mockReset();
});
test('Login 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: 'Login',
params: 'call',
},
],
},
},
],
},
},
};
const context = await testContext({
lowdefy,
rootBlock,
});
const button = context._internal.RootBlocks.map['button'];
await button.triggerEvent({ name: 'onClick' });
Login({ methods: { login: mockActionMethod }, params: 'call' });
expect(mockActionMethod.mock.calls).toEqual([['call']]);
});

View File

@ -14,62 +14,15 @@
limitations under the License.
*/
import testContext from './testContext.js';
import Logout from './Logout.js';
const mockActionMethod = jest.fn();
const lowdefy = {
_internal: {
actions: {
Logout: (props) => Logout({ ...props, methods: { logout: mockActionMethod } }),
},
blockComponents: {
Button: { meta: { category: 'display' } },
},
},
};
beforeEach(() => {
mockActionMethod.mockReset();
});
test('Logout 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: 'Logout',
params: 'call',
},
],
},
},
],
},
},
};
const context = await testContext({
lowdefy,
rootBlock,
});
const button = context._internal.RootBlocks.map['button'];
await button.triggerEvent({ name: 'onClick' });
Logout({ methods: { logout: mockActionMethod } });
expect(mockActionMethod.mock.calls).toEqual([[]]);
});

View File

@ -14,62 +14,15 @@
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' });
Message({ methods: { message: mockActionMethod }, params: 'call' });
expect(mockActionMethod.mock.calls).toEqual([['call']]);
});

View File

@ -14,62 +14,15 @@
limitations under the License.
*/
import testContext from './testContext.js';
import Request from './Request.js';
const mockActionMethod = jest.fn();
const lowdefy = {
_internal: {
actions: {
Request: (props) => Request({ ...props, methods: { request: mockActionMethod } }),
},
blockComponents: {
Button: { meta: { category: 'display' } },
},
},
};
beforeEach(() => {
mockActionMethod.mockReset();
});
test('Request 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: 'Request',
params: 'call',
},
],
},
},
],
},
},
};
const context = await testContext({
lowdefy,
rootBlock,
});
const button = context._internal.RootBlocks.map['button'];
await button.triggerEvent({ name: 'onClick' });
Request({ methods: { request: mockActionMethod }, params: 'call' });
expect(mockActionMethod.mock.calls).toEqual([['call']]);
});

View File

@ -14,61 +14,15 @@
limitations under the License.
*/
import testContext from './testContext.js';
import Reset from './Reset.js';
const mockActionMethod = jest.fn();
const lowdefy = {
_internal: {
actions: {
Reset: (props) => Reset({ ...props, methods: { reset: mockActionMethod } }),
},
blockComponents: {
Button: { meta: { category: 'display' } },
},
},
};
beforeEach(() => {
mockActionMethod.mockReset();
});
test('Reset 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: 'Reset',
},
],
},
},
],
},
},
};
const context = await testContext({
lowdefy,
rootBlock,
});
const button = context._internal.RootBlocks.map['button'];
await button.triggerEvent({ name: 'onClick' });
Reset({ methods: { reset: mockActionMethod } });
expect(mockActionMethod.mock.calls).toEqual([[]]);
});

View File

@ -14,63 +14,15 @@
limitations under the License.
*/
import testContext from './testContext.js';
import ResetValidation from './ResetValidation.js';
const mockActionMethod = jest.fn();
const lowdefy = {
_internal: {
actions: {
ResetValidation: (props) =>
ResetValidation({ ...props, methods: { resetValidation: mockActionMethod } }),
},
blockComponents: {
Button: { meta: { category: 'display' } },
},
},
};
beforeEach(() => {
mockActionMethod.mockReset();
});
test('ResetValidation 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: 'ResetValidation',
params: 'call',
},
],
},
},
],
},
},
};
const context = await testContext({
lowdefy,
rootBlock,
});
const button = context._internal.RootBlocks.map['button'];
await button.triggerEvent({ name: 'onClick' });
ResetValidation({ methods: { resetValidation: mockActionMethod }, params: 'call' });
expect(mockActionMethod.mock.calls).toEqual([['call']]);
});

View File

@ -51,6 +51,10 @@ const lowdefy = {
},
};
// Comment out to use console
console.log = () => {};
console.error = () => {};
beforeEach(() => {
mockWindowOpen.mockReset();
mockWindowFocus.mockReset();

View File

@ -14,62 +14,15 @@
limitations under the License.
*/
import testContext from './testContext.js';
import SetGlobal from './SetGlobal.js';
const mockActionMethod = jest.fn();
const lowdefy = {
_internal: {
actions: {
SetGlobal: (props) => SetGlobal({ ...props, methods: { setGlobal: mockActionMethod } }),
},
blockComponents: {
Button: { meta: { category: 'display' } },
},
},
};
beforeEach(() => {
mockActionMethod.mockReset();
});
test('SetGlobal 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: 'SetGlobal',
params: 'call',
},
],
},
},
],
},
},
};
const context = await testContext({
lowdefy,
rootBlock,
});
const button = context._internal.RootBlocks.map['button'];
await button.triggerEvent({ name: 'onClick' });
SetGlobal({ methods: { setGlobal: mockActionMethod }, params: 'call' });
expect(mockActionMethod.mock.calls).toEqual([['call']]);
});

View File

@ -14,62 +14,15 @@
limitations under the License.
*/
import testContext from './testContext.js';
import SetState from './SetState.js';
const mockActionMethod = jest.fn();
const lowdefy = {
_internal: {
actions: {
SetState: (props) => SetState({ ...props, methods: { setState: mockActionMethod } }),
},
blockComponents: {
Button: { meta: { category: 'display' } },
},
},
};
beforeEach(() => {
mockActionMethod.mockReset();
});
test('SetState 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: 'SetState',
params: 'call',
},
],
},
},
],
},
},
};
const context = await testContext({
lowdefy,
rootBlock,
});
const button = context._internal.RootBlocks.map['button'];
await button.triggerEvent({ name: 'onClick' });
SetState({ methods: { setState: mockActionMethod }, params: 'call' });
expect(mockActionMethod.mock.calls).toEqual([['call']]);
});

View File

@ -14,62 +14,15 @@
limitations under the License.
*/
import testContext from './testContext.js';
import Validate from './Validate.js';
const mockActionMethod = jest.fn();
const lowdefy = {
_internal: {
actions: {
Validate: (props) => Validate({ ...props, methods: { validate: mockActionMethod } }),
},
blockComponents: {
Button: { meta: { category: 'display' } },
},
},
};
beforeEach(() => {
mockActionMethod.mockReset();
});
test('Validate 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: 'Validate',
params: 'call',
},
],
},
},
],
},
},
};
const context = await testContext({
lowdefy,
rootBlock,
});
const button = context._internal.RootBlocks.map['button'];
await button.triggerEvent({ name: 'onClick' });
Validate({ methods: { validate: mockActionMethod }, params: 'call' });
expect(mockActionMethod.mock.calls).toEqual([['call']]);
});