foreman_ansible 2.3.6 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/ui_ansible_roles_controller.rb +14 -0
- data/app/helpers/foreman_ansible/ansible_roles_helper.rb +4 -0
- data/app/models/ansible_role.rb +1 -0
- data/app/models/foreman_ansible/ansible_provider.rb +6 -1
- data/app/models/setting/ansible.rb +10 -10
- data/app/services/foreman_ansible/inventory_creator.rb +26 -23
- data/app/views/foreman_ansible/ansible_roles/_select_tab_content.html.erb +13 -13
- data/app/views/ui_ansible_roles/index.json.rabl +3 -0
- data/app/views/ui_ansible_roles/main.json.rabl +3 -0
- data/app/views/ui_ansible_roles/show.json.rabl +3 -0
- data/config/routes.rb +2 -0
- data/db/migrate/20190328114657_remove_top_level_ansible_variables_setting.rb +6 -0
- data/lib/foreman_ansible/register.rb +3 -2
- data/lib/foreman_ansible/version.rb +1 -1
- data/locale/de/foreman_ansible.edit.po +90 -191
- data/locale/en/foreman_ansible.edit.po +90 -191
- data/locale/es/foreman_ansible.edit.po +90 -191
- data/locale/fr/foreman_ansible.edit.po +90 -191
- data/locale/it/foreman_ansible.edit.po +90 -191
- data/locale/ja/foreman_ansible.edit.po +90 -191
- data/locale/ko/foreman_ansible.edit.po +90 -191
- data/locale/pt_BR/foreman_ansible.edit.po +90 -191
- data/locale/ru/foreman_ansible.edit.po +90 -191
- data/locale/zh_CN/foreman_ansible.edit.po +90 -191
- data/locale/zh_TW/foreman_ansible.edit.po +90 -191
- data/package.json +50 -9
- data/test/factories/ansible_variables.rb +1 -0
- data/test/functional/ui_ansible_roles_controller_test.rb +14 -0
- data/test/unit/lib/foreman_ansible_core/playbook_runner_test.rb +11 -11
- data/test/unit/services/inventory_creator_test.rb +75 -24
- data/webpack/__mocks__/foremanReact/components/Pagination/PaginationWrapper.js +2 -0
- data/webpack/__mocks__/foremanReact/components/common/EmptyState.js +5 -0
- data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcher.js +140 -0
- data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcher.scss +45 -0
- data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherActions.js +69 -0
- data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherConstants.js +7 -0
- data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherHelpers.js +7 -0
- data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherReducer.js +69 -0
- data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherSelectors.js +68 -0
- data/webpack/components/AnsibleRolesSwitcher/__fixtures__/ansibleRolesData.fixtures.js +20 -0
- data/webpack/components/AnsibleRolesSwitcher/__fixtures__/ansibleRolesSwitcherReducer.fixtures.js +36 -0
- data/webpack/components/AnsibleRolesSwitcher/__tests__/AnsibleRolesSwitcher.test.js +30 -0
- data/webpack/components/AnsibleRolesSwitcher/__tests__/AnsibleRolesSwitcherReducer.test.js +73 -0
- data/webpack/components/AnsibleRolesSwitcher/__tests__/AnsibleRolesSwitcherSelectors.test.js +43 -0
- data/webpack/components/AnsibleRolesSwitcher/__tests__/__snapshots__/AnsibleRolesSwitcher.test.js.snap +79 -0
- data/webpack/components/AnsibleRolesSwitcher/__tests__/__snapshots__/AnsibleRolesSwitcherReducer.test.js.snap +399 -0
- data/webpack/components/AnsibleRolesSwitcher/__tests__/__snapshots__/AnsibleRolesSwitcherSelectors.test.js.snap +60 -0
- data/webpack/components/AnsibleRolesSwitcher/components/AnsiblePermissionDenied.js +33 -0
- data/webpack/components/AnsibleRolesSwitcher/components/AnsiblePermissionDenied.test.js +9 -0
- data/webpack/components/AnsibleRolesSwitcher/components/AnsibleRole.js +56 -0
- data/webpack/components/AnsibleRolesSwitcher/components/AnsibleRole.test.js +26 -0
- data/webpack/components/AnsibleRolesSwitcher/components/AnsibleRoleActionButton.js +16 -0
- data/webpack/components/AnsibleRolesSwitcher/components/AnsibleRolesSwitcherError.js +32 -0
- data/webpack/components/AnsibleRolesSwitcher/components/AssignedRolesList.js +67 -0
- data/webpack/components/AnsibleRolesSwitcher/components/AssignedRolesList.test.js +19 -0
- data/webpack/components/AnsibleRolesSwitcher/components/AvailableRolesList.js +52 -0
- data/webpack/components/AnsibleRolesSwitcher/components/AvailableRolesList.test.js +22 -0
- data/webpack/components/AnsibleRolesSwitcher/components/__snapshots__/AnsiblePermissionDenied.test.js.snap +26 -0
- data/webpack/components/AnsibleRolesSwitcher/components/__snapshots__/AnsibleRole.test.js.snap +108 -0
- data/webpack/components/AnsibleRolesSwitcher/components/__snapshots__/AssignedRolesList.test.js.snap +64 -0
- data/webpack/components/AnsibleRolesSwitcher/components/__snapshots__/AvailableRolesList.test.js.snap +54 -0
- data/webpack/components/AnsibleRolesSwitcher/components/withProtectedView.js +14 -0
- data/webpack/components/AnsibleRolesSwitcher/index.js +44 -0
- data/webpack/components/ReportJsonViewer.js +11 -7
- data/webpack/index.js +14 -1
- data/webpack/reducer.js +7 -0
- data/webpack/test_setup.js +11 -0
- metadata +44 -2
@@ -0,0 +1,69 @@
|
|
1
|
+
import api from 'foremanReact/API';
|
2
|
+
import {
|
3
|
+
propsToSnakeCase,
|
4
|
+
propsToCamelCase,
|
5
|
+
} from 'foremanReact/common/helpers';
|
6
|
+
|
7
|
+
import {
|
8
|
+
ANSIBLE_ROLES_REQUEST,
|
9
|
+
ANSIBLE_ROLES_SUCCESS,
|
10
|
+
ANSIBLE_ROLES_FAILURE,
|
11
|
+
ANSIBLE_ROLES_ADD,
|
12
|
+
ANSIBLE_ROLES_REMOVE,
|
13
|
+
ANSIBLE_ROLES_ASSIGNED_PAGE_CHANGE,
|
14
|
+
} from './AnsibleRolesSwitcherConstants';
|
15
|
+
|
16
|
+
export const getAnsibleRoles = (
|
17
|
+
url,
|
18
|
+
initialAssignedRoles,
|
19
|
+
inheritedRoleIds,
|
20
|
+
resourceId,
|
21
|
+
resourceName,
|
22
|
+
pagination,
|
23
|
+
search
|
24
|
+
) => dispatch => {
|
25
|
+
dispatch({ type: ANSIBLE_ROLES_REQUEST });
|
26
|
+
|
27
|
+
const params = {
|
28
|
+
...propsToSnakeCase(pagination || {}),
|
29
|
+
...(search || {}),
|
30
|
+
...propsToSnakeCase({ resourceId, resourceName }),
|
31
|
+
};
|
32
|
+
|
33
|
+
return api
|
34
|
+
.get(url, {}, params)
|
35
|
+
.then(({ data }) =>
|
36
|
+
dispatch({
|
37
|
+
type: ANSIBLE_ROLES_SUCCESS,
|
38
|
+
payload: {
|
39
|
+
initialAssignedRoles,
|
40
|
+
inheritedRoleIds,
|
41
|
+
...propsToCamelCase(data),
|
42
|
+
},
|
43
|
+
})
|
44
|
+
)
|
45
|
+
.catch(error => dispatch(errorHandler(ANSIBLE_ROLES_FAILURE, error)));
|
46
|
+
};
|
47
|
+
|
48
|
+
const errorHandler = (msg, err) => {
|
49
|
+
const error = {
|
50
|
+
errorMsg: 'Failed to fetch Ansible Roles from server.',
|
51
|
+
statusText: err.response.statusText,
|
52
|
+
};
|
53
|
+
return { type: msg, payload: { error } };
|
54
|
+
};
|
55
|
+
|
56
|
+
export const addAnsibleRole = role => ({
|
57
|
+
type: ANSIBLE_ROLES_ADD,
|
58
|
+
payload: { role },
|
59
|
+
});
|
60
|
+
|
61
|
+
export const removeAnsibleRole = role => ({
|
62
|
+
type: ANSIBLE_ROLES_REMOVE,
|
63
|
+
payload: { role },
|
64
|
+
});
|
65
|
+
|
66
|
+
export const changeAssignedPage = pagination => ({
|
67
|
+
type: ANSIBLE_ROLES_ASSIGNED_PAGE_CHANGE,
|
68
|
+
payload: { pagination },
|
69
|
+
});
|
@@ -0,0 +1,7 @@
|
|
1
|
+
export const ANSIBLE_ROLES_REQUEST = 'ANSIBLE_ROLES_REQUEST';
|
2
|
+
export const ANSIBLE_ROLES_SUCCESS = 'ANSIBLE_ROLES_SUCCESS';
|
3
|
+
export const ANSIBLE_ROLES_FAILURE = 'ANSIBLE_ROLES_FAILURE';
|
4
|
+
export const ANSIBLE_ROLES_ADD = 'ANSIBLE_ROLES_ADD';
|
5
|
+
export const ANSIBLE_ROLES_REMOVE = 'ANSIBLE_ROLES_REMOVE';
|
6
|
+
export const ANSIBLE_ROLES_ASSIGNED_PAGE_CHANGE =
|
7
|
+
'ANSIBLE_ROLES_ASSIGNED_PAGE_CHANGE';
|
@@ -0,0 +1,69 @@
|
|
1
|
+
import Immutable from 'seamless-immutable';
|
2
|
+
|
3
|
+
import {
|
4
|
+
ANSIBLE_ROLES_REQUEST,
|
5
|
+
ANSIBLE_ROLES_SUCCESS,
|
6
|
+
ANSIBLE_ROLES_FAILURE,
|
7
|
+
ANSIBLE_ROLES_ADD,
|
8
|
+
ANSIBLE_ROLES_REMOVE,
|
9
|
+
ANSIBLE_ROLES_ASSIGNED_PAGE_CHANGE,
|
10
|
+
} from './AnsibleRolesSwitcherConstants';
|
11
|
+
|
12
|
+
export const initialState = Immutable({
|
13
|
+
loading: false,
|
14
|
+
itemCount: 0,
|
15
|
+
pagination: {
|
16
|
+
page: 1,
|
17
|
+
perPage: 10,
|
18
|
+
},
|
19
|
+
assignedRoles: [],
|
20
|
+
inheritedRoleIds: [],
|
21
|
+
results: [],
|
22
|
+
assignedPagination: {
|
23
|
+
page: 1,
|
24
|
+
perPage: 10,
|
25
|
+
},
|
26
|
+
error: { errorMsg: '', status: '', statusText: '' },
|
27
|
+
});
|
28
|
+
|
29
|
+
const ansibleRoles = (state = initialState, action) => {
|
30
|
+
const { payload } = action;
|
31
|
+
|
32
|
+
switch (action.type) {
|
33
|
+
case ANSIBLE_ROLES_REQUEST:
|
34
|
+
return state.set('loading', true);
|
35
|
+
case ANSIBLE_ROLES_SUCCESS:
|
36
|
+
return state.merge({
|
37
|
+
loading: false,
|
38
|
+
itemCount: Number(payload.subtotal),
|
39
|
+
pagination: {
|
40
|
+
page: Number(payload.page),
|
41
|
+
perPage: Number(payload.perPage),
|
42
|
+
},
|
43
|
+
results: payload.results,
|
44
|
+
assignedRoles: payload.initialAssignedRoles,
|
45
|
+
inheritedRoleIds: payload.inheritedRoleIds,
|
46
|
+
});
|
47
|
+
case ANSIBLE_ROLES_FAILURE:
|
48
|
+
return state.merge({ error: payload.error, loading: false });
|
49
|
+
case ANSIBLE_ROLES_ADD:
|
50
|
+
return state.merge({
|
51
|
+
assignedRoles: state.assignedRoles.concat([payload.role]),
|
52
|
+
itemCount: state.itemCount - 1,
|
53
|
+
});
|
54
|
+
case ANSIBLE_ROLES_REMOVE:
|
55
|
+
return state.merge({
|
56
|
+
assignedRoles: Immutable.flatMap(state.assignedRoles, item =>
|
57
|
+
item.id === payload.role.id ? [] : item
|
58
|
+
),
|
59
|
+
results: state.results.concat([payload.role]),
|
60
|
+
itemCount: state.itemCount + 1,
|
61
|
+
});
|
62
|
+
case ANSIBLE_ROLES_ASSIGNED_PAGE_CHANGE:
|
63
|
+
return state.set('assignedPagination', payload.pagination);
|
64
|
+
default:
|
65
|
+
return state;
|
66
|
+
}
|
67
|
+
};
|
68
|
+
|
69
|
+
export default ansibleRoles;
|
@@ -0,0 +1,68 @@
|
|
1
|
+
import { differenceBy, slice, includes, uniq } from 'lodash';
|
2
|
+
import Immutable from 'seamless-immutable';
|
3
|
+
import { createSelector } from 'reselect';
|
4
|
+
|
5
|
+
const compare = (a, b) => {
|
6
|
+
if (a.name < b.name) {
|
7
|
+
return -1;
|
8
|
+
}
|
9
|
+
if (a.name > b.name) {
|
10
|
+
return 1;
|
11
|
+
}
|
12
|
+
return 0;
|
13
|
+
};
|
14
|
+
|
15
|
+
const switcherState = state => state.foremanAnsible.ansibleRolesSwitcher;
|
16
|
+
|
17
|
+
const markInheritedRoles = (roles, inheritedRoleIds) =>
|
18
|
+
roles.map(role =>
|
19
|
+
includes(inheritedRoleIds, role.id) ? { ...role, inherited: true } : role
|
20
|
+
);
|
21
|
+
|
22
|
+
export const selectResults = state =>
|
23
|
+
Immutable(
|
24
|
+
Immutable.asMutable(uniq(switcherState(state).results)).sort(compare)
|
25
|
+
);
|
26
|
+
|
27
|
+
export const selectItemCount = state => switcherState(state).itemCount;
|
28
|
+
|
29
|
+
export const selectAssignedRoles = state =>
|
30
|
+
Immutable.asMutable(
|
31
|
+
markInheritedRoles(
|
32
|
+
switcherState(state).assignedRoles,
|
33
|
+
switcherState(state).inheritedRoleIds
|
34
|
+
)
|
35
|
+
).sort(compare);
|
36
|
+
|
37
|
+
export const selectAssignedRolesCount = state =>
|
38
|
+
selectAssignedRoles(state).length;
|
39
|
+
export const selectLoading = state => switcherState(state).loading;
|
40
|
+
export const selectAssignedPagination = state =>
|
41
|
+
switcherState(state).assignedPagination;
|
42
|
+
export const selectError = state => switcherState(state).error;
|
43
|
+
export const selectPagination = state => switcherState(state).pagination;
|
44
|
+
|
45
|
+
export const selectPaginationMemoized = createSelector(
|
46
|
+
selectPagination,
|
47
|
+
selectResults,
|
48
|
+
(pagination, results) =>
|
49
|
+
results.length > pagination.perPage
|
50
|
+
? { ...pagination, perPage: results.length }
|
51
|
+
: pagination
|
52
|
+
);
|
53
|
+
|
54
|
+
export const selectUnassignedRoles = createSelector(
|
55
|
+
selectResults,
|
56
|
+
selectAssignedRoles,
|
57
|
+
(results, assignedRoles) => differenceBy(results, assignedRoles, 'id')
|
58
|
+
);
|
59
|
+
|
60
|
+
export const selectAssignedRolesPage = createSelector(
|
61
|
+
selectAssignedPagination,
|
62
|
+
selectAssignedRoles,
|
63
|
+
(assignedPagination, assignedRoles) => {
|
64
|
+
const offset = (assignedPagination.page - 1) * assignedPagination.perPage;
|
65
|
+
|
66
|
+
return slice(assignedRoles, offset, offset + assignedPagination.perPage);
|
67
|
+
}
|
68
|
+
);
|
@@ -0,0 +1,20 @@
|
|
1
|
+
export const ansibleRolesShort = [
|
2
|
+
{ id: 1, name: 'sthirugn.motd' },
|
3
|
+
{ id: 2, name: 'jtyr.ntp' },
|
4
|
+
{ id: 3, name: 'rvm.ruby' },
|
5
|
+
{ id: 4, name: 'geerlingguy.java' },
|
6
|
+
];
|
7
|
+
|
8
|
+
export const ansibleRolesLong = [
|
9
|
+
{ id: 1, name: 'sthirugn.motd' },
|
10
|
+
{ id: 2, name: 'jtyr.ntp' },
|
11
|
+
{ id: 3, name: 'rvm.ruby' },
|
12
|
+
{ id: 4, name: 'geerlingguy.java' },
|
13
|
+
{ id: 5, name: 'naftulikay.golang' },
|
14
|
+
{ id: 6, name: 'theforeman.foreman_scap_client' },
|
15
|
+
{ id: 7, name: 'ansible.ansible' },
|
16
|
+
{ id: 8, name: 'puppet.puppet' },
|
17
|
+
{ id: 9, name: 'chef.chef' },
|
18
|
+
{ id: 10, name: 'salt.salt' },
|
19
|
+
{ id: 11, name: 'anonymous.something' },
|
20
|
+
];
|
data/webpack/components/AnsibleRolesSwitcher/__fixtures__/ansibleRolesSwitcherReducer.fixtures.js
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
import Immutable from 'seamless-immutable';
|
2
|
+
|
3
|
+
import { ansibleRolesLong } from './ansibleRolesData.fixtures';
|
4
|
+
|
5
|
+
export const successPayload = {
|
6
|
+
page: 1,
|
7
|
+
perPage: 5,
|
8
|
+
subtotal: 11,
|
9
|
+
results: ansibleRolesLong,
|
10
|
+
initialAssignedRoles: ansibleRolesLong.slice(3, 6),
|
11
|
+
inheritedRoleIds: [4],
|
12
|
+
};
|
13
|
+
|
14
|
+
export const successState = Immutable({
|
15
|
+
loading: false,
|
16
|
+
itemCount: 11,
|
17
|
+
pagination: {
|
18
|
+
page: 1,
|
19
|
+
perPage: 5,
|
20
|
+
},
|
21
|
+
assignedRoles: [
|
22
|
+
{ ...ansibleRolesLong[3], inherited: true },
|
23
|
+
...ansibleRolesLong.slice(4, 6),
|
24
|
+
],
|
25
|
+
results: ansibleRolesLong,
|
26
|
+
assignedPagination: {
|
27
|
+
page: 1,
|
28
|
+
perPage: 20,
|
29
|
+
},
|
30
|
+
error: { errorMsg: '', status: '', statusText: '' },
|
31
|
+
});
|
32
|
+
|
33
|
+
export const errorPayload = {
|
34
|
+
errorMsg: 'Failed to fetch Ansible Roles from server.',
|
35
|
+
statusText: '500',
|
36
|
+
};
|
@@ -0,0 +1,30 @@
|
|
1
|
+
import { testComponentSnapshotsWithFixtures } from 'react-redux-test-utils';
|
2
|
+
|
3
|
+
import AnsibleRolesSwitcher from '../AnsibleRolesSwitcher';
|
4
|
+
|
5
|
+
jest.mock('foremanReact/components/Pagination/PaginationWrapper');
|
6
|
+
|
7
|
+
const noop = () => {};
|
8
|
+
|
9
|
+
const fixtures = {
|
10
|
+
'should render': {
|
11
|
+
loading: false,
|
12
|
+
pagination: { page: 1, perPage: 12 },
|
13
|
+
itemCount: 20,
|
14
|
+
addAnsibleRole: noop,
|
15
|
+
removeAnsibleRole: noop,
|
16
|
+
getAnsibleRoles: noop,
|
17
|
+
changeAssignedPage: noop,
|
18
|
+
assignedPagination: { page: 1, perPage: 12 },
|
19
|
+
assignedRolesCount: 2,
|
20
|
+
assignedRoles: [],
|
21
|
+
unassignedRoles: [],
|
22
|
+
data: {
|
23
|
+
initialAssignedRoles: [],
|
24
|
+
},
|
25
|
+
error: { statusText: '', errorMsg: '' },
|
26
|
+
},
|
27
|
+
};
|
28
|
+
|
29
|
+
describe('AnsibleRolesSwitcher', () =>
|
30
|
+
testComponentSnapshotsWithFixtures(AnsibleRolesSwitcher, fixtures));
|
@@ -0,0 +1,73 @@
|
|
1
|
+
import { testReducerSnapshotWithFixtures } from 'react-redux-test-utils';
|
2
|
+
|
3
|
+
import reducer, { initialState } from '../AnsibleRolesSwitcherReducer';
|
4
|
+
import { ansibleRolesLong } from '../__fixtures__/ansibleRolesData.fixtures';
|
5
|
+
|
6
|
+
import {
|
7
|
+
successPayload,
|
8
|
+
successState,
|
9
|
+
errorPayload,
|
10
|
+
} from '../__fixtures__/ansibleRolesSwitcherReducer.fixtures';
|
11
|
+
|
12
|
+
import {
|
13
|
+
ANSIBLE_ROLES_REQUEST,
|
14
|
+
ANSIBLE_ROLES_SUCCESS,
|
15
|
+
ANSIBLE_ROLES_FAILURE,
|
16
|
+
ANSIBLE_ROLES_ADD,
|
17
|
+
ANSIBLE_ROLES_REMOVE,
|
18
|
+
ANSIBLE_ROLES_ASSIGNED_PAGE_CHANGE,
|
19
|
+
} from '../AnsibleRolesSwitcherConstants';
|
20
|
+
|
21
|
+
const fixtures = {
|
22
|
+
'should return initial state': {
|
23
|
+
state: initialState,
|
24
|
+
action: {
|
25
|
+
type: undefined,
|
26
|
+
payload: {},
|
27
|
+
},
|
28
|
+
},
|
29
|
+
'should start loading on Ansible roles request': {
|
30
|
+
state: initialState,
|
31
|
+
action: {
|
32
|
+
type: ANSIBLE_ROLES_REQUEST,
|
33
|
+
},
|
34
|
+
},
|
35
|
+
'should stop loading on Ansible roles success': {
|
36
|
+
state: initialState.set('loading', true),
|
37
|
+
action: {
|
38
|
+
type: ANSIBLE_ROLES_SUCCESS,
|
39
|
+
payload: successPayload,
|
40
|
+
},
|
41
|
+
},
|
42
|
+
'should stop loading on Ansible roles error': {
|
43
|
+
state: initialState.set('loading', true),
|
44
|
+
action: {
|
45
|
+
type: ANSIBLE_ROLES_FAILURE,
|
46
|
+
payload: { error: errorPayload },
|
47
|
+
},
|
48
|
+
},
|
49
|
+
'should add Ansible role to assigned': {
|
50
|
+
state: successState,
|
51
|
+
action: {
|
52
|
+
type: ANSIBLE_ROLES_ADD,
|
53
|
+
payload: { role: ansibleRolesLong[8] },
|
54
|
+
},
|
55
|
+
},
|
56
|
+
'should remove Ansible role from assigned': {
|
57
|
+
state: successState,
|
58
|
+
action: {
|
59
|
+
type: ANSIBLE_ROLES_REMOVE,
|
60
|
+
payload: { role: ansibleRolesLong[5] },
|
61
|
+
},
|
62
|
+
},
|
63
|
+
'should change pagination for assigned roles': {
|
64
|
+
state: successState,
|
65
|
+
action: {
|
66
|
+
type: ANSIBLE_ROLES_ASSIGNED_PAGE_CHANGE,
|
67
|
+
payload: { pagination: { page: 20, perPage: 5 } },
|
68
|
+
},
|
69
|
+
},
|
70
|
+
};
|
71
|
+
|
72
|
+
describe('AnsibleRolesSwitcherReducer', () =>
|
73
|
+
testReducerSnapshotWithFixtures(reducer, fixtures));
|
@@ -0,0 +1,43 @@
|
|
1
|
+
import { testSelectorsSnapshotWithFixtures } from 'react-redux-test-utils';
|
2
|
+
|
3
|
+
import {
|
4
|
+
selectUnassignedRoles,
|
5
|
+
selectAssignedRolesPage,
|
6
|
+
} from '../AnsibleRolesSwitcherSelectors';
|
7
|
+
import {
|
8
|
+
ansibleRolesShort,
|
9
|
+
ansibleRolesLong,
|
10
|
+
} from '../__fixtures__/ansibleRolesData.fixtures';
|
11
|
+
|
12
|
+
const stateFactory = obj => ({
|
13
|
+
foremanAnsible: {
|
14
|
+
ansibleRolesSwitcher: obj,
|
15
|
+
},
|
16
|
+
});
|
17
|
+
|
18
|
+
const state1 = {
|
19
|
+
results: ansibleRolesShort,
|
20
|
+
assignedRoles: [{ id: 2 }, { id: 4 }],
|
21
|
+
};
|
22
|
+
|
23
|
+
const state2 = {
|
24
|
+
results: ansibleRolesShort,
|
25
|
+
assignedRoles: [],
|
26
|
+
};
|
27
|
+
|
28
|
+
const state3 = {
|
29
|
+
assignedRoles: ansibleRolesLong,
|
30
|
+
assignedPagination: { page: 2, perPage: 5 },
|
31
|
+
};
|
32
|
+
|
33
|
+
const fixtures = {
|
34
|
+
'should return unassigned roles': () =>
|
35
|
+
selectUnassignedRoles(stateFactory(state1)),
|
36
|
+
'should return all roles when no roles assigned': () =>
|
37
|
+
selectUnassignedRoles(stateFactory(state2)),
|
38
|
+
'should return requested page': () =>
|
39
|
+
selectAssignedRolesPage(stateFactory(state3)),
|
40
|
+
};
|
41
|
+
|
42
|
+
describe('AnsibleRolesSwitcherSelectors', () =>
|
43
|
+
testSelectorsSnapshotWithFixtures(fixtures));
|
@@ -0,0 +1,79 @@
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
2
|
+
|
3
|
+
exports[`AnsibleRolesSwitcher should render 1`] = `
|
4
|
+
<Grid
|
5
|
+
bsClass="container-fluid"
|
6
|
+
componentClass="div"
|
7
|
+
fluid={false}
|
8
|
+
id="ansibleRolesSwitcher"
|
9
|
+
>
|
10
|
+
<Row
|
11
|
+
bsClass="row"
|
12
|
+
className="row-eq-height"
|
13
|
+
componentClass="div"
|
14
|
+
>
|
15
|
+
<AnsibleRolesSwitcherError
|
16
|
+
error={
|
17
|
+
Object {
|
18
|
+
"errorMsg": "",
|
19
|
+
"statusText": "",
|
20
|
+
}
|
21
|
+
}
|
22
|
+
/>
|
23
|
+
<Col
|
24
|
+
bsClass="col"
|
25
|
+
className="available-roles-container"
|
26
|
+
componentClass="div"
|
27
|
+
sm={6}
|
28
|
+
>
|
29
|
+
<div
|
30
|
+
className="available-roles-header"
|
31
|
+
>
|
32
|
+
<h2>
|
33
|
+
Available Ansible Roles
|
34
|
+
</h2>
|
35
|
+
</div>
|
36
|
+
<AvailableRolesList
|
37
|
+
itemCount={20}
|
38
|
+
loading={false}
|
39
|
+
onAddRole={[Function]}
|
40
|
+
onListingChange={[Function]}
|
41
|
+
pagination={
|
42
|
+
Object {
|
43
|
+
"page": 1,
|
44
|
+
"perPage": 12,
|
45
|
+
}
|
46
|
+
}
|
47
|
+
unassignedRoles={Array []}
|
48
|
+
/>
|
49
|
+
</Col>
|
50
|
+
<Col
|
51
|
+
bsClass="col"
|
52
|
+
className="assigned-roles-container"
|
53
|
+
componentClass="div"
|
54
|
+
sm={6}
|
55
|
+
>
|
56
|
+
<div
|
57
|
+
className="assigned-roles-header"
|
58
|
+
>
|
59
|
+
<h2>
|
60
|
+
Assigned Ansible Roles
|
61
|
+
</h2>
|
62
|
+
</div>
|
63
|
+
<AssignedRolesList
|
64
|
+
assignedRoles={Array []}
|
65
|
+
itemCount={2}
|
66
|
+
onPaginationChange={[Function]}
|
67
|
+
onRemoveRole={[Function]}
|
68
|
+
pagination={
|
69
|
+
Object {
|
70
|
+
"page": 1,
|
71
|
+
"perPage": 12,
|
72
|
+
}
|
73
|
+
}
|
74
|
+
resourceName=""
|
75
|
+
/>
|
76
|
+
</Col>
|
77
|
+
</Row>
|
78
|
+
</Grid>
|
79
|
+
`;
|