forked from mattermost/mattermost-plugin-msteams
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[MI-3825] Add test cases for components #39
Merged
Merged
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
bcf0f7c
[MI-3827]: RTL base setup + downgrade to react 17
SaurabhSharma-884 4571c39
[MI-3827]: Remove error log file & update ui-lib version
SaurabhSharma-884 45a42e7
[MI-3826]: Reducers and Containers test cases
SaurabhSharma-884 9c9f0db
[MI-3826]: Update mockState
SaurabhSharma-884 f886d2c
[MI-3825] Add test cases for components
ayusht2810 3ea5940
[MI-3826]: Update snapshots
SaurabhSharma-884 60881d0
[MI-3825] Remove extra imports and update variable name
ayusht2810 ef4986e
Merge branch 'MI-3826' of github.com:Brightscout/mattermost-plugin-ms…
ayusht2810 c61e382
Merge branch 'epic-ui' of github.com:Brightscout/mattermost-plugin-ms…
ayusht2810 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,4 @@ bin/ | |
|
||
node_modules | ||
|
||
coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. | ||
// See LICENSE.txt for license information. | ||
|
||
const config = { | ||
presets: [ | ||
['@babel/preset-env', { | ||
targets: { | ||
chrome: 66, | ||
firefox: 60, | ||
edge: 42, | ||
safari: 12, | ||
}, | ||
modules: false, | ||
corejs: 3, | ||
debug: false, | ||
useBuiltIns: 'usage', | ||
shippedProposals: true, | ||
}], | ||
['@babel/preset-react', { | ||
useBuiltIns: true, | ||
}], | ||
['@babel/typescript', { | ||
allExtensions: true, | ||
isTSX: true, | ||
}], | ||
], | ||
plugins: [ | ||
'@babel/plugin-proposal-class-properties', | ||
'@babel/plugin-syntax-dynamic-import', | ||
'@babel/plugin-proposal-optional-chaining', | ||
'babel-plugin-typescript-to-proptypes', | ||
], | ||
}; | ||
|
||
// Jest needs module transformation | ||
config.env = { | ||
test: { | ||
presets: config.presets, | ||
plugins: config.plugins, | ||
}, | ||
}; | ||
config.env.test.presets[0][1].modules = 'auto'; | ||
|
||
module.exports = config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/** | ||
* For a detailed explanation regarding each configuration property, visit: | ||
* https://jestjs.io/docs/configuration | ||
*/ | ||
|
||
import type {Config} from 'jest'; | ||
|
||
const config: Config = { | ||
|
||
// Automatically clear mock calls, instances, contexts and results before every test | ||
clearMocks: true, | ||
|
||
// Indicates whether the coverage information should be collected while executing the test | ||
collectCoverage: true, | ||
|
||
// An array of glob patterns indicating a set of files for which coverage information should be collected | ||
collectCoverageFrom: [ | ||
'src/components/**/*.{jsx,tsx}', | ||
'src/reducers/**/*.{js,jsx,ts,tsx}', | ||
'src/containers/**/*.{js,jsx,ts,tsx}', | ||
], | ||
|
||
// The directory where Jest should output its coverage files | ||
coverageDirectory: 'coverage', | ||
|
||
// An array of directory names to be searched recursively up from the requiring module's location | ||
moduleDirectories: [ | ||
'node_modules', | ||
], | ||
|
||
// An array of file extensions your modules use | ||
// moduleFileExtensions: [ | ||
// "js", | ||
// "mjs", | ||
// "cjs", | ||
// "jsx", | ||
// "ts", | ||
// "tsx", | ||
// "json", | ||
// "node" | ||
// ], | ||
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'], | ||
|
||
// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module | ||
moduleNameMapper: { | ||
'^.+\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': 'identity-obj-proxy', | ||
'^.+\\.(css|less|scss)$': 'identity-obj-proxy', | ||
'^src/(.*)': '<rootDir>/src/$1', | ||
'^components/(.*)': '<rootDir>/src/components/$1', | ||
'^constants/(.*)': '<rootDir>/src/constants/$1', | ||
'^components': '<rootDir>/src/components/$1', | ||
'^utils': '<rootDir>/src/utils/$1', | ||
'^selectors': '<rootDir>/src/selectors/$1', | ||
'^hooks/(.*)': '<rootDir>/src/hooks/$1', | ||
'^reducers/(.*)': '<rootDir>/src/reducers/$1', | ||
'^services': '<rootDir>/src/services/$1', | ||
'^tests/(.*)': '<rootDir>/src/tests/$1', | ||
}, | ||
|
||
// A preset that is used as a base for Jest's configuration | ||
preset: 'ts-jest', | ||
|
||
// A list of paths to directories that Jest should use to search for files in | ||
// roots: [ | ||
// "<rootDir>" | ||
// ], | ||
roots: ['<rootDir>/src/'], | ||
|
||
// A list of paths to modules that run some code to configure or set up the testing framework before each test | ||
// setupFilesAfterEnv: [], | ||
setupFilesAfterEnv: [ | ||
'@testing-library/jest-dom', | ||
'<rootDir>/src/tests/setup.ts', | ||
], | ||
|
||
// The test environment that will be used for testing | ||
testEnvironment: 'jsdom', | ||
|
||
// A map from regular expressions to paths to transformers | ||
transform: { | ||
'\\.[jt]sx?$': 'babel-jest', | ||
}, | ||
|
||
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation | ||
// transformIgnorePatterns: [ | ||
// "/node_modules/", | ||
// "\\.pnp\\.[^\\/]+$" | ||
// ], | ||
transformIgnorePatterns: [ | ||
'node_modules/(?!(react-native|react-router|@brightscout)/)', | ||
], | ||
}; | ||
|
||
export default config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import React from 'react'; | ||
|
||
import {render, RenderResult} from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
|
||
import {DialogProps, LinearProgress} from '@brightscout/mattermost-ui-library'; | ||
ayusht2810 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
import {Dialog} from './Dialog.component'; | ||
|
||
const onCloseHandler = jest.fn(); | ||
const onSubmitHandler = jest.fn(); | ||
|
||
const dialogProps = { | ||
onCloseHandler, | ||
onSubmitHandler, | ||
}; | ||
|
||
let tree: RenderResult; | ||
|
||
describe('Dialog', () => { | ||
ayusht2810 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
beforeEach(() => { | ||
tree = render(<Dialog {...dialogProps}/>); | ||
}); | ||
|
||
it('Should render correctly', () => { | ||
expect(tree).toMatchSnapshot(); | ||
}); | ||
|
||
it('Should close the dialog on clicking close button', () => { | ||
expect(tree.getAllByRole('button').length).toEqual(2); | ||
|
||
userEvent.click(tree.getAllByRole('button')[1]); | ||
expect(onCloseHandler).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also Check error thrown by test cases