foreman_rh_cloud 14.1.2 → 14.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/foreman_inventory_upload/generators/fact_helpers.rb +26 -4
- data/lib/foreman_inventory_upload.rb +8 -1
- data/lib/foreman_rh_cloud/version.rb +1 -1
- data/lib/foreman_rh_cloud.rb +36 -9
- data/lib/insights_cloud/async/insights_generate_notifications.rb +10 -1
- data/lib/inventory_sync/async/inventory_self_host_sync.rb +12 -2
- data/package.json +1 -1
- data/test/jobs/insights_generate_notifications_test.rb +26 -0
- data/test/jobs/inventory_self_host_sync_test.rb +9 -0
- data/test/unit/foreman_rh_cloud_self_host_test.rb +50 -2
- data/test/unit/metadata_generator_test.rb +24 -1
- data/webpack/ForemanInventoryUpload/Components/AccountList/Components/EmptyResults/__tests__/EmptyResults.test.js +10 -9
- data/webpack/ForemanInventoryUpload/Components/AccountList/Components/EmptyState/__tests__/EmptyState.test.js +13 -9
- data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ErrorState/__tests__/ErrorState.test.js +20 -9
- data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItem/__tests__/ListItem.test.js +31 -8
- data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItemStatus/__tests__/ListItemStatus.test.js +26 -10
- data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountList.test.js +33 -9
- data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListReducer.test.js +55 -35
- data/webpack/ForemanInventoryUpload/Components/FileDownload/__tests__/FileDownload.test.js +13 -9
- data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/InventoryFilter.test.js +12 -15
- data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/integration.test.js +32 -12
- data/webpack/ForemanInventoryUpload/Components/PageHeader/__tests__/PageTitle.test.js +14 -7
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/CloudConnectorButton/__tests__/CloudConnectorButton.test.js +47 -18
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SettingsWarning/SettingsWarning.test.js +58 -15
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/SyncButton.test.js +23 -9
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/SyncButtonSelectors.test.js +19 -17
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/integrations.test.js +25 -37
- data/webpack/ForemanInventoryUpload/Components/ScheduledRun/__tests__/ScheduledRun.test.js +28 -8
- data/webpack/ForemanInventoryUpload/Components/StatusChart/__tests__/StatusChart.test.js +25 -8
- data/webpack/ForemanInventoryUpload/Components/TabContainer/__tests__/TabContainer.test.js +11 -9
- data/webpack/ForemanInventoryUpload/Components/TabFooter/__tests__/TabFooter.test.js +11 -9
- data/webpack/ForemanInventoryUpload/SubscriptionsPageExtension/InventoryAutoUpload/__tests__/InventoryAutoUpload.test.js +33 -12
- data/webpack/ForemanInventoryUpload/__tests__/ForemanInventoryHelpers.test.js +21 -8
- data/webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/InsightsSettingsActions.test.js +61 -47
- data/webpack/InsightsCloudSync/Components/InsightsTable/__tests__/InsightsTable.test.js +48 -4
- data/webpack/InsightsCloudSync/Components/InsightsTable/__tests__/InsightsTableActions.test.js +126 -35
- data/webpack/InsightsCloudSync/Components/InsightsTable/__tests__/InsightsTableSelectors.test.js +90 -24
- data/webpack/InsightsCloudSync/InsightsCloudSync.test.js +79 -21
- data/webpack/InsightsCloudSync/__tests__/InsightsCloudSyncActions.test.js +31 -6
- data/webpack/InsightsHostDetailsTab/__tests__/InsightsTab.test.js +42 -9
- data/webpack/__tests__/ForemanRhCloudHelpers.test.js +91 -53
- data/webpack/common/Switcher/__tests__/HelpLabel.test.js +25 -10
- data/webpack/common/Switcher/__tests__/SwitcherPF4.test.js +41 -10
- metadata +3 -67
- data/webpack/ForemanInventoryUpload/Components/AccountList/Components/EmptyResults/__tests__/__snapshots__/EmptyResults.test.js.snap +0 -18
- data/webpack/ForemanInventoryUpload/Components/AccountList/Components/EmptyState/__tests__/__snapshots__/EmptyState.test.js.snap +0 -25
- data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ErrorState/__tests__/__snapshots__/ErrorState.test.js.snap +0 -20
- data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItem/__tests__/__snapshots__/ListItem.test.js.snap +0 -47
- data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItemStatus/__tests__/__snapshots__/ListItemStatus.test.js.snap +0 -59
- data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListActions.test.js +0 -34
- data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListIntegration.test.js +0 -14
- data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListSelectors.test.js +0 -25
- data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountList.test.js.snap +0 -49
- data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountListActions.test.js.snap +0 -86
- data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountListReducer.test.js.snap +0 -75
- data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountListSelectors.test.js.snap +0 -46
- data/webpack/ForemanInventoryUpload/Components/FileDownload/__tests__/__snapshots__/FileDownload.test.js.snap +0 -26
- data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/InventoryFilterActions.test.js +0 -14
- data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/InventoryFilterReducer.test.js +0 -28
- data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/InventoryFilterSelectors.test.js +0 -21
- data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/__snapshots__/InventoryFilter.test.js.snap +0 -21
- data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/__snapshots__/InventoryFilterActions.test.js.snap +0 -17
- data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/__snapshots__/InventoryFilterReducer.test.js.snap +0 -19
- data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/__snapshots__/InventoryFilterSelectors.test.js.snap +0 -9
- data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/__snapshots__/integration.test.js.snap +0 -43
- data/webpack/ForemanInventoryUpload/Components/InventorySettings/AdvancedSetting/__tests__/AdvancedSettingActions.test.js +0 -9
- data/webpack/ForemanInventoryUpload/Components/InventorySettings/AdvancedSetting/__tests__/__snapshots__/AdvancedSettingActions.test.js.snap +0 -18
- data/webpack/ForemanInventoryUpload/Components/InventorySettings/__tests__/InventorySettingsActions.test.js +0 -14
- data/webpack/ForemanInventoryUpload/Components/InventorySettings/__tests__/__snapshots__/InventorySettingsActions.test.js.snap +0 -26
- data/webpack/ForemanInventoryUpload/Components/PageHeader/__tests__/__snapshots__/PageTitle.test.js.snap +0 -68
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/CloudConnectorButton/__tests__/CloudConnectorActions.test.js +0 -9
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/CloudConnectorButton/__tests__/__snapshots__/CloudConnectorActions.test.js.snap +0 -11
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/CloudConnectorButton/__tests__/__snapshots__/CloudConnectorButton.test.js.snap +0 -59
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SettingsWarning/__snapshots__/SettingsWarning.test.js.snap +0 -32
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/__snapshots__/SyncButton.test.js.snap +0 -15
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/__snapshots__/SyncButtonSelectors.test.js.snap +0 -3
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/__snapshots__/integrations.test.js.snap +0 -58
- data/webpack/ForemanInventoryUpload/Components/ScheduledRun/__tests__/__snapshots__/ScheduledRun.test.js.snap +0 -23
- data/webpack/ForemanInventoryUpload/Components/StatusChart/__tests__/__snapshots__/StatusChart.test.js.snap +0 -74
- data/webpack/ForemanInventoryUpload/Components/TabContainer/__tests__/__snapshots__/TabContainer.test.js.snap +0 -18
- data/webpack/ForemanInventoryUpload/Components/TabFooter/__tests__/__snapshots__/TabFooter.test.js.snap +0 -12
- data/webpack/ForemanInventoryUpload/SubscriptionsPageExtension/InventoryAutoUpload/__tests__/__snapshots__/InventoryAutoUpload.test.js.snap +0 -96
- data/webpack/ForemanInventoryUpload/__tests__/ForemanInventoryUpload.test.js +0 -10
- data/webpack/ForemanInventoryUpload/__tests__/__snapshots__/ForemanInventoryHelpers.test.js.snap +0 -5
- data/webpack/ForemanInventoryUpload/__tests__/__snapshots__/ForemanInventoryUpload.test.js.snap +0 -14
- data/webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/InsightsSettingsReducer.test.js +0 -33
- data/webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/InsightsSettingsSelectors.test.js +0 -21
- data/webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/__snapshots__/InsightsSettingsActions.test.js.snap +0 -65
- data/webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/__snapshots__/InsightsSettingsReducer.test.js.snap +0 -19
- data/webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/__snapshots__/InsightsSettingsSelectors.test.js.snap +0 -9
- data/webpack/InsightsCloudSync/Components/InsightsTable/__tests__/__snapshots__/InsightsTableActions.test.js.snap +0 -131
- data/webpack/InsightsCloudSync/Components/InsightsTable/__tests__/__snapshots__/InsightsTableSelectors.test.js.snap +0 -87
- data/webpack/InsightsCloudSync/__snapshots__/InsightsCloudSync.test.js.snap +0 -10
- data/webpack/InsightsCloudSync/__tests__/InsightsCloudSyncHelpers.test.js +0 -9
- data/webpack/InsightsCloudSync/__tests__/__snapshots__/InsightsCloudSyncActions.test.js.snap +0 -15
- data/webpack/InsightsCloudSync/__tests__/__snapshots__/InsightsCloudSyncHelpers.test.js.snap +0 -3
- data/webpack/InsightsHostDetailsTab/__tests__/InsightsTabActions.test.js +0 -19
- data/webpack/InsightsHostDetailsTab/__tests__/InsightsTabReducer.test.js +0 -26
- data/webpack/InsightsHostDetailsTab/__tests__/InsightsTabSelectors.test.js +0 -13
- data/webpack/InsightsHostDetailsTab/__tests__/__snapshots__/InsightsTab.test.js.snap +0 -34
- data/webpack/InsightsHostDetailsTab/__tests__/__snapshots__/InsightsTabActions.test.js.snap +0 -56
- data/webpack/InsightsHostDetailsTab/__tests__/__snapshots__/InsightsTabReducer.test.js.snap +0 -32
- data/webpack/InsightsHostDetailsTab/__tests__/__snapshots__/InsightsTabSelectors.test.js.snap +0 -18
- data/webpack/__tests__/ForemanRhCloudSelectors.test.js +0 -22
- data/webpack/__tests__/ForemanRhCloudTestHelpers.test.js +0 -20
- data/webpack/__tests__/__snapshots__/ForemanRhCloudHelpers.test.js.snap +0 -19
- data/webpack/__tests__/__snapshots__/ForemanRhCloudSelectors.test.js.snap +0 -25
- data/webpack/__tests__/__snapshots__/ForemanRhCloudTestHelpers.test.js.snap +0 -39
- data/webpack/common/Switcher/__tests__/__snapshots__/HelpLabel.test.js.snap +0 -16
- data/webpack/common/Switcher/__tests__/__snapshots__/SwitcherPF4.test.js.snap +0 -24
|
@@ -1,25 +1,83 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}),
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render } from '@testing-library/react';
|
|
3
|
+
import RecommendationsPage from './InsightsCloudSync';
|
|
4
|
+
|
|
5
|
+
let mockIsIop = false;
|
|
6
|
+
jest.mock('../common/Hooks/ConfigHooks', () => ({
|
|
7
|
+
useIopConfig: () => mockIsIop,
|
|
8
|
+
}));
|
|
9
|
+
|
|
10
|
+
jest.mock('../common/Hooks/PermissionsHooks', () => ({
|
|
11
|
+
useInsightsPermissions: () => ({}),
|
|
13
12
|
}));
|
|
14
13
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
jest.mock('./Components/InsightsTable', () => () => null);
|
|
15
|
+
jest.mock('./Components/RemediationModal', () => () => null);
|
|
16
|
+
jest.mock('./Components/InsightsTable/Pagination', () => () => null);
|
|
17
|
+
jest.mock('./Components/InsightsSettings', () => () => null);
|
|
18
|
+
jest.mock('foremanReact/routes/common/PageLayout/PageLayout', () => ({
|
|
19
|
+
children,
|
|
20
|
+
header,
|
|
21
|
+
toolbarButtons,
|
|
22
|
+
}) => (
|
|
23
|
+
<div data-testid="page-layout" data-header={header}>
|
|
24
|
+
{toolbarButtons}
|
|
25
|
+
{children}
|
|
26
|
+
</div>
|
|
27
|
+
));
|
|
28
|
+
jest.mock('@scalprum/react-core', () => ({
|
|
29
|
+
ScalprumComponent: () => <div data-testid="scalprum-component" />,
|
|
30
|
+
ScalprumProvider: ({ children }) => <div>{children}</div>,
|
|
31
|
+
}));
|
|
32
|
+
jest.mock('../common/ScalprumModule/ScalprumContext', () => ({
|
|
33
|
+
createProviderOptions: () => ({ config: {} }),
|
|
34
|
+
}));
|
|
35
|
+
|
|
36
|
+
const defaultProps = {
|
|
37
|
+
syncInsights: jest.fn(),
|
|
38
|
+
fetchInsights: jest.fn(),
|
|
39
|
+
query: '',
|
|
22
40
|
};
|
|
23
41
|
|
|
24
|
-
describe('
|
|
25
|
-
|
|
42
|
+
describe('RecommendationsPage', () => {
|
|
43
|
+
afterEach(() => {
|
|
44
|
+
mockIsIop = false;
|
|
45
|
+
jest.clearAllMocks();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
describe('non-IOP mode', () => {
|
|
49
|
+
it('renders with rh-cloud-insights class and correct header', () => {
|
|
50
|
+
const { container } = render(
|
|
51
|
+
<RecommendationsPage {...defaultProps} />
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
expect(container.querySelector('.rh-cloud-insights')).toBeTruthy();
|
|
55
|
+
expect(
|
|
56
|
+
container.querySelector('[data-header="Red Hat Insights"]')
|
|
57
|
+
).toBeTruthy();
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('does not render IOP advisor view', () => {
|
|
61
|
+
const { container } = render(
|
|
62
|
+
<RecommendationsPage {...defaultProps} />
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
expect(container.querySelector('.advisor')).toBeNull();
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
describe('IOP mode', () => {
|
|
70
|
+
beforeEach(() => {
|
|
71
|
+
mockIsIop = true;
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('renders advisor view instead of insights page', () => {
|
|
75
|
+
const { container } = render(
|
|
76
|
+
<RecommendationsPage {...defaultProps} />
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
expect(container.querySelector('.advisor')).toBeTruthy();
|
|
80
|
+
expect(container.querySelector('.rh-cloud-insights')).toBeNull();
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
});
|
|
@@ -1,9 +1,34 @@
|
|
|
1
|
-
import { testActionSnapshotWithFixtures } from '@theforeman/test';
|
|
2
1
|
import { syncInsights } from '../InsightsCloudSyncActions';
|
|
2
|
+
import { INSIGHTS_CLOUD_SYNC } from '../InsightsCloudSyncConstants';
|
|
3
3
|
|
|
4
|
-
const fixtures = {
|
|
5
|
-
'should syncInsights': () => syncInsights(),
|
|
6
|
-
};
|
|
7
4
|
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
jest.mock('../../common/ForemanTasks');
|
|
6
|
+
|
|
7
|
+
describe('InsightsCloudSync actions', () => {
|
|
8
|
+
let dispatch;
|
|
9
|
+
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
dispatch = jest.fn();
|
|
12
|
+
jest.clearAllMocks();
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('dispatches post with correct key and url', () => {
|
|
16
|
+
const fetchInsights = jest.fn();
|
|
17
|
+
syncInsights(fetchInsights, 'test-query')(dispatch);
|
|
18
|
+
|
|
19
|
+
expect(dispatch).toHaveBeenCalledTimes(1);
|
|
20
|
+
const dispatched = dispatch.mock.calls[0][0];
|
|
21
|
+
expect(dispatched.key).toBe(INSIGHTS_CLOUD_SYNC);
|
|
22
|
+
expect(dispatched.url).toBe('/insights_cloud/tasks');
|
|
23
|
+
expect(typeof dispatched.handleSuccess).toBe('function');
|
|
24
|
+
expect(typeof dispatched.errorToast).toBe('function');
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('errorToast returns failure message with error details', () => {
|
|
28
|
+
syncInsights(jest.fn(), '')(dispatch);
|
|
29
|
+
const dispatched = dispatch.mock.calls[0][0];
|
|
30
|
+
|
|
31
|
+
const result = dispatched.errorToast('some error');
|
|
32
|
+
expect(result).toContain('some error');
|
|
33
|
+
});
|
|
34
|
+
});
|
|
@@ -1,13 +1,46 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
3
|
import InsightsTab from '../InsightsTab';
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
const fixtures = {
|
|
7
|
-
'render with props': props,
|
|
8
|
-
};
|
|
4
|
+
import { hits, hostID } from './InsightsTab.fixtures';
|
|
9
5
|
|
|
10
6
|
describe('InsightsTab', () => {
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
it('renders "No recommendations" message when hits is empty', () => {
|
|
8
|
+
render(<InsightsTab hostID={hostID} hits={[]} />);
|
|
9
|
+
expect(
|
|
10
|
+
screen.getByText('No recommendations were found for this host!')
|
|
11
|
+
).toBeTruthy();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it('renders Recommendations heading when hits exist', () => {
|
|
15
|
+
render(<InsightsTab hostID={hostID} hits={hits} />);
|
|
16
|
+
expect(screen.getByText('Recommendations')).toBeTruthy();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('displays hit titles', () => {
|
|
20
|
+
render(<InsightsTab hostID={hostID} hits={hits} />);
|
|
21
|
+
hits.forEach(hit => {
|
|
22
|
+
expect(screen.getByText(hit.title)).toBeTruthy();
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('calls fetchHits on mount', () => {
|
|
27
|
+
const fetchHits = jest.fn();
|
|
28
|
+
render(<InsightsTab hostID={hostID} hits={[]} fetchHits={fetchHits} />);
|
|
29
|
+
expect(fetchHits).toHaveBeenCalledWith(hostID);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('sorts hits by total_risk descending', () => {
|
|
33
|
+
const multipleHits = [
|
|
34
|
+
{ ...hits[0], title: 'Low risk', total_risk: 1 },
|
|
35
|
+
{ ...hits[0], title: 'High risk', total_risk: 4 },
|
|
36
|
+
{ ...hits[0], title: 'Medium risk', total_risk: 2 },
|
|
37
|
+
];
|
|
38
|
+
render(<InsightsTab hostID={hostID} hits={multipleHits} />);
|
|
39
|
+
const titles = screen.getAllByText(/risk/i).map(el => el.textContent);
|
|
40
|
+
const highRiskIndex = titles.findIndex(t => t === 'High risk');
|
|
41
|
+
const mediumRiskIndex = titles.findIndex(t => t === 'Medium risk');
|
|
42
|
+
const lowRiskIndex = titles.findIndex(t => t === 'Low risk');
|
|
43
|
+
expect(highRiskIndex).toBeLessThan(mediumRiskIndex);
|
|
44
|
+
expect(mediumRiskIndex).toBeLessThan(lowRiskIndex);
|
|
45
|
+
});
|
|
13
46
|
});
|
|
@@ -1,59 +1,97 @@
|
|
|
1
|
-
import { testSelectorsSnapshotWithFixtures } from '@theforeman/test';
|
|
2
1
|
import {
|
|
3
2
|
foremanUrl,
|
|
4
3
|
vulnerabilityDisabled,
|
|
5
4
|
hasNoInsightsFacet,
|
|
6
5
|
} from '../ForemanRhCloudHelpers';
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
7
|
+
describe('ForemanRhCloud helpers', () => {
|
|
8
|
+
describe('foremanUrl', () => {
|
|
9
|
+
const originalUrlPrefix = global.URL_PREFIX;
|
|
10
|
+
|
|
11
|
+
beforeAll(() => {
|
|
12
|
+
global.URL_PREFIX = 'MY_TEST_URL_PREFIX.example.com';
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
afterAll(() => {
|
|
16
|
+
global.URL_PREFIX = originalUrlPrefix;
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('prepends URL_PREFIX to path', () => {
|
|
20
|
+
expect(foremanUrl('/test_path')).toBe(
|
|
21
|
+
'MY_TEST_URL_PREFIX.example.com/test_path'
|
|
22
|
+
);
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
describe('vulnerabilityDisabled', () => {
|
|
27
|
+
it('returns false for RHEL host with vulnerability enabled', () => {
|
|
28
|
+
expect(
|
|
29
|
+
vulnerabilityDisabled({
|
|
30
|
+
hostDetails: {
|
|
31
|
+
operatingsystem_name: 'Red Hat Enterprise Linux',
|
|
32
|
+
vulnerability: { enabled: true },
|
|
33
|
+
},
|
|
34
|
+
})
|
|
35
|
+
).toBe(false);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('returns true for non-RHEL host', () => {
|
|
39
|
+
expect(
|
|
40
|
+
vulnerabilityDisabled({
|
|
41
|
+
hostDetails: {
|
|
42
|
+
operatingsystem_name: 'Ubuntu',
|
|
43
|
+
vulnerability: { enabled: true },
|
|
44
|
+
},
|
|
45
|
+
})
|
|
46
|
+
).toBe(true);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('returns true for RHEL host with vulnerability disabled', () => {
|
|
50
|
+
expect(
|
|
51
|
+
vulnerabilityDisabled({
|
|
52
|
+
hostDetails: {
|
|
53
|
+
operatingsystem_name: 'Red Hat Enterprise Linux',
|
|
54
|
+
vulnerability: { enabled: false },
|
|
55
|
+
},
|
|
56
|
+
})
|
|
57
|
+
).toBe(true);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('returns true when vulnerability object is missing', () => {
|
|
61
|
+
expect(
|
|
62
|
+
vulnerabilityDisabled({
|
|
63
|
+
hostDetails: {
|
|
64
|
+
operatingsystem_name: 'Red Hat Enterprise Linux',
|
|
65
|
+
},
|
|
66
|
+
})
|
|
67
|
+
).toBe(true);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('returns true when hostDetails is missing', () => {
|
|
71
|
+
expect(vulnerabilityDisabled({})).toBe(true);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
describe('hasNoInsightsFacet', () => {
|
|
76
|
+
it('returns false when insights_attributes is present in response', () => {
|
|
77
|
+
expect(
|
|
78
|
+
hasNoInsightsFacet({
|
|
79
|
+
response: {
|
|
80
|
+
insights_attributes: {
|
|
81
|
+
uuid: 'test-uuid',
|
|
82
|
+
insights_hits_count: 5,
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
})
|
|
86
|
+
).toBe(false);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('returns true when insights_attributes is missing from response', () => {
|
|
90
|
+
expect(hasNoInsightsFacet({ response: {} })).toBe(true);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('returns true when response is missing', () => {
|
|
94
|
+
expect(hasNoInsightsFacet({})).toBe(true);
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
});
|
|
@@ -1,13 +1,28 @@
|
|
|
1
|
-
import
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
2
3
|
import { HelpLabel } from '../HelpLabel';
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
'
|
|
6
|
-
id
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
},
|
|
10
|
-
};
|
|
5
|
+
describe('HelpLabel', () => {
|
|
6
|
+
it('renders nothing when text is empty', () => {
|
|
7
|
+
const { container } = render(<HelpLabel id="test-id" text="" />);
|
|
8
|
+
expect(container.firstChild).toBeNull();
|
|
9
|
+
});
|
|
11
10
|
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
it('renders nothing when text is not provided', () => {
|
|
12
|
+
const { container } = render(<HelpLabel id="test-id" />);
|
|
13
|
+
expect(container.firstChild).toBeNull();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('renders a button when text is provided', () => {
|
|
17
|
+
render(<HelpLabel id="test-id" text="Help text" />);
|
|
18
|
+
expect(screen.getByRole('button')).toBeTruthy();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('applies the provided className', () => {
|
|
22
|
+
render(
|
|
23
|
+
<HelpLabel id="test-id" text="Help text" className="custom-class" />
|
|
24
|
+
);
|
|
25
|
+
const button = screen.getByRole('button');
|
|
26
|
+
expect(button.className).toContain('custom-class');
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -1,14 +1,45 @@
|
|
|
1
|
-
import
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render, screen, fireEvent } from '@testing-library/react';
|
|
2
3
|
import SwitcherPF4 from '../SwitcherPF4';
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
id: '
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
describe('SwitcherPF4', () => {
|
|
6
|
+
const buildProps = (overrides = {}) => ({
|
|
7
|
+
id: 'test-id',
|
|
8
|
+
label: 'Test Label',
|
|
9
|
+
tooltip: 'Test tooltip',
|
|
9
10
|
onChange: jest.fn(),
|
|
10
|
-
|
|
11
|
-
};
|
|
11
|
+
...overrides,
|
|
12
|
+
});
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
it('renders the switch', () => {
|
|
15
|
+
render(<SwitcherPF4 {...buildProps()} />);
|
|
16
|
+
expect(screen.getByRole('checkbox')).toBeTruthy();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('renders the label text', () => {
|
|
20
|
+
render(<SwitcherPF4 {...buildProps()} />);
|
|
21
|
+
expect(screen.getAllByText('Test Label').length).toBeGreaterThan(0);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('is checked by default', () => {
|
|
25
|
+
render(<SwitcherPF4 {...buildProps()} />);
|
|
26
|
+
expect(screen.getByRole('checkbox').checked).toBe(true);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('respects isChecked prop', () => {
|
|
30
|
+
render(<SwitcherPF4 {...buildProps({ isChecked: false })} />);
|
|
31
|
+
expect(screen.getByRole('checkbox').checked).toBe(false);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('respects isDisabled prop', () => {
|
|
35
|
+
render(<SwitcherPF4 {...buildProps({ isDisabled: true })} />);
|
|
36
|
+
expect(screen.getByRole('checkbox').disabled).toBe(true);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('calls onChange when toggled', () => {
|
|
40
|
+
const onChange = jest.fn();
|
|
41
|
+
render(<SwitcherPF4 {...buildProps({ onChange })} />);
|
|
42
|
+
fireEvent.click(screen.getByRole('checkbox'));
|
|
43
|
+
expect(onChange).toHaveBeenCalledTimes(1);
|
|
44
|
+
});
|
|
45
|
+
});
|