focalboard/webapp/src/octoClient.test.ts

83 lines
2.4 KiB
TypeScript
Raw Normal View History

2020-12-07 23:50:22 +01:00
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
// Disable console log
console.log = jest.fn()
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
import {Block} from './blocks/block'
import {createBoard} from './blocks/board'
2020-12-07 23:50:22 +01:00
import octoClient from './octoClient'
import 'isomorphic-fetch'
2020-12-08 00:40:32 +01:00
import {FetchMock} from './test/fetchMock'
2020-12-07 23:50:22 +01:00
2020-12-08 00:40:32 +01:00
global.fetch = FetchMock.fn
2020-12-07 23:50:22 +01:00
beforeEach(() => {
2020-12-08 00:40:32 +01:00
FetchMock.fn.mockReset()
2020-12-07 23:50:22 +01:00
})
test('OctoClient: get blocks', async () => {
const blocks = createBoards()
2020-12-08 00:40:32 +01:00
FetchMock.fn.mockReturnValueOnce(FetchMock.jsonResponse(JSON.stringify(blocks)))
2020-12-07 23:50:22 +01:00
let boards = await octoClient.getBlocksWithType('board')
expect(boards.length).toBe(blocks.length)
2020-12-08 00:40:32 +01:00
FetchMock.fn.mockReturnValueOnce(FetchMock.jsonResponse(JSON.stringify(blocks)))
2020-12-07 23:50:22 +01:00
boards = await octoClient.getSubtree()
expect(boards.length).toBe(blocks.length)
2020-12-08 00:40:32 +01:00
FetchMock.fn.mockReturnValueOnce(FetchMock.jsonResponse(JSON.stringify(blocks)))
boards = await octoClient.exportArchive()
2020-12-07 23:50:22 +01:00
expect(boards.length).toBe(blocks.length)
2020-12-08 00:40:32 +01:00
FetchMock.fn.mockReturnValueOnce(FetchMock.jsonResponse(JSON.stringify(blocks)))
2020-12-07 23:50:22 +01:00
const parentId = 'id1'
boards = await octoClient.getBlocksWithParent(parentId)
expect(boards.length).toBe(blocks.length)
2020-12-08 00:40:32 +01:00
FetchMock.fn.mockReturnValueOnce(FetchMock.jsonResponse(JSON.stringify(blocks)))
2020-12-07 23:50:22 +01:00
boards = await octoClient.getBlocksWithParent(parentId, 'board')
expect(boards.length).toBe(blocks.length)
})
test('OctoClient: insert blocks', async () => {
const blocks = createBoards()
await octoClient.insertBlocks(blocks)
2020-12-08 00:40:32 +01:00
expect(FetchMock.fn).toBeCalledTimes(1)
expect(FetchMock.fn).toHaveBeenCalledWith(
2020-12-07 23:50:22 +01:00
expect.anything(),
expect.objectContaining({
method: 'POST',
body: JSON.stringify(blocks),
}))
})
test('OctoClient: importFullArchive', async () => {
const blocks = createBoards()
await octoClient.importFullArchive(blocks)
2020-12-08 00:40:32 +01:00
expect(FetchMock.fn).toBeCalledTimes(1)
expect(FetchMock.fn).toHaveBeenCalledWith(
2020-12-07 23:50:22 +01:00
expect.anything(),
expect.objectContaining({
method: 'POST',
body: JSON.stringify(blocks),
}))
})
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
function createBoards(): Block[] {
2020-12-07 23:50:22 +01:00
const blocks = []
for (let i = 0; i < 5; i++) {
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
const board = createBoard()
2020-12-07 23:50:22 +01:00
board.id = `board${i + 1}`
blocks.push(board)
}
return blocks
}