Skip to content
This repository has been archived by the owner on Jul 21, 2023. It is now read-only.

Commit

Permalink
Test fetching cloud tenants
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelkro committed Dec 7, 2018
1 parent f5b8f00 commit 38a0d37
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 25 deletions.
Expand Up @@ -5,6 +5,7 @@ import { Field, reduxForm } from 'redux-form';
import { length } from 'redux-form-validators';

import ClustersStepForm from './components/ClustersStepForm/ClustersStepForm';
import { FETCH_TARGET_COMPUTE_URLS } from './MappingWizardClustersStepConstants';

class MappingWizardClustersStep extends React.Component {
componentDidMount() {
Expand Down Expand Up @@ -140,13 +141,7 @@ MappingWizardClustersStep.defaultProps = {
'/api/clusters?expand=resources' +
'&attributes=ext_management_system.emstype,v_parent_datacenter,ext_management_system.name' +
'&filter[]=ext_management_system.emstype=vmwarews',
fetchTargetComputeUrls: {
rhevm:
'/api/clusters?expand=resources' +
'&attributes=ext_management_system.emstype,v_parent_datacenter,ext_management_system.name,hosts' +
'&filter[]=ext_management_system.emstype=rhevm',
openstack: '/api/cloud_tenants?expand=resources&attributes=ext_management_system.name,ext_management_system.id'
}
fetchTargetComputeUrls: FETCH_TARGET_COMPUTE_URLS
};

export default reduxForm({
Expand Down
Expand Up @@ -3,3 +3,11 @@ export const FETCH_V2V_TARGET_CLUSTERS = 'FETCH_V2V_TARGET_CLUSTERS';
export const QUERY_V2V_HOSTS = 'QUERY_V2V_HOSTS';

export const OPENSTACK_CONVERSION_HOST_TYPE = 'ManageIQ::Providers::Openstack::CloudManager::Vm';

export const FETCH_TARGET_COMPUTE_URLS = {
rhevm:
'/api/clusters?expand=resources' +
'&attributes=ext_management_system.emstype,v_parent_datacenter,ext_management_system.name,hosts' +
'&filter[]=ext_management_system.emstype=rhevm',
openstack: '/api/cloud_tenants?expand=resources&attributes=ext_management_system.name,ext_management_system.id'
};
Expand Up @@ -8,7 +8,7 @@ import {
import { V2V_MAPPING_WIZARD_EXITED } from '../../../../screens/MappingWizard/MappingWizardConstants';
import { getHostsByClusterID } from './helpers';

const initialState = Immutable({
export const initialState = Immutable({
sourceClusters: [],
isFetchingSourceClusters: false,
isRejectedSourceClusters: false,
Expand Down
@@ -0,0 +1,50 @@
import React from 'react';
import { mount } from 'enzyme';
import { Provider } from 'react-redux';
import { reducer as formReducer } from 'redux-form';

import { generateStore } from '../../../../../../common/testReduxHelpers';
import { reducers } from '../index';
import { initialState } from '../MappingWizardClustersStepReducer';
import MappingWizardClustersStep from '../MappingWizardClustersStep';
import { FETCH_TARGET_COMPUTE_URLS } from '../MappingWizardClustersStepConstants';
import { V2V_TARGET_PROVIDERS } from '../../../MappingWizardConstants';

const store = generateStore(
{ ...reducers, form: formReducer },
{ mappingWizardClustersStep: initialState, form: { mappingWizardClustersStep: { values: { clusterMappings: [] } } } }
);

describe('target provider is OSP', () => {
const targetProvider = V2V_TARGET_PROVIDERS[1].id;

let fetchTargetClustersAction;
let showAlertAction;
let hideAlertAction;
beforeEach(() => {
fetchTargetClustersAction = jest.fn();
showAlertAction = jest.fn();
hideAlertAction = jest.fn();
});

test('cloud tenants are fetched', () => {
fetchTargetClustersAction.mockReturnValue(Promise.resolve());

const wrapper = mount(
<Provider store={store}>
<MappingWizardClustersStep
fetchTargetClustersAction={fetchTargetClustersAction}
fetchTargetComputeUrls={FETCH_TARGET_COMPUTE_URLS}
hideAlertAction={hideAlertAction}
showAlertAction={showAlertAction}
sourceClusters={[]}
targetProvider={targetProvider}
/>
</Provider>
);

expect(fetchTargetClustersAction).toHaveBeenCalledWith(FETCH_TARGET_COMPUTE_URLS[targetProvider]);

wrapper.unmount();
});
});
@@ -1,39 +1,34 @@
import React from 'react';
import thunk from 'redux-thunk';
import promiseMiddleware from 'redux-promise-middleware';
import { reducer as formReducer } from 'redux-form';
import { createStore, applyMiddleware, combineReducers } from 'redux';
import { mount } from 'enzyme';
import { Provider } from 'react-redux';

import { generateStore } from '../../../../../../common/testReduxHelpers';
import { initialState } from '../mappingWizardClustersStep.fixtures';
import { initialState as generalStepInitialState } from '../../MappingWizardGeneralStep/MappingWizardGeneralStepReducer';
import { reducers as generalStepReducers } from '../../MappingWizardGeneralStep/index';
import MappingWizardClustersStep from '../MappingWizardClustersStep';
import MappingWizardClustersStepContainer, { reducers } from '../index';

describe('Mapping Wizard integration test', () => {
const middlewares = [thunk, promiseMiddleware()];
const generateStore = () =>
createStore(
combineReducers({ ...reducers, ...generalStepReducers, form: formReducer }),
{
mappingWizardClustersStep: initialState,
mappingWizardGeneralStep: generalStepInitialState,
form: { mappingWizardGeneralStep: { values: { targetProvider: 'rhevm' } } }
},
applyMiddleware(...middlewares)
);
const store = generateStore(
{ ...reducers, ...generalStepReducers, form: formReducer },
{
mappingWizardClustersStep: initialState,
mappingWizardGeneralStep: generalStepInitialState,
form: { mappingWizardGeneralStep: { values: { targetProvider: 'rhevm' } } }
}
);

const mountComponent = store =>
const mountComponent = () =>
mount(
<Provider store={store}>
<MappingWizardClustersStepContainer />
</Provider>
);

it('should mount the MappingWizardClusterStep with mapStateToProps reduced', () => {
const store = generateStore();
const wrapper = mountComponent(store);
const wrapper = mountComponent();

// query the unconnected component to assert reduced props
const component = wrapper.find(MappingWizardClustersStep);
Expand Down
8 changes: 8 additions & 0 deletions app/javascript/react/screens/App/common/testReduxHelpers.js
@@ -0,0 +1,8 @@
import thunk from 'redux-thunk';
import promiseMiddleware from 'redux-promise-middleware';
import { createStore, applyMiddleware, combineReducers } from 'redux';

const middlewares = [thunk, promiseMiddleware()];

export const generateStore = (reducers, initialState) =>
createStore(combineReducers(reducers), initialState, applyMiddleware(...middlewares));

0 comments on commit 38a0d37

Please sign in to comment.