Skip to content

Commit 42457ad

Browse files
authored
Move 'Use existing settings' to top of Hardware Profile select list (opendatahub-io#4627)
* change order * add unit test * move to new describe block * add not exist assertion
1 parent c75f65c commit 42457ad

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

frontend/src/concepts/hardwareProfiles/HardwareProfileSelect.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ const HardwareProfileSelect: React.FC<HardwareProfileSelectProps> = ({
176176

177177
// allow usage of existing settings if no hardware profile is found
178178
if (allowExistingSettings) {
179-
formattedOptions.push({
179+
formattedOptions.unshift({
180180
key: EXISTING_SETTINGS_KEY,
181181
label: 'Use existing settings',
182182
description: 'Use existing resource requests/limits, tolerations, and node selectors.',

frontend/src/concepts/hardwareProfiles/__tests__/HardwareProfileSelect.spec.tsx

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ const renderComponent = (
6969
hardwareProfiles: HardwareProfileKind[],
7070
currentProject: ProjectKind,
7171
isKueueEnabled: boolean,
72+
allowExistingSettings = false,
7273
) => {
7374
useIsAreaAvailableMock.mockReturnValue({
7475
status: isKueueEnabled,
@@ -112,7 +113,7 @@ const renderComponent = (
112113
hardwareProfilesLoaded
113114
hardwareProfilesError={undefined}
114115
projectScopedHardwareProfiles={[[], true, undefined, () => Promise.resolve()]}
115-
allowExistingSettings={false}
116+
allowExistingSettings={allowExistingSettings}
116117
hardwareProfileConfig={hardwareProfileConfig}
117118
isHardwareProfileSupported={() => true}
118119
onChange={() => null}
@@ -161,3 +162,32 @@ describe('HardwareProfileSelect filtering', () => {
161162
expect(screen.getByText('Node Profile 2')).toBeInTheDocument();
162163
});
163164
});
165+
166+
describe('HardwareProfileSelect - Use existing settings', () => {
167+
it('should not show "Use existing settings" as the first option when allowExistingSettings is false', async () => {
168+
const project = mockProjectK8sResource({});
169+
renderComponent([nodeHardwareProfile, nodeHardwareProfile2], project, false, false);
170+
171+
await userEvent.click(screen.getByRole('button', { name: 'Options menu' }));
172+
173+
const options = screen.getAllByRole('option');
174+
expect(screen.queryByText('Use existing settings')).not.toBeInTheDocument();
175+
expect(options[0]).toHaveTextContent('Node Profile');
176+
expect(options[1]).toHaveTextContent('Node Profile 2');
177+
});
178+
179+
it('should show "Use existing settings" as the first option when allowExistingSettings is true', async () => {
180+
const project = mockProjectK8sResource({});
181+
project.metadata.labels ??= {};
182+
project.metadata.labels[KnownLabels.KUEUE_MANAGED] = 'true';
183+
184+
renderComponent([nodeHardwareProfile, nodeHardwareProfile2], project, false, true);
185+
186+
await userEvent.click(screen.getByRole('button', { name: 'Options menu' }));
187+
188+
const options = screen.getAllByRole('option');
189+
expect(options[0]).toHaveTextContent('Use existing settings');
190+
expect(options[1]).toHaveTextContent('Node Profile');
191+
expect(options[2]).toHaveTextContent('Node Profile 2');
192+
});
193+
});

0 commit comments

Comments
 (0)