From 2574027f9c54d71584563ba8fe1bfb98fc3ef5e8 Mon Sep 17 00:00:00 2001 From: Chen-I Lim Date: Wed, 9 Dec 2020 19:47:52 -0800 Subject: [PATCH] Update unit tests --- webapp/src/viewModel/boardTree.test.ts | 15 ++++++++++++--- webapp/src/viewModel/cardTree.test.ts | 11 +++++++++-- webapp/src/viewModel/cardTree.ts | 6 +++--- webapp/src/viewModel/workspaceTree.ts | 6 +++--- 4 files changed, 27 insertions(+), 11 deletions(-) diff --git a/webapp/src/viewModel/boardTree.test.ts b/webapp/src/viewModel/boardTree.test.ts index d9e668383..759e970ab 100644 --- a/webapp/src/viewModel/boardTree.test.ts +++ b/webapp/src/viewModel/boardTree.test.ts @@ -9,7 +9,7 @@ import 'isomorphic-fetch' import {TestBlockFactory} from '../test/testBlockFactory' import {FetchMock} from '../test/fetchMock' -import {MutableBoardTree} from './boardTree' +import {BoardTree, MutableBoardTree} from './boardTree' global.fetch = FetchMock.fn @@ -30,15 +30,23 @@ test('BoardTree', async () => { // Sync FetchMock.fn.mockReturnValueOnce(FetchMock.jsonResponse(JSON.stringify([board, view, view2, card, cardTemplate]))) - let boardTree = await MutableBoardTree.sync(board.id, view.id) + let boardTree: BoardTree | undefined + + boardTree = await MutableBoardTree.sync('invalid_id', 'invalid_id') + expect(boardTree).toBeUndefined() + expect(FetchMock.fn).toBeCalledTimes(1) + + FetchMock.fn.mockReturnValueOnce(FetchMock.jsonResponse(JSON.stringify([board, view, view2, card, cardTemplate]))) + boardTree = await MutableBoardTree.sync(board.id, view.id) expect(boardTree).not.toBeUndefined() if (!boardTree) { fail('sync') } - expect(FetchMock.fn).toBeCalledTimes(1) + expect(FetchMock.fn).toBeCalledTimes(2) expect(boardTree.board).toEqual(board) expect(boardTree.views).toEqual([view, view2]) expect(boardTree.allCards).toEqual([card]) + expect(boardTree.orderedCards()).toEqual([card]) expect(boardTree.cardTemplates).toEqual([cardTemplate]) expect(boardTree.allBlocks).toEqual([board, view, view2, card, cardTemplate]) @@ -78,6 +86,7 @@ test('BoardTree', async () => { expect(boardTree).not.toBe(originalBoardTree) expect(boardTree.activeView).toEqual(view) expect(boardTree.cards).toEqual([card, card2]) + expect(boardTree.orderedCards()).toEqual([card, card2]) // Group / filter without sort originalBoardTree = boardTree diff --git a/webapp/src/viewModel/cardTree.test.ts b/webapp/src/viewModel/cardTree.test.ts index 96a892335..288d219e1 100644 --- a/webapp/src/viewModel/cardTree.test.ts +++ b/webapp/src/viewModel/cardTree.test.ts @@ -24,14 +24,21 @@ test('CardTree', async () => { const image = TestBlockFactory.createImage(card) const divider = TestBlockFactory.createDivider(card) + let cardTree: CardTree | undefined + FetchMock.fn.mockReturnValueOnce(FetchMock.jsonResponse(JSON.stringify([card, comment, text, image, divider]))) - let cardTree: CardTree | undefined = await MutableCardTree.sync(card.id) + cardTree = await MutableCardTree.sync('invalid_id') + expect(cardTree).toBeUndefined() + expect(FetchMock.fn).toBeCalledTimes(1) + + FetchMock.fn.mockReturnValueOnce(FetchMock.jsonResponse(JSON.stringify([card, comment, text, image, divider]))) + cardTree = await MutableCardTree.sync(card.id) expect(cardTree).not.toBeUndefined() if (!cardTree) { fail('sync') } - expect(FetchMock.fn).toBeCalledTimes(1) + expect(FetchMock.fn).toBeCalledTimes(2) expect(cardTree.card).toEqual(card) expect(cardTree.comments).toEqual([comment]) expect(cardTree.contents).toEqual([text, image, divider]) diff --git a/webapp/src/viewModel/cardTree.ts b/webapp/src/viewModel/cardTree.ts index 725ac1958..16db04e87 100644 --- a/webapp/src/viewModel/cardTree.ts +++ b/webapp/src/viewModel/cardTree.ts @@ -61,9 +61,9 @@ class MutableCardTree implements CardTree { return cardTree } - private mutableCopy(): MutableCardTree { - return MutableCardTree.buildTree(this.card.id, this.allBlocks)! - } + // private mutableCopy(): MutableCardTree { + // return MutableCardTree.buildTree(this.card.id, this.allBlocks)! + // } } export {MutableCardTree, CardTree} diff --git a/webapp/src/viewModel/workspaceTree.ts b/webapp/src/viewModel/workspaceTree.ts index a6d3608c0..956b0f55a 100644 --- a/webapp/src/viewModel/workspaceTree.ts +++ b/webapp/src/viewModel/workspaceTree.ts @@ -55,9 +55,9 @@ class MutableWorkspaceTree { return workspaceTree } - private mutableCopy(): MutableWorkspaceTree { - return MutableWorkspaceTree.buildTree(this.allBlocks)! - } + // private mutableCopy(): MutableWorkspaceTree { + // return MutableWorkspaceTree.buildTree(this.allBlocks)! + // } } export {MutableWorkspaceTree, WorkspaceTree}