Skip to content
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

Fixes #29637 - Allow jest testing to use foremanReact #8682

Merged
merged 1 commit into from
May 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
64 changes: 64 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
const path = require('path');
const fs = require('fs');

// Check for foremanReact files provided by Foreman and make available as module in Jest.
const checkForForemanReact = (foremanLocations, foremanReact) => {
const currentDir = process.cwd();

let foremanReactFullPath;
foremanLocations.forEach((relativeForemanPath) => {
if (fs.existsSync(path.join(currentDir, relativeForemanPath))) {
const fullPath = path.join(currentDir, relativeForemanPath, foremanReact);
if (fs.existsSync(fullPath)) foremanReactFullPath = fullPath;
}
});
return foremanReactFullPath;
};

const foremanReactRelative = 'webpack/assets/javascripts/react_app';
const possibleForemanLocations = ['./foreman', '../foreman', '../../foreman'];
const notFound = 'Foreman directory cannot be found! These tests require Foreman to be present ' +
'in either a parent, sibling, or child directory relative to Katello and contain the expected ' +
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was about to ask who in their right mind would put the foreman directory inside of Katello, but then saw the other PR comments 😆

`files in foreman/${foremanReactRelative}.`;

const foremanReactFull = checkForForemanReact(possibleForemanLocations, foremanReactRelative);
if (!foremanReactFull) throw new Error(notFound);

// Jest configuration
module.exports = {
collectCoverage: true,
collectCoverageFrom: [
'webpack/**/*.js',
'!webpack/**/bundle*',
],
coverageReporters: [
'lcov',
],
testURL: 'http://localhost/',
setupFiles: [
'raf/polyfill',
'./webpack/test_setup.js',
],
setupFilesAfterEnv: [
'./webpack/global_test_setup.js',
],
testPathIgnorePatterns: [
'/node_modules/',
'<rootDir>/foreman/',
'<rootDir>/.+fixtures.+',
'<rootDir>/engines',
],
moduleDirectories: [
'node_modules/@theforeman/vendor-core/node_modules',
'node_modules',
'webpack/test-utils',
],
modulePathIgnorePatterns: [
'<rootDir>/foreman/',
],
moduleNameMapper: {
'^.+\\.(css|scss)$': 'identity-obj-proxy',
'^foremanReact(.*)$': `${foremanReactFull}$1`,
},
};

29 changes: 0 additions & 29 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,34 +61,5 @@
"ngreact": "^0.5.0",
"query-string": "^6.1.0",
"react-bootstrap": "^0.32.1"
},
"jest": {
"collectCoverage": true,
"collectCoverageFrom": [
"webpack/**/*.js",
"!webpack/**/bundle*"
],
"coverageReporters": [
"lcov"
],
"testURL": "http://localhost/",
"setupFiles": [
"raf/polyfill",
"./webpack/test_setup.js"
],
"setupTestFrameworkScriptFile": "./webpack/global_test_setup.js",
"testPathIgnorePatterns": [
"/node_modules/",
"<rootDir>/foreman/",
"<rootDir>/.+fixtures.+",
"<rootDir>/engines"
],
"moduleDirectories": [
"node_modules/@theforeman/vendor-core/node_modules",
"node_modules"
],
"moduleNameMapper": {
"^.+\\.(css|scss)$": "identity-obj-proxy"
}
}
}
5 changes: 0 additions & 5 deletions webpack/__mocks__/foremanReact/common/I18n.js

This file was deleted.

21 changes: 0 additions & 21 deletions webpack/__mocks__/foremanReact/common/helpers.js

This file was deleted.

8 changes: 0 additions & 8 deletions webpack/__mocks__/foremanReact/common/keyCodes.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@

const BreadcrumbsBar = () => jest.fn();
export default BreadcrumbsBar;

This file was deleted.

This file was deleted.

6 changes: 0 additions & 6 deletions webpack/__mocks__/foremanReact/components/common/table.js

This file was deleted.

This file was deleted.

This file was deleted.

3 changes: 3 additions & 0 deletions webpack/__mocks__/react-intl/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const addLocaleData = jest.fn();
export const FormattedRelative = jest.fn();
export const intlShape = jest.fn();
1 change: 1 addition & 0 deletions webpack/__mocks__/react-intl/locale-data/en.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default {};
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ exports[`Table renders Table with pagination 1`] = `
</TablePfProvider>
<PaginationWrapper
itemCount={2}
onChange={[Function]}
pagination={
Object {
"page": 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,19 @@

exports[`RedHatRepositories page should render <PermissionDenied /> when permissions are missing 1`] = `
<PermissionDenied
backHref="/"
missingPermissions={
Array [
"view_organizations",
]
}
texts={
Object {
"notAuthorizedMsg": "You are not authorized to perform this action.",
"permissionDeniedMsg": "Permission denied",
"pleaseRequestMsg": "Please request one of the required permissions listed below from a Foreman administrator:",
}
}
/>
`;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ exports[`manage manifest modal should render 1`] = `
"header": "There is no Manifest History to display.",
}
}
onPaginationChange={[Function]}
rows={
Array [
Object {
Expand Down Expand Up @@ -141,7 +142,7 @@ exports[`manage manifest modal should render 1`] = `
</LoadingState>
</Tab>
</Uncontrolled(Tabs)>
<Component>
<mockConstructor>
<Button
active={false}
block={false}
Expand All @@ -152,6 +153,6 @@ exports[`manage manifest modal should render 1`] = `
>
Close
</Button>
</Component>
</mockConstructor>
</ForemanModal>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Array [
"type": "SUBSCRIPTIONS_RESET_TASKS",
},
Object {
"interval": 1000,
"interval": 5000,
"key": "SUBSCRIPTIONS_TASK_SEARCH",
"params": Object {
"search": "organization_id=1 and result=pending and label=Actions::Katello::Organization::ManifestImport or Actions::Katello::Organization::ManifestRefresh or Actions::Katello::Organization::ManifestDelete or Actions::Katello::UpstreamSubscriptions::BindEntitlements or Actions::Katello::UpstreamSubscriptions::UpdateEntitlement or Actions::Katello::UpstreamSubscriptions::RemoveEntitlements or Actions::Katello::UpstreamSubscriptions::UpdateEntitlements",
Expand All @@ -82,7 +82,7 @@ Array [
"type": "STOP_INTERVAL",
},
Object {
"interval": 1000,
"interval": 5000,
"key": "SUBSCRIPTIONS_POLL_TASK",
"type": "API_GET",
"url": "/foreman_tasks/api/tasks/eb1b6271-8a69-4d98-84fc-bea06ddcc166",
Expand All @@ -92,7 +92,7 @@ Array [

exports[`subscription actions pollTasks can search tasks 1`] = `
Object {
"interval": 1000,
"interval": 5000,
"key": "SUBSCRIPTIONS_TASK_SEARCH",
"params": Object {
"search": "organization_id=1 and result=pending and label=Actions::Katello::Organization::ManifestImport or Actions::Katello::Organization::ManifestRefresh or Actions::Katello::Organization::ManifestDelete or Actions::Katello::UpstreamSubscriptions::BindEntitlements or Actions::Katello::UpstreamSubscriptions::UpdateEntitlement or Actions::Katello::UpstreamSubscriptions::RemoveEntitlements or Actions::Katello::UpstreamSubscriptions::UpdateEntitlements",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,19 @@

exports[`subscriptions page should render <PermissionDenied /> when permissions are missing 1`] = `
<PermissionDenied
backHref="/"
missingPermissions={
Array [
"view_subscriptions",
]
}
texts={
Object {
"notAuthorizedMsg": "You are not authorized to perform this action.",
"permissionDeniedMsg": "Permission denied",
"pleaseRequestMsg": "Please request one of the required permissions listed below from a Foreman administrator:",
}
}
/>
`;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import SubscriptionsTable from '../SubscriptionsTable';
import { successState, loadingState, emptyState, groupedSubscriptions } from '../../../__tests__/subscriptions.fixtures';
import { loadSubscriptions, updateQuantity } from '../../../SubscriptionActions';

jest.mock('foremanReact/components/Pagination/PaginationWrapper');
jest.useFakeTimers();

const tableColumns = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ exports[`SubscriptionsToolbar renders SubscriptionsToolbar 1`] = `
bsClass="btn"
bsStyle="default"
disabled={false}
onClick={[Function]}
>
Manage Manifest
</Button>
Expand All @@ -62,6 +63,7 @@ exports[`SubscriptionsToolbar renders SubscriptionsToolbar 1`] = `
bsClass="btn"
bsStyle="default"
disabled={false}
onClick={[Function]}
>
Export CSV
</Button>
Expand Down Expand Up @@ -125,6 +127,7 @@ exports[`SubscriptionsToolbar renders SubscriptionsToolbar with disabled add but
bsClass="btn"
bsStyle="default"
disabled={false}
onClick={[Function]}
>
Manage Manifest
</Button>
Expand All @@ -134,6 +137,7 @@ exports[`SubscriptionsToolbar renders SubscriptionsToolbar with disabled add but
bsClass="btn"
bsStyle="default"
disabled={false}
onClick={[Function]}
>
Export CSV
</Button>
Expand Down Expand Up @@ -197,6 +201,7 @@ exports[`SubscriptionsToolbar renders SubscriptionsToolbar with disabled delete
bsClass="btn"
bsStyle="default"
disabled={false}
onClick={[Function]}
>
Manage Manifest
</Button>
Expand All @@ -206,6 +211,7 @@ exports[`SubscriptionsToolbar renders SubscriptionsToolbar with disabled delete
bsClass="btn"
bsStyle="default"
disabled={false}
onClick={[Function]}
>
Export CSV
</Button>
Expand Down Expand Up @@ -269,6 +275,7 @@ exports[`SubscriptionsToolbar renders SubscriptionsToolbar with disabled manifes
bsClass="btn"
bsStyle="default"
disabled={false}
onClick={[Function]}
>
Manage Manifest
</Button>
Expand All @@ -278,6 +285,7 @@ exports[`SubscriptionsToolbar renders SubscriptionsToolbar with disabled manifes
bsClass="btn"
bsStyle="default"
disabled={false}
onClick={[Function]}
>
Export CSV
</Button>
Expand Down Expand Up @@ -359,6 +367,7 @@ exports[`SubscriptionsToolbar renders SubscriptionsToolbar with table columns 1`
bsClass="btn"
bsStyle="default"
disabled={false}
onClick={[Function]}
>
Manage Manifest
</Button>
Expand All @@ -368,6 +377,7 @@ exports[`SubscriptionsToolbar renders SubscriptionsToolbar with table columns 1`
bsClass="btn"
bsStyle="default"
disabled={false}
onClick={[Function]}
>
Export CSV
</Button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

exports[`task actions can poll a task 1`] = `
Object {
"interval": 1000,
"interval": 5000,
"key": "TEST_POLL_TASK",
"type": "API_GET",
"url": "/foreman_tasks/api/tasks/12345",
Expand All @@ -11,7 +11,7 @@ Object {

exports[`task actions can search tasks 1`] = `
Object {
"interval": 1000,
"interval": 5000,
"key": "TEST_TASK_SEARCH",
"params": Object {
"search": "",
Expand Down
3 changes: 3 additions & 0 deletions webpack/test_setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ configure({ adapter: new Adapter() });
// Mocking translation function
global.__ = text => text; // eslint-disable-line
Services.orgId = () => 1;

// Mocking locales to prevent unnecessary fallback messages
window.locales = { en: { domain: 'app', locale_data: { app: { '': {} } } } };