mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2026-09-09 18:03:21 +00:00
[AAE-12065] add tests
This commit is contained in:
+28
-1
@@ -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';
|
||||
@@ -778,6 +779,32 @@ 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 have any id matching the DEFAULT_OPTION id, while not having an isDefault flag set to true', () => {
|
||||
const call = widget.getDefaultOption(fakeFormOptionEntries[1]);
|
||||
|
||||
expect(call).toEqual(fakeFormOptionEntries[1][0]);
|
||||
});
|
||||
|
||||
it('should get default option from list of options which have any id matching the DEFAULT_OPTION id while also having an isDefault flag set to true', () => {
|
||||
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', () => {
|
||||
const call = widget.getDefaultOption(fakeFormOptionEntries[3]);
|
||||
|
||||
expect(call).toEqual(fakeFormOptionEntries[3][0]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Load selection for linked dropdown (i.e. saved, completed forms)', () => {
|
||||
|
||||
it('should load the selection of a manual type linked dropdown', () => {
|
||||
|
||||
+1
-1
@@ -435,6 +435,6 @@ export class DropdownCloudWidgetComponent extends WidgetComponent implements OnI
|
||||
}
|
||||
|
||||
getDefaultOption(options: FormFieldOption[]): FormFieldOption {
|
||||
return options.find((option: FormFieldOption) => option.isDefault === undefined ? option.id === DEFAULT_OPTION.id : option.isDefault);
|
||||
return options.find((option: FormFieldOption) => option.isDefault ?? option.id === DEFAULT_OPTION.id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,6 +168,71 @@ 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
|
||||
}
|
||||
]
|
||||
];
|
||||
|
||||
export const mockFormVariableWithJson = [
|
||||
new TaskVariableCloud({ name: 'json-form-variable', value: mockCountriesResponse, type: 'json', id: 'fake-id-1' })
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user