AAE-22948 Radio buttons should not display errors / call apis when they're in readOnly state (#9946)

* AAE-22948 Update form-field.model

* AAE-22948 Update radio-buttons.widget

* AAE-22948 Update radio-buttons-cloud.widget

* AAE-22948 Update radio-buttons-cloud

* AAE-22948 Update radio-buttons

* AAE-22948 Improvements

* AAE-22948 Small fix

* AAE-22948 Fix unit
This commit is contained in:
Wiktor Danielewski
2024-07-25 16:19:52 +02:00
committed by GitHub
parent 63d017350d
commit 5d969ccca5
7 changed files with 435 additions and 152 deletions

View File

@@ -960,8 +960,7 @@ describe('FormComponent', () => {
radioField = formFields.find((field) => field.id === 'radio');
expect(dropdownField.value).toBe('dropdown_option_2');
expect(radioField.value.id).toBe('radio_option_3');
expect(radioField.value.name).toBe('Radio option 3');
expect(radioField.value).toBe('radio_option_3');
});
it('should refresh radio buttons value when id is given to data', () => {

View File

@@ -166,6 +166,86 @@ describe('RadioButtonsWidgetComponent', () => {
expect(widget.field.value).toEqual('fake-opt');
});
describe('fetching options from rest api', () => {
const getRadioButtonsWidgetConfig = (readOnly: boolean) => ({
id: 'rest-radio-id',
name: 'Rest Radio Buttons',
type: FormFieldTypes.RADIO_BUTTONS,
readOnly,
optionType: 'rest',
restUrl: '<url>'
});
describe('when NOT readonly Radio Buttons widget is part of readonly form', () => {
it('should NOT request field values from service by task id', () => {
widget.field = new FormFieldModel(new FormModel({ taskId: '<task-id>' }, undefined, true), getRadioButtonsWidgetConfig(false));
spyOn(taskFormService, 'getRestFieldValues').and.returnValue(of([]));
widget.ngOnInit();
expect(taskFormService.getRestFieldValues).not.toHaveBeenCalled();
});
it('should NOT request field values from service by process definition id', () => {
widget.field = new FormFieldModel(
new FormModel({ processDefinitionId: '<definition-id>' }, undefined, true),
getRadioButtonsWidgetConfig(false)
);
spyOn(processDefinitionService, 'getRestFieldValuesByProcessId').and.returnValue(of([]));
widget.ngOnInit();
expect(processDefinitionService.getRestFieldValuesByProcessId).not.toHaveBeenCalled();
});
});
describe('when NOT readonly Radio Buttons widget is part of NOT readonly form', () => {
it('should request field values from service by task id', () => {
widget.field = new FormFieldModel(new FormModel({ taskId: '<task-id>' }, undefined, false), getRadioButtonsWidgetConfig(false));
spyOn(taskFormService, 'getRestFieldValues').and.returnValue(of([]));
widget.ngOnInit();
expect(taskFormService.getRestFieldValues).toHaveBeenCalled();
});
it('should request field values from service by process definition id', () => {
widget.field = new FormFieldModel(
new FormModel({ processDefinitionId: '<definition-id>' }, undefined, false),
getRadioButtonsWidgetConfig(false)
);
spyOn(processDefinitionService, 'getRestFieldValuesByProcessId').and.returnValue(of([]));
widget.ngOnInit();
expect(processDefinitionService.getRestFieldValuesByProcessId).toHaveBeenCalled();
});
});
describe('when readonly Radio Buttons widget is part of NOT readonly form', () => {
it('should request field values from service by task id', () => {
widget.field = new FormFieldModel(new FormModel({ taskId: '<task-id>' }, undefined, false), getRadioButtonsWidgetConfig(true));
spyOn(taskFormService, 'getRestFieldValues').and.returnValue(of([]));
widget.ngOnInit();
expect(taskFormService.getRestFieldValues).toHaveBeenCalled();
});
it('should request field values from service by process definition id', () => {
widget.field = new FormFieldModel(
new FormModel({ processDefinitionId: '<definition-id>' }, undefined, false),
getRadioButtonsWidgetConfig(true)
);
spyOn(processDefinitionService, 'getRestFieldValuesByProcessId').and.returnValue(of([]));
widget.ngOnInit();
expect(processDefinitionService.getRestFieldValuesByProcessId).toHaveBeenCalled();
});
});
});
describe('when template is ready', () => {
let radioButtonWidget: RadioButtonsWidgetComponent;
let fixture: ComponentFixture<RadioButtonsWidgetComponent>;
@@ -190,7 +270,7 @@ describe('RadioButtonsWidgetComponent', () => {
loader = TestbedHarnessEnvironment.loader(fixture);
});
it('should show radio buttons as text when is readonly', async () => {
it('should show Radio Buttons as text when is readonly', async () => {
radioButtonWidget.field = new FormFieldModel(new FormModel({}), {
id: 'radio-id',
name: 'radio-name',
@@ -202,7 +282,7 @@ describe('RadioButtonsWidgetComponent', () => {
expect(element.querySelector('display-text-widget')).toBeDefined();
});
it('should be able to set label property for Radio Button widget', () => {
it('should be able to set label property for Radio Buttons widget', () => {
radioButtonWidget.field = new FormFieldModel(new FormModel({}), {
id: 'radio-id',
name: 'radio-name-label',
@@ -213,7 +293,7 @@ describe('RadioButtonsWidgetComponent', () => {
expect(element.querySelector('label').innerText).toBe('radio-name-label');
});
it('should be able to set a Radio Button widget as required', async () => {
it('should be able to set a Radio Buttons widget as required', async () => {
radioButtonWidget.field = new FormFieldModel(new FormModel({}), {
id: 'radio-id',
name: 'radio-name-label',
@@ -238,7 +318,7 @@ describe('RadioButtonsWidgetComponent', () => {
expect(radioButtonWidget.field.isValid).toBe(true);
});
it('should be able to set another Radio Button widget as required', async () => {
it('should be able to set another Radio Buttons widget as required', async () => {
radioButtonWidget.field = new FormFieldModel(new FormModel({}), {
id: 'radio-id',
name: 'radio-name-label',
@@ -277,7 +357,7 @@ describe('RadioButtonsWidgetComponent', () => {
expect(tooltip).toEqual(radioButtonWidget.field.tooltip);
});
describe('and radioButton is populated via taskId', () => {
describe('and Radio Buttons widget is populated via taskId', () => {
beforeEach(() => {
spyOn(taskFormService, 'getRestFieldValues').and.returnValue(of(restOption));
radioButtonWidget.field = new FormFieldModel(new FormModel({ taskId: 'task-id' }), {
@@ -311,7 +391,7 @@ describe('RadioButtonsWidgetComponent', () => {
});
}));
describe('and radioButton is readonly', () => {
describe('and Radio Buttons widget is readonly', () => {
beforeEach(() => {
radioButtonWidget.field.readOnly = true;
fixture.detectChanges();
@@ -341,7 +421,7 @@ describe('RadioButtonsWidgetComponent', () => {
});
});
describe('and radioButton is populated via processDefinitionId', () => {
describe('and Radio Buttons widget is populated via processDefinitionId', () => {
beforeEach(() => {
radioButtonWidget.field = new FormFieldModel(new FormModel({ processDefinitionId: 'proc-id' }), {
id: 'radio-id',

View File

@@ -55,7 +55,7 @@ export class RadioButtonsWidgetComponent extends WidgetComponent implements OnIn
}
ngOnInit() {
if (this.field?.restUrl) {
if (this.field?.restUrl && !this.field?.form?.readOnly) {
if (this.field.form.taskId) {
this.getOptionsByTaskId();
} else {