Skip to content

Commit

Permalink
Fixes #37640 - Apply Loc/Org filter to Host Registration form
Browse files Browse the repository at this point in the history
  • Loading branch information
nadjaheitmann authored and m-bucher committed Jul 19, 2024
1 parent a39297e commit 5ac8bba
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ Object {
"hostgroupId": undefined,
"insecure": false,
"jwtExpiration": 4,
"locationId": undefined,
"locationId": 4,
"operatingsystemId": undefined,
"organizationId": undefined,
"organizationId": 3,
"packages": "",
"repoData": Array [],
"setupInsights": "",
Expand All @@ -39,8 +39,8 @@ Object {
"payload": Object {
"key": "REGISTRATION_COMMANDS_DATA",
"params": Object {
"location_id": undefined,
"organization_id": undefined,
"location_id": 4,
"organization_id": 3,
},
"url": "/hosts/register/data",
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,19 @@ export const formData = {
id: 1,
name: 'Default Organization',
},
{
id: 3,
name: 'ACME',
},
],
locations: [
{
id: 2,
name: 'Default Location',
},
{
id: 4,
name: 'munich',
},
],
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,16 @@ import RegistrationCommandsPage from '../index'
import { APIMiddleware } from '../../../../redux/API';
import apiReducer from '../../../../redux/API/APIReducer';
import { spySelector } from './fixtures'
import ForemanContext from '../../../../Root/Context/ForemanContext';

jest.mock('../../../../components/common/Slot', () => () => (<></>));
jest
.spyOn(ForemanContext, 'useForemanOrganization')
.mockReturnValue({ id: 3, title: 'ACME' });
jest
.spyOn(ForemanContext, 'useForemanLocation')
.mockReturnValue({ id: 4, title: 'munich' });


spySelector(selectors);

Expand All @@ -29,6 +37,16 @@ describe('RegistrationCommandsPage integration', () => {
expect(submitBtn.hasClass('pf-m-disabled')).toBe(false);
expect(commandField.length).toBe(0);

// check that only current Org and Loc are selectable
const organizationSelectOptions = component.find('#reg_organization').find('FormSelectOption');
expect(organizationSelectOptions.length).toBe(2);
expect(organizationSelectOptions.findWhere((n) => n.prop('value') === 1).length).toBe(0);
expect(organizationSelectOptions.findWhere((n) => n.prop('value') === 3).length).toBe(2);
const locationSelectOptions = component.find('#reg_location').find('FormSelectOption');
expect(locationSelectOptions.length).toBe(2);
expect(locationSelectOptions.findWhere((n) => n.prop('value') === 2).length).toBe(0);
expect(locationSelectOptions.findWhere((n) => n.prop('value') === 4).length).toBe(2);

submitBtn.simulate('click');
integrationTestHelper.takeStoreAndLastActionSnapshot('generated command');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,14 @@ const RegistrationCommandsPage = () => {
const isGenerating = apiStatusCommand === STATUS.PENDING;

// Form data
const organizations = useSelector(selectOrganizations);
const locations = useSelector(selectLocations);
let organizations = useSelector(selectOrganizations);
if (currentOrganization !== undefined) {
organizations = organizations.filter(f => f.id === currentOrganization.id);
}
let locations = useSelector(selectLocations);
if (currentLocation !== undefined) {
locations = locations.filter(f => f.id === currentLocation.id);
}
const hostGroups = useSelector(selectHostGroups);
const operatingSystems = useSelector(selectOperatingSystems);
const operatingSystemTemplate = useSelector(selectOperatingSystemTemplate);
Expand Down

0 comments on commit 5ac8bba

Please sign in to comment.