mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2026-09-09 18:02:54 +00:00
[MNT-25149] Add unit tests for multivalued select parameter default value (#5262)
* [MNT-25149] Add unit tests for multivalued select parameter default value * address comment on pr
This commit is contained in:
@@ -106,3 +106,23 @@ export const dummyCategoriesConstraints: ActionParameterConstraint[] = [
|
||||
]
|
||||
}
|
||||
];
|
||||
|
||||
export const dummyMultiSelectConstraints: ActionParameterConstraint[] = [
|
||||
{
|
||||
name: 'mock-multi-select-param',
|
||||
constraints: [
|
||||
{
|
||||
value: 'opt:one',
|
||||
label: 'Option One'
|
||||
},
|
||||
{
|
||||
value: 'opt:two',
|
||||
label: 'Option Two'
|
||||
},
|
||||
{
|
||||
value: 'opt:three',
|
||||
label: 'Option Three'
|
||||
}
|
||||
]
|
||||
}
|
||||
];
|
||||
|
||||
@@ -156,6 +156,15 @@ const actionParamLinkToCategoryTransformedMock = {
|
||||
displayLabel: 'Category value'
|
||||
};
|
||||
|
||||
const actionMultiSelectParamTransformedMock: ActionParameterDefinitionTransformed = {
|
||||
name: 'mock-multi-select-param',
|
||||
type: 'd:text',
|
||||
multiValued: true,
|
||||
mandatory: false,
|
||||
displayLabel: 'Mock multi select param',
|
||||
parameterConstraintName: 'mock-multi-select-constraint'
|
||||
};
|
||||
|
||||
const actionParamSecurityGroup: ActionParameterDefinitionTransformed = {
|
||||
name: 'securityGroupId',
|
||||
type: 'd:text',
|
||||
@@ -229,6 +238,16 @@ export const actionNodeTransformedMock: ActionDefinitionTransformed = {
|
||||
parameterDefinitions: [actionParam6TransformedMock]
|
||||
};
|
||||
|
||||
export const actionMultiSelectTransformedMock: ActionDefinitionTransformed = {
|
||||
id: 'mock-action-6-definition',
|
||||
name: 'mock-action-6-definition',
|
||||
description: '',
|
||||
title: 'mock-action-6-definition',
|
||||
applicableTypes: [],
|
||||
trackStatus: false,
|
||||
parameterDefinitions: [actionMultiSelectParamTransformedMock]
|
||||
};
|
||||
|
||||
export const actionsTransformedListMock: ActionDefinitionTransformed[] = [action1TransformedMock, action2TransformedMock];
|
||||
|
||||
export const validActionMock: RuleAction = {
|
||||
|
||||
+46
-1
@@ -34,11 +34,17 @@ import {
|
||||
import { RuleActionUiComponent } from './rule-action.ui-component';
|
||||
import {
|
||||
actionLinkToCategoryTransformedMock,
|
||||
actionMultiSelectTransformedMock,
|
||||
actionNodeTransformedMock,
|
||||
actionsTransformedListMock,
|
||||
securityActionTransformedMock
|
||||
} from '../../mock/actions.mock';
|
||||
import { dummyCategoriesConstraints, dummyConstraints, dummyTagsConstraints } from '../../mock/action-parameter-constraints.mock';
|
||||
import {
|
||||
dummyCategoriesConstraints,
|
||||
dummyConstraints,
|
||||
dummyMultiSelectConstraints,
|
||||
dummyTagsConstraints
|
||||
} from '../../mock/action-parameter-constraints.mock';
|
||||
import { securityMarksResponseMock, updateNotificationMock } from '../../mock/security-marks.mock';
|
||||
import {
|
||||
AlfrescoApiService,
|
||||
@@ -448,4 +454,43 @@ describe('RuleActionUiComponent', () => {
|
||||
expect(component.readOnly).toBe(true);
|
||||
expect(component.form.disabled).toBe(true);
|
||||
});
|
||||
|
||||
describe('Multivalued select parameter default value', () => {
|
||||
const multiSelectActionTitle = 'mock-action-6-definition';
|
||||
|
||||
beforeEach(() => {
|
||||
component.actionDefinitions = [actionMultiSelectTransformedMock];
|
||||
component.parameterConstraints = dummyMultiSelectConstraints;
|
||||
});
|
||||
|
||||
it('should default a multivalued select parameter value to an array with an empty string when no value is set', async () => {
|
||||
fixture.detectChanges();
|
||||
await changeMatSelectValue(multiSelectActionTitle);
|
||||
|
||||
const cardView = getPropertiesCardView();
|
||||
const selectProperty = cardView.properties[0] as CardViewSelectItemModel<string>;
|
||||
|
||||
expect(selectProperty).toBeInstanceOf(CardViewSelectItemModel);
|
||||
expect(selectProperty.multivalued).toBe(true);
|
||||
expect(selectProperty.value).toEqual(['']);
|
||||
});
|
||||
|
||||
it('should preserve an existing array value for a multivalued select parameter', async () => {
|
||||
fixture.detectChanges();
|
||||
await changeMatSelectValue(multiSelectActionTitle);
|
||||
|
||||
component.writeValue({
|
||||
actionDefinitionId: actionMultiSelectTransformedMock.id,
|
||||
params: { 'mock-multi-select-param': ['opt:one', 'opt:three'] }
|
||||
});
|
||||
fixture.detectChanges();
|
||||
|
||||
const cardView = getPropertiesCardView();
|
||||
const selectProperty = cardView.properties[0] as CardViewSelectItemModel<string>;
|
||||
|
||||
expect(selectProperty).toBeInstanceOf(CardViewSelectItemModel);
|
||||
expect(selectProperty.multivalued).toBe(true);
|
||||
expect(selectProperty.value).toEqual(['opt:one', 'opt:three']);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user