Skip to content

Commit

Permalink
feat(): next (#1636)
Browse files Browse the repository at this point in the history
  • Loading branch information
dvoegelin authored Dec 18, 2024
2 parents 3cae4bb + 9e27c94 commit 2968b90
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ export class NovoDatePickerElement implements ControlValueAccessor, OnInit {
@Input()
disabledDateMessage: string;

@Input()
dateForInitialView?: Date;

// Select callback for output
@Output()
onSelect: EventEmitter<any> = new EventEmitter(false);
Expand Down Expand Up @@ -260,7 +263,9 @@ export class NovoDatePickerElement implements ControlValueAccessor, OnInit {
if (this.model) {
this.modelToSelection(this.model);
}
if (this.selection && this.selection.length) {
if (this.dateForInitialView) {
this.updateView(this.dateForInitialView);
} else if (this.selection && this.selection.length) {
this.updateView(this.selection[0]);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const DATE_VALUE_ACCESSOR = {
[ngModel]="value"
[weekStart]="weekStart"
[hideFooter]="hideFooter"
[dateForInitialView]="dateForInitialView"
></novo-date-picker>
</novo-overlay-template>
`,
Expand Down Expand Up @@ -143,6 +144,11 @@ export class NovoDatePickerInputElement implements OnInit, OnChanges, AfterViewI
*/
@Input()
disabledDateMessage: string;
/**
* An optional date/month to show in the DatePicker initially besides the current date/month
*/
@Input()
dateForInitialView?: Date;
/**
* Day of the week the calendar should display first, Sunday=0...Saturday=6
**/
Expand Down
56 changes: 56 additions & 0 deletions projects/novo-elements/src/elements/picker/Picker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,62 @@ describe('Elements: NovoPickerElement', () => {
}));
});

describe('clearValue', () => {
beforeEach(() => {
component._value = 'initialValue';
component.term = 'initialTerm';
component.popup = {
instance: {
customTextValue: 'popupValue',
},
};
component.select = {
emit: jest.fn()
} as unknown;
component.changed = {
emit: jest.fn()
} as unknown;
spyOn(component, 'onModelChange');
spyOn(component, 'hideResults');
});

it('should clear the value, emit the new value, and optionally clear the term', () => {
component.clearValue(true);

expect(component._value).toBeNull();
expect(component.select.emit).toHaveBeenCalledWith(null);
expect(component.changed.emit).toHaveBeenCalledWith({ value: null, rawValue: { label: '', value: null } });
expect(component.onModelChange).toHaveBeenCalledWith(null);
expect(component.term).toBe('');
expect(component.popup.instance.customTextValue).toBeNull();
expect(component.hideResults).toHaveBeenCalled();
});
it('should clear the value and emit the new value without clearing the term', () => {
component.clearValue(false);

expect(component._value).toBeNull();
expect(component.select.emit).toHaveBeenCalledWith(null);
expect(component.changed.emit).toHaveBeenCalledWith({ value: null, rawValue: { label: '', value: null } });
expect(component.onModelChange).toHaveBeenCalledWith(null);
expect(component.term).toBe('initialTerm');
expect(component.popup.instance.customTextValue).toBe('popupValue');
expect(component.hideResults).not.toHaveBeenCalled();
});
it('should not try to clear out customTextValue if popup and popup.instance are undefined', () => {
component.popup = undefined;
component.clearValue(true);

expect(component.popup).toBeUndefined();

component.popup = {
instance: undefined,
};
component.clearValue(true);

expect(component.popup.instance).toBeUndefined();
});
});

describe('Method: registerOnChange()', () => {
it('should be defined.', () => {
expect(component.registerOnChange).toBeDefined();
Expand Down
4 changes: 3 additions & 1 deletion projects/novo-elements/src/elements/picker/Picker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,9 @@ export class NovoPickerElement implements OnInit {

if (wipeTerm) {
this.term = '';
this.popup.instance.customTextValue = null;
if (this.popup?.instance) {
this.popup.instance.customTextValue = null;
}
this.hideResults();
}
this.ref.markForCheck();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,22 @@ export class ConditionBuilderComponent implements OnInit, OnChanges, AfterConten
this.results$ = Promise.resolve(this.fieldConfig.options);
}

/**
* Resets the input and operator view containers, regenerates the field templates,
* and marks the component for change detection.
*
* Use this method after updating form controls to reinitialize the input and
* operator fields so that the view reflects the latest form control changes.
*
* @returns void
*/
resetInputAndOperator(): void {
this._inputOutlet.viewContainer.clear();
this._operatorOutlet.viewContainer.clear();
this.createFieldTemplates();
this.cdr.markForCheck();
}

getField() {
const field = this.parentForm?.value?.field;
if (!field) return null;
Expand Down

0 comments on commit 2968b90

Please sign in to comment.