Skip to content

Commit d530dad

Browse files
committed
RH Cloud Host Details
1 parent b15680c commit d530dad

18 files changed

+191
-373
lines changed
Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
import { testComponentSnapshotsWithFixtures } from '@theforeman/test';
1+
import React from 'react';
2+
import { render, screen } from '@testing-library/react';
3+
import '@testing-library/jest-dom';
24

35
import InsightsTab from '../InsightsTab';
46
import { props } from './InsightsTab.fixtures';
57

6-
const fixtures = {
7-
'render with props': props,
8-
};
9-
108
describe('InsightsTab', () => {
11-
describe('rendering', () =>
12-
testComponentSnapshotsWithFixtures(InsightsTab, fixtures));
9+
describe('rendering', () => {
10+
it('should render with props', () => {
11+
render(<InsightsTab {...props} />);
12+
expect(screen.getByText('Recommendations')).toBeInTheDocument();
13+
});
14+
});
1315
});
Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,52 @@
1-
import { testActionSnapshotWithFixtures } from '@theforeman/test';
21
import { API } from 'foremanReact/redux/API';
32
import { fetchHits } from '../InsightsTabActions';
43
import { hostID, hits } from './InsightsTab.fixtures';
4+
import {
5+
INSIGHTS_HITS_REQUEST,
6+
INSIGHTS_HITS_SUCCESS,
7+
INSIGHTS_HITS_FAILURE,
8+
} from '../InsightsTabConstants';
59

610
jest.mock('foremanReact/redux/API');
7-
API.get.mockImplementation(async () => ({ data: { hits } }));
811

9-
const fixtures = {
10-
'should fetchHits': () => fetchHits(hostID),
11-
'should fetchHits with error': () => {
12+
describe('InsightsTab actions', () => {
13+
it('should fetchHits', async () => {
14+
API.get.mockImplementation(async () => ({ data: { hits } }));
15+
const dispatch = jest.fn();
16+
17+
await fetchHits(hostID)(dispatch);
18+
19+
expect(dispatch).toHaveBeenCalledWith(
20+
expect.objectContaining({
21+
type: INSIGHTS_HITS_REQUEST,
22+
})
23+
);
24+
expect(dispatch).toHaveBeenCalledWith(
25+
expect.objectContaining({
26+
type: INSIGHTS_HITS_SUCCESS,
27+
payload: { hits },
28+
})
29+
);
30+
});
31+
32+
it('should fetchHits with error', async () => {
1233
API.get.mockImplementationOnce(() =>
1334
Promise.reject(new Error('Network error!'))
1435
);
15-
return fetchHits(hostID);
16-
},
17-
};
36+
const dispatch = jest.fn();
37+
38+
await fetchHits(hostID)(dispatch);
1839

19-
describe('InsightsTab actions', () => testActionSnapshotWithFixtures(fixtures));
40+
expect(dispatch).toHaveBeenCalledWith(
41+
expect.objectContaining({
42+
type: INSIGHTS_HITS_REQUEST,
43+
})
44+
);
45+
// Error handling dispatches a toast notification, not INSIGHTS_HITS_FAILURE
46+
expect(dispatch).toHaveBeenCalledWith(
47+
expect.objectContaining({
48+
type: 'TOASTS_ADD',
49+
})
50+
);
51+
});
52+
});
Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,35 @@
1-
import { testReducerSnapshotWithFixtures } from '@theforeman/test';
1+
import Immutable from 'seamless-immutable';
22
import reducer from '../InsightsTabReducer';
33
import { hits } from './InsightsTab.fixtures';
44
import {
55
INSIGHTS_HITS_REQUEST,
66
INSIGHTS_HITS_SUCCESS,
77
} from '../InsightsTabConstants';
88

9-
const fixtures = {
10-
'should return the initial state': {},
11-
'should handle INSIGHTS_HITS_REQUEST': {
12-
action: {
9+
describe('AccountList reducer', () => {
10+
it('should return the initial state', () => {
11+
const initialState = Immutable({ hits: [] });
12+
expect(reducer(undefined, {})).toEqual(initialState);
13+
});
14+
15+
it('should handle INSIGHTS_HITS_REQUEST', () => {
16+
const initialState = Immutable({ hits: [] });
17+
const action = {
1318
type: INSIGHTS_HITS_REQUEST,
1419
payload: {},
15-
},
16-
},
17-
'should handle INSIGHTS_HITS_SUCCESS': {
18-
action: {
20+
};
21+
const newState = reducer(initialState, action);
22+
expect(newState).toHaveProperty('hits');
23+
expect(newState.hits).toEqual([]);
24+
});
25+
26+
it('should handle INSIGHTS_HITS_SUCCESS', () => {
27+
const initialState = Immutable({ hits: [] });
28+
const action = {
1929
type: INSIGHTS_HITS_SUCCESS,
2030
payload: { hits },
21-
},
22-
},
23-
};
24-
25-
describe('AccountList reducer', () =>
26-
testReducerSnapshotWithFixtures(reducer, fixtures));
31+
};
32+
const newState = reducer(initialState, action);
33+
expect(newState.hits).toEqual(hits);
34+
});
35+
});
Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
import { testSelectorsSnapshotWithFixtures } from '@theforeman/test';
21
import { hostInsightsStateWrapper } from '../../ForemanRhCloudTestHelpers';
32
import { hits } from './InsightsTab.fixtures';
43
import { selectHits } from '../InsightsTabSelectors';
54

65
const state = hostInsightsStateWrapper({ hits });
76

8-
const fixtures = {
9-
'should return hits': () => selectHits(state),
10-
};
11-
12-
describe('InsightsTab selectors', () =>
13-
testSelectorsSnapshotWithFixtures(fixtures));
7+
describe('InsightsTab selectors', () => {
8+
it('should return hits', () => {
9+
expect(selectHits(state)).toEqual(hits);
10+
});
11+
});

webpack/InsightsHostDetailsTab/__tests__/__snapshots__/InsightsTab.test.js.snap

Lines changed: 0 additions & 34 deletions
This file was deleted.

webpack/InsightsHostDetailsTab/__tests__/__snapshots__/InsightsTabActions.test.js.snap

Lines changed: 0 additions & 56 deletions
This file was deleted.

webpack/InsightsHostDetailsTab/__tests__/__snapshots__/InsightsTabReducer.test.js.snap

Lines changed: 0 additions & 32 deletions
This file was deleted.

webpack/InsightsHostDetailsTab/__tests__/__snapshots__/InsightsTabSelectors.test.js.snap

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 42 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,69 @@
1-
import { testSelectorsSnapshotWithFixtures } from '@theforeman/test';
21
import { foremanUrl, vulnerabilityDisabled, hasNoInsightsFacet } from '../ForemanRhCloudHelpers';
32

43
global.URL_PREFIX = 'MY_TEST_URL_PREFIX.example.com';
54

6-
const fixtures = {
7-
'should return foreman Url': () => foremanUrl('/test_path'),
8-
'vulnerabilityDisabled returns false for RHEL host with vulnerability enabled': () =>
9-
vulnerabilityDisabled({
5+
describe('ForemanRhCloud helpers', () => {
6+
it('should return foreman Url', () => {
7+
expect(foremanUrl('/test_path')).toBe('MY_TEST_URL_PREFIX.example.com/test_path');
8+
});
9+
10+
it('vulnerabilityDisabled returns false for RHEL host with vulnerability enabled', () => {
11+
expect(vulnerabilityDisabled({
1012
hostDetails: {
1113
operatingsystem_name: 'Red Hat Enterprise Linux',
1214
vulnerability: { enabled: true },
1315
},
14-
}),
15-
'vulnerabilityDisabled returns true for non-RHEL host': () =>
16-
vulnerabilityDisabled({
16+
})).toBe(false);
17+
});
18+
19+
it('vulnerabilityDisabled returns true for non-RHEL host', () => {
20+
expect(vulnerabilityDisabled({
1721
hostDetails: {
1822
operatingsystem_name: 'Ubuntu',
1923
vulnerability: { enabled: true },
2024
},
21-
}),
22-
'vulnerabilityDisabled returns true for RHEL host with vulnerability disabled': () =>
23-
vulnerabilityDisabled({
25+
})).toBe(true);
26+
});
27+
28+
it('vulnerabilityDisabled returns true for RHEL host with vulnerability disabled', () => {
29+
expect(vulnerabilityDisabled({
2430
hostDetails: {
2531
operatingsystem_name: 'Red Hat Enterprise Linux',
2632
vulnerability: { enabled: false },
2733
},
28-
}),
29-
'vulnerabilityDisabled returns true for missing vulnerability object': () =>
30-
vulnerabilityDisabled({
34+
})).toBe(true);
35+
});
36+
37+
it('vulnerabilityDisabled returns true for missing vulnerability object', () => {
38+
expect(vulnerabilityDisabled({
3139
hostDetails: {
3240
operatingsystem_name: 'Red Hat Enterprise Linux',
3341
},
34-
}),
35-
'vulnerabilityDisabled returns true for missing hostDetails': () =>
36-
vulnerabilityDisabled({}),
37-
'hasNoInsightsFacet returns false when insights_attributes is present': () =>
38-
hasNoInsightsFacet({
42+
})).toBe(true);
43+
});
44+
45+
it('vulnerabilityDisabled returns true for missing hostDetails', () => {
46+
expect(vulnerabilityDisabled({})).toBe(true);
47+
});
48+
49+
it('hasNoInsightsFacet returns false when insights_attributes is present', () => {
50+
expect(hasNoInsightsFacet({
3951
response: {
4052
insights_attributes: {
4153
uuid: 'test-uuid',
4254
insights_hits_count: 5,
4355
},
4456
},
45-
}),
46-
'hasNoInsightsFacet returns true when insights_attributes is missing': () =>
47-
hasNoInsightsFacet({
57+
})).toBe(false);
58+
});
59+
60+
it('hasNoInsightsFacet returns true when insights_attributes is missing', () => {
61+
expect(hasNoInsightsFacet({
4862
response: {},
49-
}),
50-
'hasNoInsightsFacet returns true when response is missing': () =>
51-
hasNoInsightsFacet({}),
52-
};
63+
})).toBe(true);
64+
});
5365

54-
describe('ForemanRhCloud helpers', () =>
55-
testSelectorsSnapshotWithFixtures(fixtures));
66+
it('hasNoInsightsFacet returns true when response is missing', () => {
67+
expect(hasNoInsightsFacet({})).toBe(true);
68+
});
69+
});

0 commit comments

Comments
 (0)