Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #37640 - Apply Loc/Org filter to Host Registration form #10240

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading