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

FI-2685: Allow locking individual checkboxes #522

Merged
merged 15 commits into from
Oct 18, 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
9 changes: 7 additions & 2 deletions client/src/components/InputsModal/FieldLabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@ const FieldLabel: FC<FieldLabelProps> = ({ requirement, isMissingInput = false }

const fieldLabelText = (requirement.title || requirement.name) as string;

// Radio buttons will always have an input value
const requiredLabel = !requirement.optional && requirement.type !== 'radio' ? ' (required)' : '';
// Radio buttons and single checkboxes will always have an input value
const requiredLabel =
!requirement.optional &&
requirement.type !== 'radio' &&
!(requirement.type === 'checkbox' && !requirement.options?.list_options?.length)
? ' (required)'
: '';

const lockedIcon = requirement.locked && (
<LockIcon fontSize="small" className={classes.lockedIcon} />
Expand Down
1 change: 1 addition & 0 deletions client/src/components/InputsModal/InputCheckboxGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ const InputCheckboxGroup: FC<InputCheckboxGroupProps> = ({
size="small"
color="secondary"
name={option.value}
disabled={option.locked}
checked={values[option.value as keyof CheckboxValues] || false}
onBlur={(e) => {
if (e.currentTarget === e.target) {
Expand Down
8 changes: 2 additions & 6 deletions client/src/components/InputsModal/InputSingleCheckbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,8 @@ const InputSingleCheckbox: FC<InputSingleCheckboxProps> = ({
const isMissingInput =
hasBeenModified && !requirement.optional && inputsMap.get(requirement.name) === false;

const fieldLabel = (
<>
<FieldLabel requirement={requirement} isMissingInput={isMissingInput} />{' '}
{requirement.optional ? '' : '*'}
</>
);
// No "required" formatting because single checkboxes always have a value assigned
const fieldLabel = <FieldLabel requirement={requirement} isMissingInput={isMissingInput} />;

useEffect(() => {
const inputsValue = inputsMap.get(requirement.name) as string;
Expand Down
1 change: 1 addition & 0 deletions client/src/models/testSuiteModels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export type FooterLink = {
export interface InputOption {
label: string;
value: string;
locked?: boolean;
}

export interface InputValues {
Expand Down
50 changes: 48 additions & 2 deletions dev_suites/dev_demo_ig_stu1/groups/demo_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ class DemoGroup < Inferno::TestGroup
end

test 'checkbox group input' do
input :checkbox,
input :checkbox_group,
title: 'Checkbox Group Input Example',
type: 'checkbox',
description: 'Checkbox description',
Expand All @@ -297,7 +297,53 @@ class DemoGroup < Inferno::TestGroup
]
}

run { info "Received the following 'checkbox' variable: '#{checkbox}'" }
run { info "Received the following 'checkbox' variable: '#{checkbox_group}'" }
end

test 'locked checkbox group input' do
input :locked_checkbox_group,
title: 'Locked Checkbox Group Input Example',
type: 'checkbox',
description: 'Checkbox description',
default: ['value2'],
optional: false,
options: {
list_options: [
{
label: 'Label 1',
value: 'value1'
}, {
label: 'Label 2',
value: 'value2',
locked: true
}
]
}

run { info "Received the following 'checkbox' variable: '#{locked_checkbox_group}'" }
end

test 'single checkbox input' do
input :single_checkbox,
title: 'Single Checkbox Input Example',
type: 'checkbox',
description: 'Checkbox description',
default: ['true'],
optional: false

run { info "Received the following 'checkbox' variable: '#{single_checkbox}'" }
end

test 'locked single checkbox input' do
input :locked_single_checkbox,
title: 'Locked Single Checkbox Input Example',
type: 'checkbox',
description: 'Checkbox description',
default: ['true'],
optional: false,
locked: true

run { info "Received the following 'checkbox' variable: '#{locked_single_checkbox}'" }
end

test 'OAuth Credentials group input' do
Expand Down
23 changes: 22 additions & 1 deletion spec/inferno/utils/preset_template_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,35 @@
_options: { list_options: [{ label: 'Label 1', value: 'value1' },
{ label: 'Label 2', value: 'value2' }] },
value: nil },
{ name: 'checkbox',
{ name: 'checkbox_group',
_type: 'checkbox',
_title: 'Checkbox Group Input Example',
_description: 'Checkbox description',
_optional: false,
_options: { list_options: [{ label: 'Label 1', value: 'value1' },
{ label: 'Label 2', value: 'value2' }] },
value: ['value2'] },
{ name: 'locked_checkbox_group',
_type: 'checkbox',
_title: 'Locked Checkbox Group Input Example',
_description: 'Checkbox description',
_optional: false,
_options: { list_options: [{ label: 'Label 1', value: 'value1' },
{ label: 'Label 2', locked: true, value: 'value2' }] },
value: ['value2'] },
{ name: 'single_checkbox',
_type: 'checkbox',
_title: 'Single Checkbox Input Example',
_description: 'Checkbox description',
_optional: false,
value: ['true'] },
{ name: 'locked_single_checkbox',
_type: 'checkbox',
_title: 'Locked Single Checkbox Input Example',
_description: 'Checkbox description',
_optional: false,
_locked: true,
value: ['true'] },
{ name: 'credentials',
_description: 'OAuth Credentials description',
_optional: true,
Expand Down
Loading