1
0
mirror of https://github.com/mattermost/focalboard.git synced 2025-01-17 18:26:17 +02:00

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 {TestBlockFactory} from '../test/testBlockFactory'
import {FetchMock} from '../test/fetchMock' import {FetchMock} from '../test/fetchMock'
import {MutableBoardTree} from './boardTree' import {BoardTree, MutableBoardTree} from './boardTree'
global.fetch = FetchMock.fn global.fetch = FetchMock.fn
@ -30,15 +30,23 @@ test('BoardTree', async () => {
// Sync // Sync
FetchMock.fn.mockReturnValueOnce(FetchMock.jsonResponse(JSON.stringify([board, view, view2, card, cardTemplate]))) 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() expect(boardTree).not.toBeUndefined()
if (!boardTree) { if (!boardTree) {
fail('sync') fail('sync')
} }
expect(FetchMock.fn).toBeCalledTimes(1) expect(FetchMock.fn).toBeCalledTimes(2)
expect(boardTree.board).toEqual(board) expect(boardTree.board).toEqual(board)
expect(boardTree.views).toEqual([view, view2]) expect(boardTree.views).toEqual([view, view2])
expect(boardTree.allCards).toEqual([card]) expect(boardTree.allCards).toEqual([card])
expect(boardTree.orderedCards()).toEqual([card])
expect(boardTree.cardTemplates).toEqual([cardTemplate]) expect(boardTree.cardTemplates).toEqual([cardTemplate])
expect(boardTree.allBlocks).toEqual([board, view, view2, card, cardTemplate]) expect(boardTree.allBlocks).toEqual([board, view, view2, card, cardTemplate])
@ -78,6 +86,7 @@ test('BoardTree', async () => {
expect(boardTree).not.toBe(originalBoardTree) expect(boardTree).not.toBe(originalBoardTree)
expect(boardTree.activeView).toEqual(view) expect(boardTree.activeView).toEqual(view)
expect(boardTree.cards).toEqual([card, card2]) expect(boardTree.cards).toEqual([card, card2])
expect(boardTree.orderedCards()).toEqual([card, card2])
// Group / filter without sort // Group / filter without sort
originalBoardTree = boardTree originalBoardTree = boardTree

View File

@ -24,14 +24,21 @@ test('CardTree', async () => {
const image = TestBlockFactory.createImage(card) const image = TestBlockFactory.createImage(card)
const divider = TestBlockFactory.createDivider(card) const divider = TestBlockFactory.createDivider(card)
let cardTree: CardTree | undefined
FetchMock.fn.mockReturnValueOnce(FetchMock.jsonResponse(JSON.stringify([card, comment, text, image, divider]))) 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() expect(cardTree).not.toBeUndefined()
if (!cardTree) { if (!cardTree) {
fail('sync') fail('sync')
} }
expect(FetchMock.fn).toBeCalledTimes(1) expect(FetchMock.fn).toBeCalledTimes(2)
expect(cardTree.card).toEqual(card) expect(cardTree.card).toEqual(card)
expect(cardTree.comments).toEqual([comment]) expect(cardTree.comments).toEqual([comment])
expect(cardTree.contents).toEqual([text, image, divider]) expect(cardTree.contents).toEqual([text, image, divider])

View File

@ -61,9 +61,9 @@ class MutableCardTree implements CardTree {
return cardTree return cardTree
} }
private mutableCopy(): MutableCardTree { // private mutableCopy(): MutableCardTree {
return MutableCardTree.buildTree(this.card.id, this.allBlocks)! // return MutableCardTree.buildTree(this.card.id, this.allBlocks)!
} // }
} }
export {MutableCardTree, CardTree} export {MutableCardTree, CardTree}

View File

@ -55,9 +55,9 @@ class MutableWorkspaceTree {
return workspaceTree return workspaceTree
} }
private mutableCopy(): MutableWorkspaceTree { // private mutableCopy(): MutableWorkspaceTree {
return MutableWorkspaceTree.buildTree(this.allBlocks)! // return MutableWorkspaceTree.buildTree(this.allBlocks)!
} // }
} }
export {MutableWorkspaceTree, WorkspaceTree} export {MutableWorkspaceTree, WorkspaceTree}