imageElement.test.tsx
TLDR
This file is a test file for the ImageElement component. It contains tests to verify the behavior and rendering of the ImageElement component under different conditions.
Methods
This file does not contain any methods.
Classes
ImageElement
The ImageElement
class is a component that renders an image element. It receives a block
prop which represents the image block being displayed. The component fetches the image file and renders it.
-
wrapIntl(component: React.ReactElement)
: This method wraps the provided component with an internationalization context. It is used to ensure that the component has access to the required internationalization functions.
END
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React from 'react'
import {render} from '@testing-library/react'
import {act} from 'react-dom/test-utils'
import {mocked} from 'jest-mock'
import {ImageBlock} from '../../blocks/imageBlock'
import {wrapIntl} from '../../testUtils'
import octoClient from '../../octoClient'
import ImageElement from './imageElement'
jest.mock('../../octoClient')
const mockedOcto = mocked(octoClient, true)
mockedOcto.getFileAsDataUrl.mockResolvedValue({url: 'test.jpg'})
describe('components/content/ImageElement', () => {
const defaultBlock: ImageBlock = {
id: 'test-id',
boardId: '1',
parentId: '',
modifiedBy: 'test-user-id',
schema: 0,
type: 'image',
title: 'test-title',
fields: {
fileId: 'test.jpg',
},
createdBy: 'test-user-id',
createAt: 0,
updateAt: 0,
deleteAt: 0,
limited: false,
}
test('should match snapshot', async () => {
const component = wrapIntl(
<ImageElement
block={defaultBlock}
/>,
)
let imageContainer: Element | undefined
await act(async () => {
const {container} = render(component)
imageContainer = container
})
expect(imageContainer).toMatchSnapshot()
})
test('archived file', async () => {
mockedOcto.getFileAsDataUrl.mockResolvedValue({
archived: true,
name: 'Filename',
extension: '.txt',
size: 165002,
})
const component = wrapIntl(
<ImageElement
block={defaultBlock}
/>,
)
let imageContainer: Element | undefined
await act(async () => {
const {container} = render(component)
imageContainer = container
})
expect(imageContainer).toMatchSnapshot()
})
})