From 739ec2f54e0fc53aafdb7462e4b545b9e8281214 Mon Sep 17 00:00:00 2001 From: Leandro Lourenci Date: Fri, 15 Nov 2019 09:17:15 -0300 Subject: [PATCH] Welcome, Prettier --- .eslintrc | 3 +- .prettierrc | 6 ++ package.json | 3 + .../Board/components/DefaultCard/index.js | 6 +- .../components/DefaultCard/index.spec.js | 4 +- .../components/DefaultLaneHeader/index.js | 43 ++++----- .../DefaultLaneHeader/index.spec.js | 4 +- .../components/Lane/components/Card/index.js | 13 +-- .../Lane/components/Card/index.spec.js | 14 ++- src/components/Board/components/Lane/index.js | 9 +- .../Board/components/Lane/index.spec.js | 10 +- .../LaneAdder/components/LaneForm/index.js | 8 +- .../components/LaneForm/index.spec.js | 6 +- .../Board/components/LaneAdder/index.js | 14 ++- .../Board/components/LaneAdder/index.spec.js | 6 +- src/components/Board/index.js | 66 ++++++------- src/components/Board/index.spec.js | 94 ++++++++++++------- src/components/Board/services/reorderBoard.js | 8 +- .../Board/services/reorderBoard.spec.js | 4 +- src/components/withDroppable/index.js | 4 +- src/components/withDroppable/index.spec.js | 4 +- src/services/utils.js | 18 ++-- 22 files changed, 195 insertions(+), 152 deletions(-) create mode 100644 .prettierrc diff --git a/.eslintrc b/.eslintrc index 895def6b..6c0f9b7b 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,11 +1,12 @@ { - "extends": ["standard", "standard-react"], + "extends": ["standard", "standard-react", "plugin:prettier/recommended"], "plugins": ["react-hooks"], "env": { "jest": true }, "rules": { "react/prop-types": "off", + "react/jsx-indent": "off", "react-hooks/rules-of-hooks": "error", "react-hooks/exhaustive-deps": "warn" } diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 00000000..efd31986 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,6 @@ +{ + "semi": false, + "singleQuote": true, + "printWidth": 120, + "jsxSingleQuote": true +} diff --git a/package.json b/package.json index d9d996c5..91af83a4 100644 --- a/package.json +++ b/package.json @@ -28,11 +28,13 @@ "cypress": "3.6.1", "docz": "2.0.0-rc.53", "eslint": "6.6.0", + "eslint-config-prettier": "^6.5.0", "eslint-config-standard": "14.1.0", "eslint-config-standard-react": "9.2.0", "eslint-plugin-cypress": "2.7.0", "eslint-plugin-import": "2.18.2", "eslint-plugin-node": "10.0.0", + "eslint-plugin-prettier": "^3.1.1", "eslint-plugin-promise": "4.2.1", "eslint-plugin-react": "7.15.1", "eslint-plugin-react-hooks": "2.3.0", @@ -42,6 +44,7 @@ "jest": "24.8.0", "jest-environment-jsdom-fifteen": "1.0.0", "nyc": "14.1.1", + "prettier": "^1.19.1", "react": "16.12.0", "react-dom": "16.12.0", "start-server-and-test": "1.10.3", diff --git a/src/components/Board/components/DefaultCard/index.js b/src/components/Board/components/DefaultCard/index.js index f2c2704b..6bcf5888 100644 --- a/src/components/Board/components/DefaultCard/index.js +++ b/src/components/Board/components/DefaultCard/index.js @@ -9,7 +9,9 @@ const DefaultCard = styled(CardSkeleton)` padding: 10px; margin-bottom: 7px; - ${({ dragging }) => dragging && ` + ${({ dragging }) => + dragging && + ` box-shadow: 2px 2px grey; `} ` @@ -26,7 +28,7 @@ const CardDescription = styled.div` padding-top: 10px; ` -export default function ({ children: card, dragging, allowRemoveCard, onCardRemove }) { +export default function({ children: card, dragging, allowRemoveCard, onCardRemove }) { return ( diff --git a/src/components/Board/components/DefaultCard/index.spec.js b/src/components/Board/components/DefaultCard/index.spec.js index e55b50b6..67b2bba5 100644 --- a/src/components/Board/components/DefaultCard/index.spec.js +++ b/src/components/Board/components/DefaultCard/index.spec.js @@ -9,7 +9,7 @@ describe('', () => { const card = { id: 1, title: 'Card title', description: 'Description' } - function mount (props) { + function mount(props) { subject = render( {card} @@ -18,7 +18,7 @@ describe('', () => { return subject } - function reset () { + function reset() { subject = undefined onCardRemove.mockClear() } diff --git a/src/components/Board/components/DefaultLaneHeader/index.js b/src/components/Board/components/DefaultLaneHeader/index.js index 5c93a6be..9003cbe6 100644 --- a/src/components/Board/components/DefaultLaneHeader/index.js +++ b/src/components/Board/components/DefaultLaneHeader/index.js @@ -15,11 +15,13 @@ const LaneHeaderSkeleton = styled.div` const DefaultButton = styled.button` color: #333333; - background-color: #FFFFFF; - border-color: #CCCCCC; + background-color: #ffffff; + border-color: #cccccc; - :hover, :focus, :active { - background-color: #E6E6E6; + :hover, + :focus, + :active { + background-color: #e6e6e6; } ` @@ -29,34 +31,26 @@ const Input = styled.input` } ` -function LaneTitle ({ allowRenameLane, onClick, children: title }) { - return allowRenameLane ? ( - - {title} - - ) : ( - - {title} - - ) +function LaneTitle({ allowRenameLane, onClick, children: title }) { + return allowRenameLane ? {title} : {title} } -function useRenameMode (state) { +function useRenameMode(state) { const [renameMode, setRenameMode] = useState(state) - function toggleRenameMode () { + function toggleRenameMode() { setRenameMode(!renameMode) } return [renameMode, toggleRenameMode] } -export default function ({ children: lane, allowRemoveLane, onLaneRemove, allowRenameLane, onLaneRename }) { +export default function({ children: lane, allowRemoveLane, onLaneRemove, allowRenameLane, onLaneRename }) { const [renameMode, toggleRenameMode] = useRenameMode(false) const [title, setTitle] = useState(lane.title) const [titleInput, setTitleInput] = useState('') - function handleRenameLane (event) { + function handleRenameLane(event) { event.preventDefault() onLaneRename(lane.id, titleInput) @@ -64,7 +58,7 @@ export default function ({ children: lane, allowRemoveLane, onLaneRemove, allowR toggleRenameMode() } - function handleRenameMode () { + function handleRenameMode() { setTitleInput(title) toggleRenameMode() } @@ -74,11 +68,18 @@ export default function ({ children: lane, allowRemoveLane, onLaneRemove, allowR {renameMode ? (
- setTitleInput(value)} autoFocus /> + setTitleInput(value)} + autoFocus + /> Rename - Cancel + + Cancel +
) : ( diff --git a/src/components/Board/components/DefaultLaneHeader/index.spec.js b/src/components/Board/components/DefaultLaneHeader/index.spec.js index a8dfe37a..5277675f 100644 --- a/src/components/Board/components/DefaultLaneHeader/index.spec.js +++ b/src/components/Board/components/DefaultLaneHeader/index.spec.js @@ -10,13 +10,13 @@ describe('', () => { const lane = { id: 1, title: 'Lane title' } - function reset () { + function reset() { subject = undefined onLaneRemove.mockClear() onLaneRename.mockClear() } - function mount (props) { + function mount(props) { subject = render( {lane} diff --git a/src/components/Board/components/Lane/components/Card/index.js b/src/components/Board/components/Lane/components/Card/index.js index c6ed7f48..40da19ca 100644 --- a/src/components/Board/components/Lane/components/Card/index.js +++ b/src/components/Board/components/Lane/components/Card/index.js @@ -7,20 +7,13 @@ const CardTemplate = styled.div` white-space: normal; ` -function Card ({ children, index, renderCard, disableCardDrag }) { +function Card({ children, index, renderCard, disableCardDrag }) { return ( {(provided, { isDragging }) => { return ( -
- - {renderCard(isDragging)} - +
+ {renderCard(isDragging)}
) }} diff --git a/src/components/Board/components/Lane/components/Card/index.spec.js b/src/components/Board/components/Lane/components/Card/index.spec.js index 2e953ff3..34728705 100644 --- a/src/components/Board/components/Lane/components/Card/index.spec.js +++ b/src/components/Board/components/Lane/components/Card/index.spec.js @@ -14,12 +14,16 @@ describe('', () => { const defaultCard = jest.fn(() =>
Card title
) - function mount ({ children = card, ...otherProps } = {}) { - subject = render({children}) + function mount({ children = card, ...otherProps } = {}) { + subject = render( + + {children} + + ) return subject } - function reset () { + function reset() { subject = undefined defaultCard.mockClear() } @@ -35,7 +39,9 @@ describe('', () => { callbacks.isDragging(true) mount() }) - afterEach(() => { callbacks.isDragging(false) }) + afterEach(() => { + callbacks.isDragging(false) + }) it('calls the "renderCard" prop passing the dragging value', () => { expect(defaultCard).toHaveBeenCalledTimes(1) diff --git a/src/components/Board/components/Lane/index.js b/src/components/Board/components/Lane/index.js index a6943c2f..62518bfe 100644 --- a/src/components/Board/components/Lane/index.js +++ b/src/components/Board/components/Lane/index.js @@ -19,14 +19,7 @@ const DroppableLane = withDroppable(styled.div` min-height: 28px; `) -function Lane ({ - children, - index: laneIndex, - renderCard, - renderLaneHeader, - disableLaneDrag, - disableCardDrag -}) { +function Lane({ children, index: laneIndex, renderCard, renderLaneHeader, disableLaneDrag, disableCardDrag }) { return ( {laneProvided => ( diff --git a/src/components/Board/components/Lane/index.spec.js b/src/components/Board/components/Lane/index.spec.js index 236e2e7f..0963a9aa 100644 --- a/src/components/Board/components/Lane/index.spec.js +++ b/src/components/Board/components/Lane/index.spec.js @@ -24,20 +24,16 @@ describe('', () => { ] } - function mount ({ children = lane, ...otherProps } = {}) { + function mount({ children = lane, ...otherProps } = {}) { subject = render( - Backlog
} - renderCard={renderCard} - > + Backlog} renderCard={renderCard}> {children} ) return subject } - function reset () { + function reset() { subject = undefined renderCard.mockClear() } diff --git a/src/components/Board/components/LaneAdder/components/LaneForm/index.js b/src/components/Board/components/LaneAdder/components/LaneForm/index.js index 5389897f..21021630 100644 --- a/src/components/Board/components/LaneAdder/components/LaneForm/index.js +++ b/src/components/Board/components/LaneAdder/components/LaneForm/index.js @@ -12,10 +12,10 @@ const StyledLaneForm = styled(StyledLane)` } ` -function LaneForm ({ onConfirm, onCancel }) { +function LaneForm({ onConfirm, onCancel }) { const inputLaneTitle = React.createRef() - function addLane (event) { + function addLane(event) { event.preventDefault() when(inputLaneTitle.current.value)(onConfirm) @@ -26,7 +26,9 @@ function LaneForm ({ onConfirm, onCancel }) {
- +
) diff --git a/src/components/Board/components/LaneAdder/components/LaneForm/index.spec.js b/src/components/Board/components/LaneAdder/components/LaneForm/index.spec.js index 0290fc2c..a671af2c 100644 --- a/src/components/Board/components/LaneAdder/components/LaneForm/index.spec.js +++ b/src/components/Board/components/LaneAdder/components/LaneForm/index.spec.js @@ -5,7 +5,7 @@ import LaneForm from './' describe('', () => { let subject, onConfirm, onCancel - function mount () { + function mount() { onConfirm = jest.fn() onCancel = jest.fn() @@ -13,7 +13,9 @@ describe('', () => { } beforeEach(mount) - afterEach(() => { subject = onConfirm = onCancel = undefined }) + afterEach(() => { + subject = onConfirm = onCancel = undefined + }) it('renders an input asking for a lane title', () => { expect(subject.container.querySelector('input')).toBeInTheDocument() diff --git a/src/components/Board/components/LaneAdder/index.js b/src/components/Board/components/LaneAdder/index.js index 9084acaa..5c277ddd 100644 --- a/src/components/Board/components/LaneAdder/index.js +++ b/src/components/Board/components/LaneAdder/index.js @@ -16,17 +16,21 @@ const LaneAdderPlaceholder = styled.div` } ` -function LaneAdder ({ onConfirm }) { +function LaneAdder({ onConfirm }) { const [isAddingLane, setAddingLane] = useState(false) - function confirmLane (title) { + function confirmLane(title) { onConfirm(title) setAddingLane(false) } - return isAddingLane - ? setAddingLane(false)} /> - : setAddingLane(true)} role='button'>➕ + return isAddingLane ? ( + setAddingLane(false)} /> + ) : ( + setAddingLane(true)} role='button'> + ➕ + + ) } export default LaneAdder diff --git a/src/components/Board/components/LaneAdder/index.spec.js b/src/components/Board/components/LaneAdder/index.spec.js index 19b2089b..5621ccf0 100644 --- a/src/components/Board/components/LaneAdder/index.spec.js +++ b/src/components/Board/components/LaneAdder/index.spec.js @@ -5,14 +5,16 @@ import LaneAdder from './' describe('', () => { let subject, onConfirm - function mount () { + function mount() { onConfirm = jest.fn() subject = render() } beforeEach(mount) - afterEach(() => { subject = onConfirm = undefined }) + afterEach(() => { + subject = onConfirm = undefined + }) it('renders the lane placeholder to add a new lane', () => { expect(subject.queryByText('➕')).toBeInTheDocument() diff --git a/src/components/Board/index.js b/src/components/Board/index.js index 21b12d64..727b9a9a 100644 --- a/src/components/Board/index.js +++ b/src/components/Board/index.js @@ -22,7 +22,7 @@ const Lanes = styled.div` const DroppableBoard = withDroppable(Lanes) -function Board ({ +function Board({ children, onCardDragEnd, onLaneDragEnd, @@ -43,7 +43,7 @@ function Board ({ }) { const [board, setBoard] = useState(children) - function onDragEnd (event) { + function onDragEnd(event) { if (event.destination === null) return let source = { index: event.source.index } @@ -61,49 +61,48 @@ function Board ({ setBoard(reorderedBoard) } - async function addLane (lane) { - const lanes = renderLaneAdder ? addInArrayAtPosition(board.lanes, lane, board.lanes.length) + async function addLane(lane) { + const lanes = renderLaneAdder + ? addInArrayAtPosition(board.lanes, lane, board.lanes.length) : addInArrayAtPosition(board.lanes, await onLaneNew(lane), board.lanes.length) setBoard({ ...board, lanes }) } - function removeLane (lane) { + function removeLane(lane) { const filteredLanes = board.lanes.filter(({ id }) => id !== lane.id) const filteredBoard = { ...board, lanes: filteredLanes } onLaneRemove(filteredBoard, lane) setBoard(filteredBoard) } - function renameLane (laneId, title) { + function renameLane(laneId, title) { const renamedLane = board.lanes.find(lane => lane.id === laneId) - const renamedLanes = board.lanes.map(lane => lane.id === laneId ? { ...lane, title } : lane) + const renamedLanes = board.lanes.map(lane => (lane.id === laneId ? { ...lane, title } : lane)) const boardWithRenamedLane = { ...board, lanes: renamedLanes } onLaneRename(boardWithRenamedLane, { ...renamedLane, title }) setBoard(boardWithRenamedLane) } - function removeCard (lane, card) { + function removeCard(lane, card) { const filteredCards = lane.cards.filter(({ id }) => card.id !== id) const laneWithoutCard = { ...lane, cards: filteredCards } - const filteredLanes = board.lanes.map(laneMap => lane.id === laneMap.id ? laneWithoutCard : laneMap) + const filteredLanes = board.lanes.map(laneMap => (lane.id === laneMap.id ? laneWithoutCard : laneMap)) const boardWithoutCard = { ...board, lanes: filteredLanes } onCardRemove(boardWithoutCard, laneWithoutCard, card) setBoard(boardWithoutCard) } - function addCard (lane, card, { on } = {}) { + function addCard(lane, card, { on } = {}) { const cards = addInArrayAtPosition(lane.cards, card, on === 'top' ? 0 : lane.cards.length) - const lanes = board.lanes.map(laneMap => lane.id === laneMap.id ? { ...laneMap, cards } : laneMap) + const lanes = board.lanes.map(laneMap => (lane.id === laneMap.id ? { ...laneMap, cards } : laneMap)) const boardWithNewCard = { ...board, lanes } onCardNew(boardWithNewCard, { ...lane, cards }, card) setBoard(boardWithNewCard) } return ( - + {board.lanes.map((lane, index) => ( @@ -122,22 +121,24 @@ function Board ({
) }} - renderLaneHeader={renderLaneHeader ? ( - renderLaneHeader(lane, { - removeLane: removeLane.bind(null, lane), - renameLane: renameLane.bind(null, lane.id), - addCard: addCard.bind(null, lane) - }) - ) : ( - - {lane} - - )} + renderLaneHeader={ + renderLaneHeader ? ( + renderLaneHeader(lane, { + removeLane: removeLane.bind(null, lane), + renameLane: renameLane.bind(null, lane.id), + addCard: addCard.bind(null, lane) + }) + ) : ( + + {lane} + + ) + } disableLaneDrag={disableLaneDrag} disableCardDrag={disableCardDrag} > @@ -145,8 +146,9 @@ function Board ({ ))} - {renderLaneAdder && allowAddLane ? renderLaneAdder({ addLane }) - : allowAddLane && onLaneNew && addLane({ title, cards: [] })} />} + {renderLaneAdder && allowAddLane + ? renderLaneAdder({ addLane }) + : allowAddLane && onLaneNew && addLane({ title, cards: [] })} />} ) diff --git a/src/components/Board/index.spec.js b/src/components/Board/index.spec.js index 54b80af0..29113157 100644 --- a/src/components/Board/index.spec.js +++ b/src/components/Board/index.spec.js @@ -37,11 +37,13 @@ describe('', () => { ] } - function mount ({ children = board, ...otherProps } = {}) { + function mount({ children = board, ...otherProps } = {}) { subject = render({children}) return subject } - afterEach(() => { subject = onCardDragEnd = onLaneDragEnd = onLaneRemove = onCardRemove = undefined }) + afterEach(() => { + subject = onCardDragEnd = onLaneDragEnd = onLaneRemove = onCardRemove = undefined + }) it('renders a board', () => { expect(mount().container.querySelector('div')).toBeInTheDocument() @@ -55,7 +57,11 @@ describe('', () => { }) it('renders the specified cards in their lanes', () => { - const lane = within(mount().queryByText(/^Lane Backlog$/).closest('[data-testid="lane"]')) + const lane = within( + mount() + .queryByText(/^Lane Backlog$/) + .closest('[data-testid="lane"]') + ) const cards = lane.queryAllByText(/^Card title/) expect(cards).toHaveLength(2) }) @@ -68,7 +74,9 @@ describe('', () => { }) describe('when the user cancels the card moving', () => { - beforeEach(() => { callbacks.onDragEnd({ source: null, destination: null }) }) + beforeEach(() => { + callbacks.onDragEnd({ source: null, destination: null }) + }) it('does not call onCardDragEnd callback', () => { expect(onCardDragEnd).not.toHaveBeenCalled() @@ -129,7 +137,9 @@ describe('', () => { }) describe('when the user cancels the lane moving', () => { - beforeEach(() => { callbacks.onDragEnd({ source: null, destination: null, type: 'BOARD' }) }) + beforeEach(() => { + callbacks.onDragEnd({ source: null, destination: null, type: 'BOARD' }) + }) it('does not call onLaneDragEnd callback', () => { expect(onLaneDragEnd).not.toHaveBeenCalled() @@ -217,12 +227,16 @@ describe('', () => { ] } - afterEach(() => { renderCard = undefined }) + afterEach(() => { + renderCard = undefined + }) describe('when it receives a "renderCard" prop', () => { beforeEach(() => { renderCard = jest.fn(cardContent => ( -
{cardContent.id} - {cardContent.title} - {cardContent.content}
+
+ {cardContent.id} - {cardContent.title} - {cardContent.content} +
)) mount({ children: board, renderCard }) @@ -256,12 +270,16 @@ describe('', () => { ] } - afterEach(() => { renderLaneHeader = undefined }) + afterEach(() => { + renderLaneHeader = undefined + }) describe('when the component receives a "renderLaneHeader" prop', () => { beforeEach(() => { renderLaneHeader = jest.fn(laneContent => ( -
{laneContent.title} ({laneContent.wip})
+
+ {laneContent.title} ({laneContent.wip}) +
)) mount({ children: board, renderLaneHeader }) @@ -274,12 +292,15 @@ describe('', () => { it('passes the lane content, the "removeLane" and the "renameLane" to the "renderLaneHeader" prop', () => { expect(renderLaneHeader).toHaveBeenCalledTimes(1) - expect(renderLaneHeader).toHaveBeenCalledWith({ - id: 1, - title: 'Lane Backlog', - wip: 1, - cards: [{ id: 2, title: 'Card title', content: 'Card content' }] - }, { removeLane: expect.any(Function), renameLane: expect.any(Function), addCard: expect.any(Function) }) + expect(renderLaneHeader).toHaveBeenCalledWith( + { + id: 1, + title: 'Lane Backlog', + wip: 1, + cards: [{ id: 2, title: 'Card title', content: 'Card content' }] + }, + { removeLane: expect.any(Function), renameLane: expect.any(Function), addCard: expect.any(Function) } + ) }) }) @@ -302,7 +323,9 @@ describe('', () => { onLaneNew = jest.fn(lane => new Promise(resolve => resolve({ id: 999, ...lane }))) mount({ allowAddLane: false, onLaneNew }) }) - afterEach(() => { onLaneNew = undefined }) + afterEach(() => { + onLaneNew = undefined + }) it('does not render the lane adder', () => { expect(subject.queryByText('➕')).not.toBeInTheDocument() @@ -326,7 +349,9 @@ describe('', () => { onLaneNew = jest.fn(lane => new Promise(resolve => resolve({ id: 999, ...lane }))) mount({ allowAddLane: true, onLaneNew }) }) - afterEach(() => { onLaneNew = undefined }) + afterEach(() => { + onLaneNew = undefined + }) it('renders the lane placeholder as the last lane to add a new lane', () => { expect(subject.queryByText('➕')).toBeInTheDocument() @@ -388,7 +413,9 @@ describe('', () => { describe('when the component does not receive "allowAddLane" prop', () => { beforeEach(() => { renderLaneAdder = jest.fn(addLane => ( -
+
+ +
)) mount({ children: board, renderLaneAdder }) @@ -402,7 +429,9 @@ describe('', () => { describe('when the component receives the "allowAddLane" prop', () => { beforeEach(() => { renderLaneAdder = jest.fn(addLane => ( -
+
+ +
)) mount({ children: board, renderLaneAdder, allowAddLane: true }) @@ -422,7 +451,9 @@ describe('', () => { }) describe('about the lane removing', () => { - beforeEach(() => { onLaneRemove = jest.fn() }) + beforeEach(() => { + onLaneRemove = jest.fn() + }) describe('when the component uses the default header template', () => { describe('when the component receives the "allowRemoveLane" prop', () => { @@ -551,7 +582,9 @@ describe('', () => { describe('when the component receives a custom header lane template', () => { beforeEach(() => { - const renderLaneHeader = ({ title }, { renameLane }) =>
renameLane('New title')}>{title}
+ const renderLaneHeader = ({ title }, { renameLane }) => ( +
renameLane('New title')}>{title}
+ ) onLaneRename = jest.fn() mount({ renderLaneHeader, onLaneRename }) }) @@ -580,7 +613,9 @@ describe('', () => { }) describe('about the card removing', () => { - beforeEach(() => { onCardRemove = jest.fn() }) + beforeEach(() => { + onCardRemove = jest.fn() + }) describe('when the component uses the default card template', () => { describe('when the component receives the "allowRemoveCard" prop', () => { @@ -713,10 +748,7 @@ describe('', () => { expect(onCardNew).toHaveBeenCalledTimes(1) expect(onCardNew).toHaveBeenCalledWith( { - lanes: [ - expect.objectContaining({ id: 1 }), - expect.objectContaining({ id: 2 }) - ] + lanes: [expect.objectContaining({ id: 1 }), expect.objectContaining({ id: 2 })] }, expect.objectContaining({ id: 1, @@ -750,10 +782,7 @@ describe('', () => { expect(onCardNew).toHaveBeenCalledTimes(1) expect(onCardNew).toHaveBeenCalledWith( { - lanes: [ - expect.objectContaining({ id: 1 }), - expect.objectContaining({ id: 2 }) - ] + lanes: [expect.objectContaining({ id: 1 }), expect.objectContaining({ id: 2 })] }, expect.objectContaining({ id: 1, @@ -787,10 +816,7 @@ describe('', () => { expect(onCardNew).toHaveBeenCalledTimes(1) expect(onCardNew).toHaveBeenCalledWith( { - lanes: [ - expect.objectContaining({ id: 1 }), - expect.objectContaining({ id: 2 }) - ] + lanes: [expect.objectContaining({ id: 1 }), expect.objectContaining({ id: 2 })] }, expect.objectContaining({ id: 1, diff --git a/src/components/Board/services/reorderBoard.js b/src/components/Board/services/reorderBoard.js index bfd7e007..118b0b30 100644 --- a/src/components/Board/services/reorderBoard.js +++ b/src/components/Board/services/reorderBoard.js @@ -1,11 +1,11 @@ import { removeFromArrayAtPosition, addInArrayAtPosition, changeElementOfPositionInArray } from '@services/utils' -export default function reorderBoard (board, source, destination) { +export default function reorderBoard(board, source, destination) { const reorderFn = source.laneId ? reorderCardsOnBorder : reorderLaneOnBorder return reorderFn(board, source, destination) } -function reorderCardsOnBorder (board, source, destination) { +function reorderCardsOnBorder(board, source, destination) { const sourceLane = board.lanes.find(lane => lane.id === source.laneId) const destinationLane = board.lanes.find(lane => lane.id === destination.laneId) @@ -18,7 +18,7 @@ function reorderCardsOnBorder (board, source, destination) { const reorderedCardsOnLane = reorderCardsOnSourceLane(cards => { return changeElementOfPositionInArray(cards, source.index, destination.index) }) - return reorderLanesOnBoard(lane => lane.id === sourceLane.id ? reorderedCardsOnLane : lane) + return reorderLanesOnBoard(lane => (lane.id === sourceLane.id ? reorderedCardsOnLane : lane)) } else { const reorderedCardsOnSourceLane = reorderCardsOnSourceLane(cards => { return removeFromArrayAtPosition(cards, source.index) @@ -34,6 +34,6 @@ function reorderCardsOnBorder (board, source, destination) { } } -function reorderLaneOnBorder (board, source, destination) { +function reorderLaneOnBorder(board, source, destination) { return { ...board, lanes: changeElementOfPositionInArray(board.lanes, source.index, destination.index) } } diff --git a/src/components/Board/services/reorderBoard.spec.js b/src/components/Board/services/reorderBoard.spec.js index e4ab9236..cdca3750 100644 --- a/src/components/Board/services/reorderBoard.spec.js +++ b/src/components/Board/services/reorderBoard.spec.js @@ -3,7 +3,9 @@ import reorderBoard from './reorderBoard' describe('#reorderBoard', () => { let subject - afterEach(() => { subject = undefined }) + afterEach(() => { + subject = undefined + }) describe('when the card is changed of position in same lane', () => { beforeEach(() => { diff --git a/src/components/withDroppable/index.js b/src/components/withDroppable/index.js index c858b5ae..7eb85797 100644 --- a/src/components/withDroppable/index.js +++ b/src/components/withDroppable/index.js @@ -1,8 +1,8 @@ import React from 'react' import { Droppable } from 'react-beautiful-dnd' -function withDroppable (Component) { - return function WrapperComponent ({ children, ...droppableProps }) { +function withDroppable(Component) { + return function WrapperComponent({ children, ...droppableProps }) { return ( {provided => ( diff --git a/src/components/withDroppable/index.spec.js b/src/components/withDroppable/index.spec.js index 0b832146..5a79fdf5 100644 --- a/src/components/withDroppable/index.spec.js +++ b/src/components/withDroppable/index.spec.js @@ -14,7 +14,9 @@ describe('#withDroppable', () => { ) }) - afterEach(() => { subject = undefined }) + afterEach(() => { + subject = undefined + }) it('returns a droppable component', () => { expect(subject.container.querySelector('span > #children')).toBeInTheDocument() diff --git a/src/services/utils.js b/src/services/utils.js index ee07d3d8..12e2c213 100644 --- a/src/services/utils.js +++ b/src/services/utils.js @@ -1,34 +1,34 @@ -function compose (...fns) { +function compose(...fns) { return arg => fns.reduce((acc, fn) => fn(acc), arg) } -function partialRight (fn, ...args) { +function partialRight(fn, ...args) { return (...leftArgs) => fn(...leftArgs, ...args) } -function addInArrayAtPosition (array, element, position) { +function addInArrayAtPosition(array, element, position) { const arrayCopy = [...array] arrayCopy.splice(position, 0, element) return arrayCopy } -function removeFromArrayAtPosition (array, position) { - return array.reduce((acc, value, idx) => idx === position ? acc : [...acc, value], []) +function removeFromArrayAtPosition(array, position) { + return array.reduce((acc, value, idx) => (idx === position ? acc : [...acc, value]), []) } -function changeElementOfPositionInArray (array, from, to) { +function changeElementOfPositionInArray(array, from, to) { const removeFromArrayAtPositionFrom = partialRight(removeFromArrayAtPosition, from) const addInArrayAtPositionTo = partialRight(addInArrayAtPosition, array[from], to) return compose(removeFromArrayAtPositionFrom, addInArrayAtPositionTo)(array) } -function identity (value) { +function identity(value) { return value } -function when (value, predicate = identity) { - return function callback (callback) { +function when(value, predicate = identity) { + return function callback(callback) { if (predicate(value)) return callback(value) } }