diff --git a/webapp/boards/src/components/boardsUnfurl/__snapshots__/boardsUnfurl.test.tsx.snap b/webapp/boards/src/components/boardsUnfurl/__snapshots__/boardsUnfurl.test.tsx.snap index bbf4ddc411..cfe233747c 100644 --- a/webapp/boards/src/components/boardsUnfurl/__snapshots__/boardsUnfurl.test.tsx.snap +++ b/webapp/boards/src/components/boardsUnfurl/__snapshots__/boardsUnfurl.test.tsx.snap @@ -96,3 +96,9 @@ exports[`components/boardsUnfurl/BoardsUnfurl renders when limited 1`] = ` `; + +exports[`components/boardsUnfurl/BoardsUnfurl test invalid card, invalid block 1`] = `
`; + +exports[`components/boardsUnfurl/BoardsUnfurl test invalid card, valid block 1`] = `
`; + +exports[`components/boardsUnfurl/BoardsUnfurl test no card 1`] = `
`; diff --git a/webapp/boards/src/components/boardsUnfurl/boardsUnfurl.test.tsx b/webapp/boards/src/components/boardsUnfurl/boardsUnfurl.test.tsx index 81b11ae171..6afe19042b 100644 --- a/webapp/boards/src/components/boardsUnfurl/boardsUnfurl.test.tsx +++ b/webapp/boards/src/components/boardsUnfurl/boardsUnfurl.test.tsx @@ -16,6 +16,8 @@ import {createBoard} from 'src/blocks/board' import octoClient from 'src/octoClient' import {wrapIntl} from 'src/testUtils' +import {createBoardView} from 'src/blocks/boardView' + import BoardsUnfurl from './boardsUnfurl' jest.mock('src/octoClient') @@ -114,5 +116,118 @@ describe('components/boardsUnfurl/BoardsUnfurl', () => { expect(container).toMatchSnapshot() }) + + it('test no card', async () => { + const mockStore = configureStore([]) + const store = mockStore({ + language: { + value: 'en', + }, + teams: { + allTeams: [team], + current: team, + }, + }) + + const board = {...createBoard(), title: 'test board'} + // mockedOctoClient.getBoard.mockResolvedValueOnce(board) + + const component = ( + + {wrapIntl( + , + )} + + ) + + let container: Element | DocumentFragment | null = null + + await act(async () => { + const result = render(component) + container = result.container + }) + expect(container).toMatchSnapshot() + }) + + it('test invalid card, valid block', async () => { + const mockStore = configureStore([]) + const store = mockStore({ + language: { + value: 'en', + }, + teams: { + allTeams: [team], + current: team, + }, + }) + + const cards = [{...createBoardView(), title: 'test view', updateAt: 12345}] + const board = {...createBoard(), title: 'test board'} + + mockedOctoClient.getBlocksWithBlockID.mockResolvedValueOnce(cards) + mockedOctoClient.getBoard.mockResolvedValueOnce(board) + + const component = ( + + {wrapIntl( + , + )} + + ) + + let container: Element | DocumentFragment | null = null + + await act(async () => { + const result = render(component) + container = result.container + }) + expect(mockedOctoClient.getBoard).toBeCalledWith(board.id) + expect(mockedOctoClient.getBlocksWithBlockID).toBeCalledWith(cards[0].id, board.id, 'abc') + + expect(container).toMatchSnapshot() + }) + + it('test invalid card, invalid block', async () => { + const mockStore = configureStore([]) + const store = mockStore({ + language: { + value: 'en', + }, + teams: { + allTeams: [team], + current: team, + }, + }) + + const board = {...createBoard(), title: 'test board'} + + mockedOctoClient.getBlocksWithBlockID.mockResolvedValueOnce([]) + mockedOctoClient.getBoard.mockResolvedValueOnce(board) + + const component = ( + + {wrapIntl( + , + )} + + ) + + let container: Element | DocumentFragment | null = null + + await act(async () => { + const result = render(component) + container = result.container + }) + expect(mockedOctoClient.getBoard).toBeCalledWith(board.id) + expect(mockedOctoClient.getBlocksWithBlockID).toBeCalledWith('invalidCard', board.id, 'abc') + + expect(container).toMatchSnapshot() + }) }) diff --git a/webapp/boards/src/components/boardsUnfurl/boardsUnfurl.tsx b/webapp/boards/src/components/boardsUnfurl/boardsUnfurl.tsx index dcb741b591..08a9f5eb51 100644 --- a/webapp/boards/src/components/boardsUnfurl/boardsUnfurl.tsx +++ b/webapp/boards/src/components/boardsUnfurl/boardsUnfurl.tsx @@ -84,7 +84,7 @@ export const BoardsUnfurl = (props: Props): JSX.Element => { ], ) const [firstCard] = cards as Card[] - if (!firstCard || !fetchedBoard) { + if (!firstCard || !fetchedBoard || firstCard.type !== 'card') { setLoading(false) return null } @@ -116,7 +116,7 @@ export const BoardsUnfurl = (props: Props): JSX.Element => { useWebsockets(currentTeamId, (wsClient: WSClient) => { const onChangeHandler = (_: WSClient, blocks: Block[]): void => { const cardBlock: Block|undefined = blocks.find((b) => b.id === cardID) - if (cardBlock && !cardBlock.deleteAt) { + if (cardBlock && !cardBlock.deleteAt && cardBlock.type === 'card') { setCard(cardBlock as Card) }