Skip to content

Commit 0ecc480

Browse files
committed
SAT-38755 - RH Cloud Host Details snapshots to RTL
1 parent b15680c commit 0ecc480

18 files changed

+238
-372
lines changed
Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,30 @@
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+
15+
it('should render without hits', () => {
16+
render(<InsightsTab hits={[]} />);
17+
expect(screen.getByText('Recommendations')).toBeInTheDocument();
18+
});
19+
20+
it('should handle undefined hits gracefully', () => {
21+
render(<InsightsTab hits={undefined} />);
22+
expect(screen.getByText('Recommendations')).toBeInTheDocument();
23+
});
24+
25+
it('should handle null hits gracefully', () => {
26+
render(<InsightsTab hits={null} />);
27+
expect(screen.getByText('Recommendations')).toBeInTheDocument();
28+
});
29+
});
1330
});
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: 56 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,68 @@
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-
};
31+
};
32+
const newState = reducer(initialState, action);
33+
expect(newState.hits).toEqual(hits);
34+
});
35+
36+
it('should handle INSIGHTS_HITS_SUCCESS with missing hits in payload', () => {
37+
const initialState = Immutable({ hits: [] });
38+
const action = {
39+
type: INSIGHTS_HITS_SUCCESS,
40+
payload: {},
41+
};
42+
const newState = reducer(initialState, action);
43+
expect(newState).toHaveProperty('hits');
44+
expect(newState.hits).toBeUndefined();
45+
});
46+
47+
it('should handle INSIGHTS_HITS_SUCCESS with undefined hits', () => {
48+
const initialState = Immutable({ hits: [] });
49+
const action = {
50+
type: INSIGHTS_HITS_SUCCESS,
51+
payload: { hits: undefined },
52+
};
53+
const newState = reducer(initialState, action);
54+
expect(newState).toHaveProperty('hits');
55+
expect(newState.hits).toBeUndefined();
56+
});
2457

25-
describe('AccountList reducer', () =>
26-
testReducerSnapshotWithFixtures(reducer, fixtures));
58+
it('should handle INSIGHTS_HITS_SUCCESS with null hits', () => {
59+
const initialState = Immutable({ hits: [] });
60+
const action = {
61+
type: INSIGHTS_HITS_SUCCESS,
62+
payload: { hits: null },
63+
};
64+
const newState = reducer(initialState, action);
65+
expect(newState).toHaveProperty('hits');
66+
expect(newState.hits).toBeNull();
67+
});
68+
});
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.

0 commit comments

Comments
 (0)