From b02708173a39103dca27da7578d27d4db90bc4ad Mon Sep 17 00:00:00 2001 From: Julien Fabre Date: Mon, 4 Oct 2021 06:22:30 +0200 Subject: [PATCH] [GH-864]: add tests unit for viewHeader (#1413) * chore[GH-#864]: add test unit for viewHeader * fix: eslint import useless --- .../__snapshots__/viewHeader.test.tsx.snap | 183 ++++++++++++++++++ .../components/viewHeader/viewHeader.test.tsx | 82 ++++++++ webapp/src/testUtils.tsx | 7 + 3 files changed, 272 insertions(+) create mode 100644 webapp/src/components/viewHeader/__snapshots__/viewHeader.test.tsx.snap create mode 100644 webapp/src/components/viewHeader/viewHeader.test.tsx diff --git a/webapp/src/components/viewHeader/__snapshots__/viewHeader.test.tsx.snap b/webapp/src/components/viewHeader/__snapshots__/viewHeader.test.tsx.snap new file mode 100644 index 000000000..d91baf3c8 --- /dev/null +++ b/webapp/src/components/viewHeader/__snapshots__/viewHeader.test.tsx.snap @@ -0,0 +1,183 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`components/viewHeader/viewHeader return viewHeader 1`] = ` +
+
+ + +
+ + +
+ +
+ + +
+ +
+
+
+ New +
+ +
+
+
+`; + +exports[`components/viewHeader/viewHeader return viewHeader readonly 1`] = ` +
+
+ + +
+ +
+
+`; diff --git a/webapp/src/components/viewHeader/viewHeader.test.tsx b/webapp/src/components/viewHeader/viewHeader.test.tsx new file mode 100644 index 000000000..66f7e3e6c --- /dev/null +++ b/webapp/src/components/viewHeader/viewHeader.test.tsx @@ -0,0 +1,82 @@ +// 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 {Provider as ReduxProvider} from 'react-redux' + +import '@testing-library/jest-dom' + +import {TestBlockFactory} from '../../test/testBlockFactory' + +import {wrapIntl, mockStateStore} from '../../testUtils' + +import ViewHeader from './viewHeader' + +const board = TestBlockFactory.createBoard() +const activeView = TestBlockFactory.createBoardView(board) +const card = TestBlockFactory.createCard(board) + +describe('components/viewHeader/viewHeader', () => { + const state = { + users: { + me: { + id: 'user-id-1', + username: 'username_1', + }, + }, + searchText: { + }, + boards: { + current: board, + }, + cards: { + templates: [card], + }, + } + const store = mockStateStore([], state) + test('return viewHeader', () => { + const {container} = render( + wrapIntl( + + + , + ), + ) + expect(container).toMatchSnapshot() + }) + test('return viewHeader readonly', () => { + const {container} = render( + wrapIntl( + + + , + ), + ) + expect(container).toMatchSnapshot() + }) +}) diff --git a/webapp/src/testUtils.tsx b/webapp/src/testUtils.tsx index 61e368ab4..4b19622a5 100644 --- a/webapp/src/testUtils.tsx +++ b/webapp/src/testUtils.tsx @@ -2,6 +2,8 @@ // See LICENSE.txt for license information. import {IntlProvider} from 'react-intl' import React from 'react' +import configureStore, {MockStoreEnhanced} from 'redux-mock-store' +import {Middleware} from 'redux' export const wrapIntl = (children?: React.ReactNode): JSX.Element => {children} @@ -39,3 +41,8 @@ export function mockMatchMedia(result: any): void { }), }) } + +export function mockStateStore(middleware:Middleware[], state:unknown): MockStoreEnhanced { + const mockStore = configureStore(middleware) + return mockStore(state) +}