From 5808b848c39fbae74189a2176877de3b848e6b79 Mon Sep 17 00:00:00 2001 From: M-ZubairAhmed Date: Thu, 18 May 2023 17:40:12 +0530 Subject: [PATCH] MM-52213 webapp/platform/components : Add unit test framework (#23366) --- webapp/platform/components/babel.config.js | 15 ++ webapp/platform/components/jest.config.js | 21 ++ webapp/platform/components/package.json | 1 + .../legacy_generic_modal.test.tsx.snap | 143 +++++++++++++ .../footer_pagination.test.tsx.snap | 201 ++++++++++++++---- .../footer_content/footer_pagination.test.tsx | 77 ++----- .../legacy_generic_modal.test.tsx | 39 ++++ webapp/platform/components/src/setupTests.ts | 4 + webapp/platform/components/src/testUtils.tsx | 13 ++ .../components/src/tour_tip/tour_tip.tsx | 1 - 10 files changed, 414 insertions(+), 101 deletions(-) create mode 100644 webapp/platform/components/jest.config.js create mode 100644 webapp/platform/components/src/legacy_generic_modal/__snapshots__/legacy_generic_modal.test.tsx.snap create mode 100644 webapp/platform/components/src/legacy_generic_modal/legacy_generic_modal.test.tsx create mode 100644 webapp/platform/components/src/setupTests.ts create mode 100644 webapp/platform/components/src/testUtils.tsx diff --git a/webapp/platform/components/babel.config.js b/webapp/platform/components/babel.config.js index 641b2cf2e8..06f9099d35 100644 --- a/webapp/platform/components/babel.config.js +++ b/webapp/platform/components/babel.config.js @@ -11,6 +11,13 @@ const config = { safari: 12, }, modules: false, + corejs: { + version: "3.26", + proposals: true, + }, + debug: false, + shippedProposals: true, + useBuiltIns: 'usage', }], ['@babel/preset-react', { useBuiltIns: true, @@ -39,4 +46,12 @@ const config = { ], }; +config.env = { + test: { + presets: config.presets, + plugins: config.plugins, + }, +}; +config.env.test.presets[0][1].modules = 'auto'; + module.exports = config; diff --git a/webapp/platform/components/jest.config.js b/webapp/platform/components/jest.config.js new file mode 100644 index 0000000000..8c1d80cb89 --- /dev/null +++ b/webapp/platform/components/jest.config.js @@ -0,0 +1,21 @@ +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// See LICENSE.txt for license information. + +/** @type {import('jest').Config} */ + +const config = { + moduleDirectories: ['src', 'node_modules'], + testEnvironment: 'jsdom', + testPathIgnorePatterns: ['/node_modules/', '/.rollup.cache/', '/dist/'], + clearMocks: true, + moduleNameMapper: { + '^@mattermost/(components)$': '/../platform/$1/src', + '^@mattermost/(client)$': '/../platform/$1/src', + '^@mattermost/(types)/(.*)$': '/../platform/$1/src/$2', + '^.+\\.(css|scss)$': 'identity-obj-proxy', + }, + moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'], + setupFilesAfterEnv: ['/src/setupTests.ts'], +}; + +module.exports = config; diff --git a/webapp/platform/components/package.json b/webapp/platform/components/package.json index 0675cc5a53..8324322d63 100644 --- a/webapp/platform/components/package.json +++ b/webapp/platform/components/package.json @@ -7,6 +7,7 @@ "scripts": { "build": "rollup -c", "run": "rollup -c --watch", + "test": "cross-env TZ=Etc/UTC jest", "clean": "rm -rf dist node_modules tsconfig.tsbuildinfo .rollup.cache" }, "devDependencies": { diff --git a/webapp/platform/components/src/legacy_generic_modal/__snapshots__/legacy_generic_modal.test.tsx.snap b/webapp/platform/components/src/legacy_generic_modal/__snapshots__/legacy_generic_modal.test.tsx.snap new file mode 100644 index 0000000000..c43b2c8d65 --- /dev/null +++ b/webapp/platform/components/src/legacy_generic_modal/__snapshots__/legacy_generic_modal.test.tsx.snap @@ -0,0 +1,143 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`LegacyGenericModal should match snapshot for base case 1`] = ` +Object { + "asFragment": [Function], + "baseElement": +