From 9ca5cd6a877c154f528b9d5ff56e49aed33173a4 Mon Sep 17 00:00:00 2001 From: Julien Fabre Date: Sat, 9 Oct 2021 01:38:14 +0200 Subject: [PATCH] chore[GH-#849]: Add unit test for imageElement (#1502) --- .../__snapshots__/imageElement.test.tsx.snap | 11 ++++ .../components/content/imageElement.test.tsx | 55 +++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 webapp/src/components/content/__snapshots__/imageElement.test.tsx.snap create mode 100644 webapp/src/components/content/imageElement.test.tsx diff --git a/webapp/src/components/content/__snapshots__/imageElement.test.tsx.snap b/webapp/src/components/content/__snapshots__/imageElement.test.tsx.snap new file mode 100644 index 000000000..72c72dec9 --- /dev/null +++ b/webapp/src/components/content/__snapshots__/imageElement.test.tsx.snap @@ -0,0 +1,11 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`components/content/ImageElement should match snapshot 1`] = ` +
+ test-title +
+`; diff --git a/webapp/src/components/content/imageElement.test.tsx b/webapp/src/components/content/imageElement.test.tsx new file mode 100644 index 000000000..410299a20 --- /dev/null +++ b/webapp/src/components/content/imageElement.test.tsx @@ -0,0 +1,55 @@ +// 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 'ts-jest/utils' + +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('test.jpg') + +describe('components/content/ImageElement', () => { + const defaultBlock: ImageBlock = { + id: 'test-id', + workspaceId: '', + parentId: '', + rootId: '1', + 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, + } + + test('should match snapshot', async () => { + const component = wrapIntl( + , + ) + let imageContainer: Element | undefined + await act(async () => { + const {container} = render(component) + imageContainer = container + }) + expect(imageContainer).toMatchSnapshot() + }) +})