focalboard/webapp/src/octoUtils.test.ts
Jesús Espino be28b7dad5
Migrate webapp global state to redux (#737)
* Migrating workspace tree to redux

* More changes for use the redux store for boads and views

* Taking into account the templates on websocket event updates

* Fixing bug on boardTree maintenance

* Websocket client now connects once and subscribe/desubscribe on the fly

* Including usage of the new websocket client

* More work around migrating to redux

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* Fixing some things

* WIP

* WIP

* Another small fix

* Restoring filtering, sorting and grouping

* Fixing some other bugs

* Add search text reducer

* Fixing another drag and drop problem

* Improve store names and api

* Fixing small bgus

* Some small fixes

* fixing login

* Fixing register page

* Some other improvements

* Removing unneeded old files

* Removing the need of userCache

* Fixing comments and fixing content ordering

* Fixing sort

* Fixing some TODOs

* Fixing tests

* Fixing snapshot

* Fixing cypress tests

* Fix eslint

* Fixing server tests

* Updating the add cards actions

* Fixing some tiny navigation problems

* Mocking the api calls to pass the tests

* Migrating a new test to redux

* Adding the card right after the insert of the block (not wait for ws event)

* Showing the ws disconnect banner only after 5 seconds of disconnection

* Fixing share view

* Fix eslint

* Fixing problem with sort/groupby modifications

* Fixing some details on redirections and templates creation

* Fixing small bugs around undo

* Fix update properties on click outside the dialog

* Improving the column resize look and feel

* Removing the class based objects from the store (now they are all plain objects

* Fix eslint

* Fixing tests

* Removing unneeded code
2021-08-02 17:46:00 +02:00

91 lines
2.7 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {Block} from './blocks/block'
import {OctoUtils} from './octoUtils'
import {TestBlockFactory} from './test/testBlockFactory'
test('duplicateBlockTree: Board', async () => {
const [blocks, sourceBlock] = createBoardTree()
const [newBlocks, newSourceBlock, idMap] = OctoUtils.duplicateBlockTree(blocks, sourceBlock.id)
expect(newBlocks.length).toBe(blocks.length)
expect(newSourceBlock.id).not.toBe(sourceBlock)
expect(newSourceBlock.type).toBe(sourceBlock.type)
// When duplicating a root block, the rootId should be re-mapped
expect(newSourceBlock.rootId).not.toBe(sourceBlock.rootId)
expect(idMap[sourceBlock.id]).toBe(newSourceBlock.id)
for (const newBlock of newBlocks) {
expect(newBlock.rootId).toBe(newSourceBlock.id)
}
for (const textBlock of newBlocks.filter((o) => o.type === 'card')) {
expect(textBlock.parentId).toBe(newSourceBlock.id)
}
})
test('duplicateBlockTree: Card', async () => {
const [blocks, sourceBlock] = createCardTree()
const [newBlocks, newSourceBlock, idMap] = OctoUtils.duplicateBlockTree(blocks, sourceBlock.id)
expect(newBlocks.length).toBe(blocks.length)
expect(newSourceBlock.id).not.toBe(sourceBlock.id)
expect(newSourceBlock.type).toBe(sourceBlock.type)
// When duplicating a non-root block, the rootId should not be re-mapped
expect(newSourceBlock.rootId).toBe(sourceBlock.rootId)
expect(idMap[sourceBlock.id]).toBe(newSourceBlock.id)
for (const newBlock of newBlocks) {
expect(newBlock.rootId).toBe(newSourceBlock.rootId)
}
for (const textBlock of newBlocks.filter((o) => o.type === 'text')) {
expect(textBlock.parentId).toBe(newSourceBlock.id)
}
})
function createBoardTree(): [Block[], Block] {
const blocks: Block[] = []
const board = TestBlockFactory.createBoard()
board.id = 'board1'
board.rootId = board.id
blocks.push(board)
for (let i = 0; i < 5; i++) {
const card = TestBlockFactory.createCard(board)
card.id = `card${i}`
blocks.push(card)
for (let j = 0; j < 3; j++) {
const textBlock = TestBlockFactory.createText(card)
textBlock.id = `text${j}`
blocks.push(textBlock)
}
}
return [blocks, board]
}
function createCardTree(): [Block[], Block] {
const blocks: Block[] = []
const card = TestBlockFactory.createCard()
card.id = 'card1'
card.rootId = 'board1'
blocks.push(card)
for (let i = 0; i < 5; i++) {
const textBlock = TestBlockFactory.createText(card)
textBlock.id = `text${i}`
blocks.push(textBlock)
}
return [blocks, card]
}