diff --git a/webpack/assets/javascripts/react_app/routes/RegistrationCommands/RegistrationCommandsPage/__tests__/__snapshots__/integration.test.js.snap b/webpack/assets/javascripts/react_app/routes/RegistrationCommands/RegistrationCommandsPage/__tests__/__snapshots__/integration.test.js.snap index 352a3bd8f12..f5db2067cd8 100644 --- a/webpack/assets/javascripts/react_app/routes/RegistrationCommands/RegistrationCommandsPage/__tests__/__snapshots__/integration.test.js.snap +++ b/webpack/assets/javascripts/react_app/routes/RegistrationCommands/RegistrationCommandsPage/__tests__/__snapshots__/integration.test.js.snap @@ -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": "", @@ -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", }, diff --git a/webpack/assets/javascripts/react_app/routes/RegistrationCommands/RegistrationCommandsPage/__tests__/fixtures.js b/webpack/assets/javascripts/react_app/routes/RegistrationCommands/RegistrationCommandsPage/__tests__/fixtures.js index 7d2ff2a4754..7b9a4a49411 100644 --- a/webpack/assets/javascripts/react_app/routes/RegistrationCommands/RegistrationCommandsPage/__tests__/fixtures.js +++ b/webpack/assets/javascripts/react_app/routes/RegistrationCommands/RegistrationCommandsPage/__tests__/fixtures.js @@ -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', + }, ], }; diff --git a/webpack/assets/javascripts/react_app/routes/RegistrationCommands/RegistrationCommandsPage/__tests__/integration.test.js b/webpack/assets/javascripts/react_app/routes/RegistrationCommands/RegistrationCommandsPage/__tests__/integration.test.js index 59816f5cde5..d7e45b634d3 100644 --- a/webpack/assets/javascripts/react_app/routes/RegistrationCommands/RegistrationCommandsPage/__tests__/integration.test.js +++ b/webpack/assets/javascripts/react_app/routes/RegistrationCommands/RegistrationCommandsPage/__tests__/integration.test.js @@ -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); @@ -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'); }); diff --git a/webpack/assets/javascripts/react_app/routes/RegistrationCommands/RegistrationCommandsPage/index.js b/webpack/assets/javascripts/react_app/routes/RegistrationCommands/RegistrationCommandsPage/index.js index 27b81b3f410..24cfbaaae64 100644 --- a/webpack/assets/javascripts/react_app/routes/RegistrationCommands/RegistrationCommandsPage/index.js +++ b/webpack/assets/javascripts/react_app/routes/RegistrationCommands/RegistrationCommandsPage/index.js @@ -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);