1
0
mirror of https://github.com/mattermost/focalboard.git synced 2025-03-06 15:36:17 +02:00

Unit test for ContentElement fixed. (#1547)

This commit is contained in:
kamre 2021-10-13 22:06:57 +07:00 committed by GitHub
parent 45904613ec
commit 64fdeef893
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 52 additions and 37 deletions

View File

@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`components/content/contentElement return an element 1`] = ` exports[`components/content/contentElement should match snapshot for checkbox type 1`] = `
<div> <div>
<div <div
class="CheckboxElement" class="CheckboxElement"

View File

@ -1,52 +1,67 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information. // See LICENSE.txt for license information.
import React, {ReactElement, ReactNode} from 'react'
import '@testing-library/jest-dom'
import {render} from '@testing-library/react' import {render} from '@testing-library/react'
import {wrapIntl} from '../../testUtils' import {wrapIntl} from '../../testUtils'
import {ContentBlock} from '../../blocks/contentBlock' import {ContentBlock} from '../../blocks/contentBlock'
import {CardDetailProvider} from '../cardDetail/cardDetailContext'
import {TestBlockFactory} from '../../test/testBlockFactory'
import ContentElement from './contentElement' import ContentElement from './contentElement'
const board = TestBlockFactory.createBoard()
const card = TestBlockFactory.createCard(board)
const contentBlock: ContentBlock = {
id: 'test-id',
workspaceId: '',
parentId: card.id,
rootId: card.rootId,
modifiedBy: 'test-user-id',
schema: 0,
type: 'checkbox',
title: 'test-title',
fields: {},
createdBy: 'test-user-id',
createAt: 0,
updateAt: 0,
deleteAt: 0,
}
const wrap = (child: ReactNode): ReactElement => (
wrapIntl(
<CardDetailProvider card={card}>
{child}
</CardDetailProvider>,
)
)
describe('components/content/contentElement', () => { describe('components/content/contentElement', () => {
test('return an element', () => { it('should match snapshot for checkbox type', () => {
const contentBlock: ContentBlock = { const {container} = render(wrap(
id: 'test-id', <ContentElement
workspaceId: '', block={contentBlock}
parentId: '', readonly={false}
rootId: '', cords={{x: 0}}
modifiedBy: 'test-user-id', />,
schema: 0, ))
type: 'checkbox',
title: 'test-title',
fields: {},
createdBy: 'test-user-id',
createAt: 0,
updateAt: 0,
deleteAt: 0,
}
const checkBoxElement = ContentElement({block: contentBlock, readonly: false})
const {container} = render(wrapIntl(checkBoxElement))
expect(container).toMatchSnapshot() expect(container).toMatchSnapshot()
}) })
test('return null', () => { it('should return null for unknown type', () => {
const contentBlock: ContentBlock = { const block: ContentBlock = {...contentBlock, type: 'unknown'}
id: 'test-id', const {container} = render(wrap(
workspaceId: '', <ContentElement
parentId: '', block={block}
rootId: '', readonly={false}
modifiedBy: 'test-user-id', cords={{x: 0}}
schema: 0, />,
type: 'unknown', ))
title: 'test-title', expect(container).toBeEmptyDOMElement()
fields: {},
createdBy: 'test-user-id',
createAt: 0,
updateAt: 0,
deleteAt: 0,
}
const contentElement = ContentElement({block: contentBlock, readonly: false})
expect(contentElement).toBeNull()
}) })
}) })