Update unit tests

This commit is contained in:
Chen-I Lim 2020-12-09 19:47:52 -08:00
parent 6faf3cef63
commit 2574027f9c
4 changed files with 27 additions and 11 deletions

View file

@ -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

View file

@ -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])

View file

@ -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}

View file

@ -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}