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

[AAE-12065] Add isDefault flag to dropdown #8771

Closed
wants to merge 4 commits into from
Closed
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 @@ -20,4 +20,5 @@
export interface FormFieldOption {
id: string;
name: string;
isDefault?: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ import {
mockRestDropdownOptions,
mockSecondRestDropdownOptions,
mockVariablesWithDefaultJson,
mockProcessVariablesWithJson
mockProcessVariablesWithJson,
fakeFormOptionEntries
} from '../../../mocks/dropdown.mock';
import { OverlayContainer } from '@angular/cdk/overlay';
import { TaskVariableCloud } from '../../../models/task-variable-cloud.model';
Expand Down Expand Up @@ -778,6 +779,38 @@ describe('DropdownCloudWidgetComponent', () => {
});
});

describe('Default option', () => {
it('should not get default option from list of options which do not have any id matching the DEFAULT_OPTION id', () => {
const call = widget.getDefaultOption(fakeFormOptionEntries[0]);

expect(call).toEqual(undefined);
});

it('should get default option from list of options which has an id matching the DEFAULT_OPTION id, while not having an isDefault flag on that option', () => {
const call = widget.getDefaultOption(fakeFormOptionEntries[1]);

expect(call).toEqual(fakeFormOptionEntries[1][0]);
});

it('should get default option from list of options which has an id matching the DEFAULT_OPTION id while also having an isDefault flag set to true on that option', () => {
const call = widget.getDefaultOption(fakeFormOptionEntries[2]);

expect(call).toEqual(fakeFormOptionEntries[2][0]);
});

it('should get default option from list of options which has an isDefault flag set to true, despite the option id not matching the DEFAULT_OPTION id', () => {
const call = widget.getDefaultOption(fakeFormOptionEntries[3]);

expect(call).toEqual(fakeFormOptionEntries[3][0]);
});

it('should not get default option from list of options which has an id matching the DEFAULT_OPTION id, while having an isDefault flag set to false on that option', () => {
const call = widget.getDefaultOption(fakeFormOptionEntries[4]);

expect(call).toEqual(undefined);
});
});

describe('Load selection for linked dropdown (i.e. saved, completed forms)', () => {

it('should load the selection of a manual type linked dropdown', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,6 @@ export class DropdownCloudWidgetComponent extends WidgetComponent implements OnI
}

getDefaultOption(options: FormFieldOption[]): FormFieldOption {
return options.find((option: FormFieldOption) => option.id === DEFAULT_OPTION.id);
return options.find((option: FormFieldOption) => option.isDefault ?? option.id === DEFAULT_OPTION.id);
}
}
82 changes: 82 additions & 0 deletions lib/process-services-cloud/src/lib/form/mocks/dropdown.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,88 @@ export const mockCountriesResponse = {
]
};

export const fakeFormOptionEntries = [
[
{
id: 'id_1',
name: 'name_1'
},
{
id: 'id_1',
name: 'name_2'
},
{
id: 'id_3',
name: 'name_3'
}
],
[
{
id: 'empty',
name: 'name_1'
},
{
id: 'id_1',
name: 'name_2'
},
{
id: 'id_3',
name: 'name_3'
}
],
[
{
id: 'empty',
name: 'name_1',
isDefault: true
},
{
id: 'id_1',
name: 'name_2',
isDefault: false
},
{
id: 'id_3',
name: 'name_3',
isDefault: false
}
],
[
{
id: 'id_1',
name: 'name_1',
isDefault: true
},
{
id: 'id_1',
name: 'name_2',
isDefault: false
},
{
id: 'id_3',
name: 'name_3',
isDefault: false
}
],
[
{
id: 'empty',
name: 'name_1',
isDefault: false
},
{
id: 'id_1',
name: 'name_2',
isDefault: false
},
{
id: 'id_3',
name: 'name_3',
isDefault: false
}
]
];

export const mockFormVariableWithJson = [
new TaskVariableCloud({ name: 'json-form-variable', value: mockCountriesResponse, type: 'json', id: 'fake-id-1' })
];
Expand Down
Loading