-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix tests for lib and internal components
* Fix tests for lib/EditableTextInput component * Add preliminary tests for StatusPropertiesLabel
- Loading branch information
1 parent
806f465
commit b908290
Showing
7 changed files
with
92 additions
and
131 deletions.
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 |
---|---|---|
@@ -1,35 +1,30 @@ | ||
const { foremanLocation, foremanRelativePath } = require('@theforeman/find-foreman') | ||
const tfmConfig = require('@theforeman/test/src/pluginConfig'); | ||
const { | ||
foremanRelativePath, | ||
foremanLocation, | ||
} = require('@theforeman/find-foreman'); | ||
|
||
const foremanReactRelative = 'webpack/assets/javascripts/react_app'; | ||
const foremanFull = foremanLocation(); | ||
const foremanReactFull = foremanRelativePath(foremanReactRelative); | ||
|
||
// Jest configuration | ||
module.exports = { | ||
testURL: 'http://localhost/', | ||
setupFiles: [ | ||
'./webpack/test_setup.js', | ||
], | ||
setupFilesAfterEnv: [ | ||
'./webpack/global_test_setup.js', | ||
'@testing-library/jest-dom' | ||
], | ||
testPathIgnorePatterns: [ | ||
'/node_modules/', | ||
'<rootDir>/foreman/', | ||
'<rootDir>/.+fixtures.+', | ||
'<rootDir>/engines', | ||
], | ||
moduleDirectories: [ | ||
`${foremanFull}/node_modules`, | ||
`${foremanFull}/node_modules/@theforeman/vendor-core/node_modules`, | ||
'node_modules', | ||
'webpack/test-utils', | ||
], | ||
modulePathIgnorePatterns: [ | ||
'<rootDir>/foreman/', | ||
], | ||
moduleNameMapper: { | ||
'^.+\\.(css|scss)$': 'identity-obj-proxy', | ||
'^foremanReact(.*)$': `${foremanReactFull}/$1`, | ||
}, | ||
}; | ||
// Find correct path to foremanReact so we do not have to mock it in tests | ||
tfmConfig.moduleNameMapper['^foremanReact(.*)$'] = `${foremanReactFull}/$1`; | ||
|
||
tfmConfig.setupFiles = ['./webpack/test_setup.js']; | ||
tfmConfig.setupFilesAfterEnv = [ | ||
'./webpack/global_test_setup.js', | ||
'@testing-library/jest-dom', | ||
]; | ||
|
||
// Do not use default resolver | ||
tfmConfig.resolver = null; | ||
// Specify module dirs instead | ||
tfmConfig.moduleDirectories = [ | ||
`${foremanFull}/node_modules`, | ||
`${foremanFull}/node_modules/@theforeman/vendor-core/node_modules`, | ||
'node_modules', | ||
'webpack/test-utils', | ||
]; | ||
|
||
module.exports = tfmConfig; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
50 changes: 50 additions & 0 deletions
50
webpack/components/ResourceQuotaForm/components/Properties/StatusPropertiesLabel.test.js
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,50 @@ | ||
/* eslint-disable promise/prefer-await-to-then */ | ||
// Configure Enzyme | ||
import { mount } from '@theforeman/test'; | ||
import React from 'react'; | ||
import { Provider } from 'react-redux'; | ||
import store from 'foremanReact/redux'; | ||
import LabelIcon from 'foremanReact/components/common/LabelIcon'; | ||
import StatusPropertiesLabel from './StatusPropertiesLabel'; | ||
|
||
const defaultProps = { | ||
color: 'blue', | ||
iconChild: <LabelIcon text="test" />, | ||
statusContent: 'some content', | ||
linkUrl: '/test/link', | ||
tooltipText: 'Some nice tooltip', | ||
}; | ||
|
||
describe('StatusPropertiesLabel', () => { | ||
const wrapper = mount( | ||
<Provider store={store}> | ||
<StatusPropertiesLabel {...defaultProps} /> | ||
</Provider> | ||
); | ||
|
||
it('includes components', () => { | ||
expect(wrapper.find('Tooltip').exists()).toBe(true); | ||
expect(wrapper.find('Tooltip')).toHaveLength(1); | ||
expect(wrapper.find('Label').exists()).toBe(true); | ||
expect(wrapper.find('Label')).toHaveLength(1); | ||
expect(wrapper.find('Link').exists()).toBe(true); | ||
expect(wrapper.find('Link')).toHaveLength(1); | ||
}); | ||
|
||
it('passes properties', () => { | ||
// ToolTip | ||
const tooltip = wrapper.find('Tooltip'); | ||
expect(tooltip.props()).toHaveProperty('content'); | ||
expect(tooltip.prop('content')).toContain(defaultProps.tooltipText); | ||
// Label | ||
const label = wrapper.find('Label'); | ||
expect(label.props()).toHaveProperty('icon'); | ||
expect(label.prop('icon')).toEqual(defaultProps.iconChild); | ||
expect(label.props()).toHaveProperty('color'); | ||
expect(label.prop('color')).toEqual(defaultProps.color); | ||
// Link | ||
const link = wrapper.find('Link'); | ||
expect(link.props()).toHaveProperty('to'); | ||
expect(link.prop('to')).toEqual(defaultProps.linkUrl); | ||
}); | ||
}); |
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
File renamed without changes.