From 5cf3100b5ff17ce302e2a5f4840da38a2ec99730 Mon Sep 17 00:00:00 2001 From: ilyamore88 Date: Wed, 11 May 2022 23:11:43 +0300 Subject: [PATCH] use named functions, rename action creators --- .../store/actions/blockReducerActions.ts | 30 +++++++++++-------- test/cypress/tests/store/store.spec.ts | 8 ++--- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/components/store/actions/blockReducerActions.ts b/src/components/store/actions/blockReducerActions.ts index 7df8e609..3592a9f3 100644 --- a/src/components/store/actions/blockReducerActions.ts +++ b/src/components/store/actions/blockReducerActions.ts @@ -7,27 +7,33 @@ import { ChangeBlockDataAction, CreateBlockAction, RemoveBlockAction } from '../ * * @param block - new block data */ -export const createBlock = (block: OutputBlockData): CreateBlockAction => ({ - type: BlockMutationType.Added, - data: block, -}); +export function makeCreateBlockAction(block: OutputBlockData): CreateBlockAction { + return { + type: BlockMutationType.Added, + data: block, + }; +} /** * Action creator for changing block data in the store * * @param block - new block data */ -export const changeBlock = (block: OutputBlockData): ChangeBlockDataAction => ({ - type: BlockMutationType.Changed, - data: block, -}); +export function makeChangeBlockAction(block: OutputBlockData): ChangeBlockDataAction { + return { + type: BlockMutationType.Changed, + data: block, + }; +} /** * Action creator for removing block data from the store * * @param blockId - id of a block for removing */ -export const removeBlock = (blockId: string): RemoveBlockAction => ({ - type: BlockMutationType.Removed, - blockId, -}); +export function makeRemoveBlockAction(blockId: string): RemoveBlockAction { + return { + type: BlockMutationType.Removed, + blockId, + }; +} diff --git a/test/cypress/tests/store/store.spec.ts b/test/cypress/tests/store/store.spec.ts index e8b0c0e7..a36ed322 100644 --- a/test/cypress/tests/store/store.spec.ts +++ b/test/cypress/tests/store/store.spec.ts @@ -1,7 +1,7 @@ import createStore from '../../../../src/components/store/createStore'; import { EditorState } from '../../../../types/store/editorState'; import blocksReducer from '../../../../src/components/store/blocksReducer'; -import { changeBlock, createBlock, removeBlock } from '../../../../src/components/store/actions/blockReducerActions'; +import { makeChangeBlockAction, makeCreateBlockAction, makeRemoveBlockAction } from '../../../../src/components/store/actions/blockReducerActions'; describe('State manager', () => { it('should create the store without initial state', () => { @@ -49,7 +49,7 @@ describe('State manager', () => { }, }; - store.dispatch(createBlock(block)); + store.dispatch(makeCreateBlockAction(block)); expect(store.getState()).to.be.deep.equal(expectedResult); }); @@ -81,7 +81,7 @@ describe('State manager', () => { }, }; - store.dispatch(changeBlock(changedBlock)); + store.dispatch(makeChangeBlockAction(changedBlock)); expect(store.getState()).to.be.deep.equal(expectedResult); }); @@ -104,7 +104,7 @@ describe('State manager', () => { blocks: {}, }; - store.dispatch(removeBlock(block.id)); + store.dispatch(makeRemoveBlockAction(block.id)); expect(store.getState()).to.be.deep.equal(expectedResult); });