mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-07 18:25:09 +00:00
[ACA-4436] - added option for select item to display None (#7113)
* [ACA-4436] - added option for select item to display None * [ACA-4436] - added unit test and fixed wrong default behaviour * [ACA-4436] - fixed property check * [ACA-4436] - fixed unit test * [ACA-4436] - fixed unit test
This commit is contained in:
parent
26d180e661
commit
82a57c9c05
@ -85,7 +85,8 @@ export class ContentTypePropertiesService {
|
|||||||
value: currentValue,
|
value: currentValue,
|
||||||
key: 'nodeType',
|
key: 'nodeType',
|
||||||
editable: true,
|
editable: true,
|
||||||
options$: options$
|
options$: options$,
|
||||||
|
displayNoneOption: false
|
||||||
});
|
});
|
||||||
|
|
||||||
return contentTypeCard;
|
return contentTypeCard;
|
||||||
|
@ -60,6 +60,7 @@ export class CardViewSelectItemComponent extends BaseCardView<CardViewSelectItem
|
|||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
|
console.log
|
||||||
this.getOptions()
|
this.getOptions()
|
||||||
.pipe(takeUntil(this.onDestroy$))
|
.pipe(takeUntil(this.onDestroy$))
|
||||||
.subscribe((options: CardViewSelectItemOption<string>[]) => {
|
.subscribe((options: CardViewSelectItemOption<string>[]) => {
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
[property]="property"
|
[property]="property"
|
||||||
[editable]="editable"
|
[editable]="editable"
|
||||||
[displayEmpty]="displayEmpty"
|
[displayEmpty]="displayEmpty"
|
||||||
[displayNoneOption]="displayNoneOption"
|
[displayNoneOption]="property['displayNoneOption'] !== undefined ? property['displayNoneOption'] : displayNoneOption"
|
||||||
[displayClearAction]="displayClearAction"
|
[displayClearAction]="displayClearAction"
|
||||||
[copyToClipboardAction]="copyToClipboardAction"
|
[copyToClipboardAction]="copyToClipboardAction"
|
||||||
[useChipsForMultiValueProperty]="useChipsForMultiValueProperty"
|
[useChipsForMultiValueProperty]="useChipsForMultiValueProperty"
|
||||||
|
@ -23,6 +23,9 @@ import { CardViewTextItemModel } from '../../models/card-view-textitem.model';
|
|||||||
import { CardViewComponent } from './card-view.component';
|
import { CardViewComponent } from './card-view.component';
|
||||||
import { CoreTestingModule } from '../../../testing/core.testing.module';
|
import { CoreTestingModule } from '../../../testing/core.testing.module';
|
||||||
import { TranslateModule } from '@ngx-translate/core';
|
import { TranslateModule } from '@ngx-translate/core';
|
||||||
|
import { CardViewSelectItemModel } from 'core/card-view/models/card-view-selectitem.model';
|
||||||
|
import { of } from 'rxjs';
|
||||||
|
import { CardViewSelectItemOption } from 'core/card-view/interfaces/card-view-selectitem-properties.interface';
|
||||||
|
|
||||||
describe('CardViewComponent', () => {
|
describe('CardViewComponent', () => {
|
||||||
|
|
||||||
@ -140,4 +143,89 @@ describe('CardViewComponent', () => {
|
|||||||
expect(value).not.toBeNull();
|
expect(value).not.toBeNull();
|
||||||
expect(value.nativeElement.value).toBe('default value');
|
expect(value.nativeElement.value).toBe('default value');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should render the select element with the None option when not set in the properties', async () => {
|
||||||
|
const options: CardViewSelectItemOption<string>[] = [{'label' : 'Option 1', 'key': '1'}, {'label' : 'Option 2', 'key': '2'}];
|
||||||
|
component.properties = [new CardViewSelectItemModel({
|
||||||
|
label: 'My default label',
|
||||||
|
value: '1',
|
||||||
|
default: 'default value',
|
||||||
|
key: 'some-key',
|
||||||
|
editable: true,
|
||||||
|
options$: of(options)
|
||||||
|
})];
|
||||||
|
component.editable = true;
|
||||||
|
component.displayEmpty = false;
|
||||||
|
|
||||||
|
fixture.detectChanges();
|
||||||
|
await fixture.whenStable();
|
||||||
|
|
||||||
|
const labelValue = fixture.debugElement.query(By.css('adf-card-view-selectitem .mat-select-trigger'));
|
||||||
|
labelValue.triggerEventHandler('click', null);
|
||||||
|
fixture.detectChanges();
|
||||||
|
await fixture.whenStable();
|
||||||
|
|
||||||
|
const currentOptions = document.querySelectorAll('mat-option');
|
||||||
|
expect(currentOptions.length).toBe(3);
|
||||||
|
expect(currentOptions[0].innerHTML).toContain('CORE.CARDVIEW.NONE');
|
||||||
|
expect(currentOptions[1].innerHTML).toContain(options[0].label);
|
||||||
|
expect(currentOptions[2].innerHTML).toContain(options[1].label);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should render the select element with the None option when set true in the properties', async () => {
|
||||||
|
const options: CardViewSelectItemOption<string>[] = [{'label' : 'Option 1', 'key': '1'}, {'label' : 'Option 2', 'key': '2'}];
|
||||||
|
component.properties = [new CardViewSelectItemModel({
|
||||||
|
label: 'My default label',
|
||||||
|
value: '1',
|
||||||
|
default: 'default value',
|
||||||
|
key: 'some-key',
|
||||||
|
editable: true,
|
||||||
|
displayNoneOption: true,
|
||||||
|
options$: of(options)
|
||||||
|
})];
|
||||||
|
component.editable = true;
|
||||||
|
component.displayEmpty = false;
|
||||||
|
|
||||||
|
fixture.detectChanges();
|
||||||
|
await fixture.whenStable();
|
||||||
|
|
||||||
|
const labelValue = fixture.debugElement.query(By.css('adf-card-view-selectitem .mat-select-trigger'));
|
||||||
|
labelValue.triggerEventHandler('click', null);
|
||||||
|
fixture.detectChanges();
|
||||||
|
await fixture.whenStable();
|
||||||
|
|
||||||
|
const currentOptions = document.querySelectorAll('mat-option');
|
||||||
|
expect(currentOptions.length).toBe(3);
|
||||||
|
expect(currentOptions[0].innerHTML).toContain('CORE.CARDVIEW.NONE');
|
||||||
|
expect(currentOptions[1].innerHTML).toContain(options[0].label);
|
||||||
|
expect(currentOptions[2].innerHTML).toContain(options[1].label);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not render the select element with the None option when set false in the properties', async () => {
|
||||||
|
const options: CardViewSelectItemOption<string>[] = [{'label' : 'Option 1', 'key': '1'}, {'label' : 'Option 2', 'key': '2'}];
|
||||||
|
component.properties = [new CardViewSelectItemModel({
|
||||||
|
label: 'My default label',
|
||||||
|
value: '1',
|
||||||
|
default: 'default value',
|
||||||
|
key: 'some-key',
|
||||||
|
editable: true,
|
||||||
|
displayNoneOption: false,
|
||||||
|
options$: of(options)
|
||||||
|
})];
|
||||||
|
component.editable = true;
|
||||||
|
component.displayEmpty = false;
|
||||||
|
|
||||||
|
fixture.detectChanges();
|
||||||
|
await fixture.whenStable();
|
||||||
|
|
||||||
|
const labelValue = fixture.debugElement.query(By.css('adf-card-view-selectitem .mat-select-trigger'));
|
||||||
|
labelValue.triggerEventHandler('click', null);
|
||||||
|
fixture.detectChanges();
|
||||||
|
await fixture.whenStable();
|
||||||
|
|
||||||
|
const currentOptions = document.querySelectorAll('mat-option');
|
||||||
|
expect(currentOptions.length).toBe(2);
|
||||||
|
expect(currentOptions[0].innerHTML).toContain(options[0].label);
|
||||||
|
expect(currentOptions[1].innerHTML).toContain(options[1].label);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -26,4 +26,5 @@ export interface CardViewSelectItemOption<T> {
|
|||||||
export interface CardViewSelectItemProperties<T> extends CardViewItemProperties {
|
export interface CardViewSelectItemProperties<T> extends CardViewItemProperties {
|
||||||
value: string | number;
|
value: string | number;
|
||||||
options$: Observable<CardViewSelectItemOption<T>[]>;
|
options$: Observable<CardViewSelectItemOption<T>[]>;
|
||||||
|
displayNoneOption?: boolean;
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,22 @@ describe('CardViewSelectItemModel', () => {
|
|||||||
|
|
||||||
itemModel.displayValue.subscribe((value) => {
|
itemModel.displayValue.subscribe((value) => {
|
||||||
expect(value).toBe(mockData[1].label);
|
expect(value).toBe(mockData[1].label);
|
||||||
|
expect(itemModel.displayNoneOption).toBe(true);
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
it('should set true for none option when passed through the properties', fakeAsync(() => {
|
||||||
|
properties.displayNoneOption = true;
|
||||||
|
const itemModel = new CardViewSelectItemModel(properties);
|
||||||
|
|
||||||
|
expect(itemModel.displayNoneOption).toBe(true);
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should set false for none option when passed through the properties', fakeAsync(() => {
|
||||||
|
properties.displayNoneOption = false;
|
||||||
|
const itemModel = new CardViewSelectItemModel(properties);
|
||||||
|
|
||||||
|
expect(itemModel.displayNoneOption).toBe(false);
|
||||||
|
}));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -25,12 +25,15 @@ import { switchMap } from 'rxjs/operators';
|
|||||||
export class CardViewSelectItemModel<T> extends CardViewBaseItemModel implements CardViewItem, DynamicComponentModel {
|
export class CardViewSelectItemModel<T> extends CardViewBaseItemModel implements CardViewItem, DynamicComponentModel {
|
||||||
type: string = 'select';
|
type: string = 'select';
|
||||||
options$: Observable<CardViewSelectItemOption<T>[]>;
|
options$: Observable<CardViewSelectItemOption<T>[]>;
|
||||||
|
displayNoneOption: boolean;
|
||||||
|
|
||||||
valueFetch$: Observable<string> = null;
|
valueFetch$: Observable<string> = null;
|
||||||
|
|
||||||
constructor(cardViewSelectItemProperties: CardViewSelectItemProperties<T>) {
|
constructor(cardViewSelectItemProperties: CardViewSelectItemProperties<T>) {
|
||||||
super(cardViewSelectItemProperties);
|
super(cardViewSelectItemProperties);
|
||||||
|
|
||||||
|
this.displayNoneOption = cardViewSelectItemProperties.displayNoneOption !== undefined ? cardViewSelectItemProperties.displayNoneOption : true;
|
||||||
|
|
||||||
this.options$ = cardViewSelectItemProperties.options$;
|
this.options$ = cardViewSelectItemProperties.options$;
|
||||||
|
|
||||||
this.valueFetch$ = this.options$.pipe(
|
this.valueFetch$ = this.options$.pipe(
|
||||||
|
@ -163,6 +163,7 @@ export class TaskHeaderCloudComponent implements OnInit, OnDestroy, OnChanges {
|
|||||||
value: this.taskDetails.priority.toString(),
|
value: this.taskDetails.priority.toString(),
|
||||||
key: 'priority',
|
key: 'priority',
|
||||||
editable: true,
|
editable: true,
|
||||||
|
displayNoneOption: false,
|
||||||
options$: of(this.taskCloudService.priorities)
|
options$: of(this.taskCloudService.priorities)
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user