From e24d40408ff73e7b251ce2777e263d4099bf7f26 Mon Sep 17 00:00:00 2001 From: Sandile Date: Fri, 11 Feb 2022 13:37:19 +0200 Subject: [PATCH] chore(actions-core): Simplify action tests. --- .../src/actions/CallMethod.test.js | 49 +----------------- .../actions-core/src/actions/Login.test.js | 49 +----------------- .../actions-core/src/actions/Logout.test.js | 49 +----------------- .../actions-core/src/actions/Message.test.js | 49 +----------------- .../actions-core/src/actions/Request.test.js | 49 +----------------- .../actions-core/src/actions/Reset.test.js | 48 +----------------- .../src/actions/ResetValidation.test.js | 50 +------------------ .../actions-core/src/actions/ScrollTo.test.js | 4 ++ .../src/actions/SetGlobal.test.js | 49 +----------------- .../actions-core/src/actions/SetState.test.js | 49 +----------------- .../actions-core/src/actions/Validate.test.js | 49 +----------------- 11 files changed, 14 insertions(+), 480 deletions(-) diff --git a/packages/plugins/actions/actions-core/src/actions/CallMethod.test.js b/packages/plugins/actions/actions-core/src/actions/CallMethod.test.js index 8817835f9..02fb41024 100644 --- a/packages/plugins/actions/actions-core/src/actions/CallMethod.test.js +++ b/packages/plugins/actions/actions-core/src/actions/CallMethod.test.js @@ -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']]); }); diff --git a/packages/plugins/actions/actions-core/src/actions/Login.test.js b/packages/plugins/actions/actions-core/src/actions/Login.test.js index 88ce02e99..22bbe59bc 100644 --- a/packages/plugins/actions/actions-core/src/actions/Login.test.js +++ b/packages/plugins/actions/actions-core/src/actions/Login.test.js @@ -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']]); }); diff --git a/packages/plugins/actions/actions-core/src/actions/Logout.test.js b/packages/plugins/actions/actions-core/src/actions/Logout.test.js index c76c5f340..e0f94a6b0 100644 --- a/packages/plugins/actions/actions-core/src/actions/Logout.test.js +++ b/packages/plugins/actions/actions-core/src/actions/Logout.test.js @@ -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([[]]); }); diff --git a/packages/plugins/actions/actions-core/src/actions/Message.test.js b/packages/plugins/actions/actions-core/src/actions/Message.test.js index 2213aafe3..28d0cee47 100644 --- a/packages/plugins/actions/actions-core/src/actions/Message.test.js +++ b/packages/plugins/actions/actions-core/src/actions/Message.test.js @@ -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']]); }); diff --git a/packages/plugins/actions/actions-core/src/actions/Request.test.js b/packages/plugins/actions/actions-core/src/actions/Request.test.js index 7c53f9614..f183a9ad6 100644 --- a/packages/plugins/actions/actions-core/src/actions/Request.test.js +++ b/packages/plugins/actions/actions-core/src/actions/Request.test.js @@ -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']]); }); diff --git a/packages/plugins/actions/actions-core/src/actions/Reset.test.js b/packages/plugins/actions/actions-core/src/actions/Reset.test.js index da09a93f7..6dc1429e2 100644 --- a/packages/plugins/actions/actions-core/src/actions/Reset.test.js +++ b/packages/plugins/actions/actions-core/src/actions/Reset.test.js @@ -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([[]]); }); diff --git a/packages/plugins/actions/actions-core/src/actions/ResetValidation.test.js b/packages/plugins/actions/actions-core/src/actions/ResetValidation.test.js index 33aec3faf..da1786160 100644 --- a/packages/plugins/actions/actions-core/src/actions/ResetValidation.test.js +++ b/packages/plugins/actions/actions-core/src/actions/ResetValidation.test.js @@ -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']]); }); diff --git a/packages/plugins/actions/actions-core/src/actions/ScrollTo.test.js b/packages/plugins/actions/actions-core/src/actions/ScrollTo.test.js index 1716eea5a..c9aa7d396 100644 --- a/packages/plugins/actions/actions-core/src/actions/ScrollTo.test.js +++ b/packages/plugins/actions/actions-core/src/actions/ScrollTo.test.js @@ -51,6 +51,10 @@ const lowdefy = { }, }; +// Comment out to use console +console.log = () => {}; +console.error = () => {}; + beforeEach(() => { mockWindowOpen.mockReset(); mockWindowFocus.mockReset(); diff --git a/packages/plugins/actions/actions-core/src/actions/SetGlobal.test.js b/packages/plugins/actions/actions-core/src/actions/SetGlobal.test.js index b491bb976..0f6906997 100644 --- a/packages/plugins/actions/actions-core/src/actions/SetGlobal.test.js +++ b/packages/plugins/actions/actions-core/src/actions/SetGlobal.test.js @@ -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']]); }); diff --git a/packages/plugins/actions/actions-core/src/actions/SetState.test.js b/packages/plugins/actions/actions-core/src/actions/SetState.test.js index c9fc78b81..bd9b5c2ea 100644 --- a/packages/plugins/actions/actions-core/src/actions/SetState.test.js +++ b/packages/plugins/actions/actions-core/src/actions/SetState.test.js @@ -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']]); }); diff --git a/packages/plugins/actions/actions-core/src/actions/Validate.test.js b/packages/plugins/actions/actions-core/src/actions/Validate.test.js index 07bf6006b..28165cb26 100644 --- a/packages/plugins/actions/actions-core/src/actions/Validate.test.js +++ b/packages/plugins/actions/actions-core/src/actions/Validate.test.js @@ -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']]); });