Skip to content

Commit

Permalink
duplicate code removed after rebasing my branch
Browse files Browse the repository at this point in the history
  • Loading branch information
jatin2008 committed Jul 27, 2023
1 parent 5f0086c commit 22153a1
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 227 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,6 @@ describe('SearchDateRangeAdvancedTabbedComponent', () => {
};

fixture.detectChanges();

const searchDateRangeAdvancedComponentList = fixture.debugElement.queryAll(By.directive(SearchDateRangeAdvancedComponent));
createdDateRangeComponent = searchDateRangeAdvancedComponentList.find(searchDateRangeAdvancedComponent => (searchDateRangeAdvancedComponent.componentInstance as SearchDateRangeAdvancedComponent).field === 'createdDate').componentInstance;
// modifiedDateRangeComponent = searchDateRangeAdvancedComponentList.find(searchDateRangeAdvancedComponent => searchDateRangeAdvancedComponent.attributes['field'] === 'modifiedDate').componentInstance;
});

it('should be able to generate separate fields on init', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,74 +168,4 @@ export class SearchDateRangeAdvancedTabbedComponent implements SearchWidget, OnI
}
});
}

onQueriesCombined(query: string) {
this.combinedQuery = query;
}

onValuesToDisplayCombined(valuesToDisplay: string) {
this.combinedValuesToDisplay = valuesToDisplay;
}

private generateQuery(value: Partial<SearchDateRangeAdvanced>, field: string): string {
let query = '';
if (value.dateRangeType === DateRangeType.IN_LAST) {
switch(value.inLastValueType) {
case InLastDateType.DAYS:
startDate = startOfDay(subDays(new Date(), parseInt(value.inLastValue)));
break;
case InLastDateType.WEEKS:
startDate = startOfWeek(subWeeks(new Date(), parseInt(value.inLastValue)));
break;
case InLastDateType.MONTHS:
startDate = startOfMonth(subMonths(new Date(), parseInt(value.inLastValue)));
break;
default:
break;
}
endDate = endOfToday();
} else if (value.dateRangeType === DateRangeType.BETWEEN) {
if (value.betweenStartDate && value.betweenEndDate) {
startDate = startOfDay(value.betweenStartDate);
endDate = endOfDay(value.betweenEndDate);
}
}
if (startDate && endDate) {
query = `${field}:['${formatISO(startDate)}' TO '${formatISO(endDate)}']`;
}
return query;
}

private generateDisplayValue(value: Partial<SearchDateRangeAdvanced>): string {
let displayValue = '';
if (value.dateRangeType === DateRangeType.IN_LAST && value.inLastValue) {
displayValue = this.translateService.instant(`SEARCH.DATE_RANGE_ADVANCED.IN_LAST_DISPLAY_LABELS.${value.inLastValueType}`, {
value: value.inLastValue
});
} else if (value.dateRangeType === DateRangeType.BETWEEN && value.betweenStartDate && value.betweenEndDate) {
displayValue = `${format(startOfDay(value.betweenStartDate), this.settings.dateFormat)} - ${format(endOfDay(value.betweenEndDate), this.settings.dateFormat)}`;
}
return displayValue;
}

private updateQuery(value: Partial<SearchDateRangeAdvanced>, field: string) {
this.combinedQuery = '';
this.queryMapByField.set(field, this.generateQuery(value, field));
this.queryMapByField.forEach((query: string) => {
if (query) {
this.combinedQuery = this.combinedQuery ? `${this.combinedQuery} AND ${query}` : `${query}`;
}
});
}

private updateDisplayValue(value: Partial<SearchDateRangeAdvanced>, field: string) {
this.combinedDisplayValue = '';
this.displayValueMapByField.set(field, this.generateDisplayValue(value));
this.displayValueMapByField.forEach((displayValue: string, fieldForDisplayLabel: string) => {
if (displayValue) {
const displayLabelForField = `${this.translateService.instant(this.settings.displayedLabelsByField[fieldForDisplayLabel]).toUpperCase()}: ${displayValue}`;
this.combinedDisplayValue = this.combinedDisplayValue ? `${this.combinedDisplayValue} ${displayLabelForField}` : `${displayLabelForField}`;
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -278,125 +278,4 @@ describe('SearchDateRangeAdvancedComponent', () => {
fixture.detectChanges();
expect(component.changed.emit).toHaveBeenCalledWith(value);
});

it('should not be able to set zero or negative values in In the last input field', () => {
component.form.controls.dateRangeType.setValue(component.DateRangeType.IN_LAST);
fixture.detectChanges();
enterValueInInputField('date-range-advanced-in-last-input', '-5');
fixture.detectChanges();
let inLastInputFieldValue = getElementBySelector('[data-automation-id="date-range-advanced-in-last-input"]').value;
expect(inLastInputFieldValue).toBe('5');

enterValueInInputField('date-range-advanced-in-last-input', '0');
fixture.detectChanges();
inLastInputFieldValue = getElementBySelector('[data-automation-id="date-range-advanced-in-last-input"]').value;
expect(inLastInputFieldValue).toBe('');
});

it('should emit valid as false when form is invalid', () => {
spyOn(component.valid, 'emit');
component.form.controls.dateRangeType.setValue(component.DateRangeType.IN_LAST);
fixture.detectChanges();
enterValueInInputField('date-range-advanced-in-last-input', '');
selectDropdownOption('date-range-advanced-in-last-option-weeks');
fixture.detectChanges();
expect(component.valid.emit).toHaveBeenCalledWith(false);

component.form.controls.dateRangeType.setValue(component.DateRangeType.BETWEEN);
fixture.detectChanges();
expect(component.valid.emit).toHaveBeenCalledWith(false);
});

it('should emit valid as true when form is valid', () => {
spyOn(component.valid, 'emit');
component.form.controls.dateRangeType.setValue(component.DateRangeType.IN_LAST);
fixture.detectChanges();
enterValueInInputField('date-range-advanced-in-last-input', '5');
selectDropdownOption('date-range-advanced-in-last-option-weeks');
fixture.detectChanges();
expect(component.valid.emit).toHaveBeenCalledWith(true);

component.form.controls.dateRangeType.setValue(component.DateRangeType.BETWEEN);
fixture.detectChanges();
component.betweenStartDateFormControl.setValue(startDateSampleValue);
component.betweenEndDateFormControl.setValue(endDateSampleValue);
fixture.detectChanges();
expect(component.valid.emit).toHaveBeenCalledWith(true);
});

it('should not emit values when form is invalid', () => {
spyOn(component.changed, 'emit');
let value = {
dateRangeType: component.DateRangeType.IN_LAST,
inLastValueType: component.InLastDateType.WEEKS,
inLastValue: '',
betweenStartDate: undefined,
betweenEndDate: undefined
};
let dateRangeTypeRadioButton = getElementBySelector('[data-automation-id="date-range-advanced-in-last"] .mat-radio-input');
dateRangeTypeRadioButton.click();
selectDropdownOption('date-range-advanced-in-last-option-weeks');
enterValueInInputField('date-range-advanced-in-last-input', '');
fixture.detectChanges();
expect(component.changed.emit).not.toHaveBeenCalledWith(value);

component.form.patchValue({
dateRangeType: component.DateRangeType.ANY,
inLastValueType: component.InLastDateType.DAYS,
inLastValue: undefined,
betweenStartDate: undefined,
betweenEndDate: undefined
});

value = {
dateRangeType: component.DateRangeType.BETWEEN,
inLastValueType: component.InLastDateType.DAYS,
inLastValue: undefined,
betweenStartDate: '',
betweenEndDate: ''
}
dateRangeTypeRadioButton = getElementBySelector('[data-automation-id="date-range-advanced-between"] .mat-radio-input');
dateRangeTypeRadioButton.click();
fixture.detectChanges();
expect(component.changed.emit).not.toHaveBeenCalledWith(value);
});

it('should emit values when form is valid', () => {
spyOn(component.changed, 'emit');
let value = {
dateRangeType: component.DateRangeType.IN_LAST,
inLastValueType: component.InLastDateType.WEEKS,
inLastValue: 5,
betweenStartDate: null,
betweenEndDate: null
};
let dateRangeTypeRadioButton = getElementBySelector('[data-automation-id="date-range-advanced-in-last"] .mat-radio-input');
dateRangeTypeRadioButton.click();
selectDropdownOption('date-range-advanced-in-last-option-weeks');
enterValueInInputField('date-range-advanced-in-last-input', '5');
fixture.detectChanges();
expect(component.changed.emit).toHaveBeenCalledWith(value);

component.form.patchValue({
dateRangeType: component.DateRangeType.ANY,
inLastValueType: component.InLastDateType.DAYS,
inLastValue: undefined,
betweenStartDate: undefined,
betweenEndDate: undefined
});

value = {
dateRangeType: component.DateRangeType.BETWEEN,
inLastValueType: component.InLastDateType.DAYS,
inLastValue: undefined,
betweenStartDate: startDateSampleValue,
betweenEndDate: endDateSampleValue
}
dateRangeTypeRadioButton = getElementBySelector('[data-automation-id="date-range-advanced-between"] .mat-radio-input');
dateRangeTypeRadioButton.click();
component.betweenStartDateFormControl.setValue(startDateSampleValue);
component.betweenEndDateFormControl.setValue(endDateSampleValue);
fixture.detectChanges();
expect(component.changed.emit).toHaveBeenCalledWith(value);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,6 @@ export class SearchDateRangeAdvancedComponent implements OnInit, OnDestroy {
this.betweenStartDateFormControl.clearValidators();
this.betweenEndDateFormControl.clearValidators();
break;
default:
this.form.controls.inLastValue.clearValidators();
this.betweenStartDateFormControl.clearValidators();
this.betweenEndDateFormControl.clearValidators();
break;
}
this.betweenStartDateFormControl.updateValueAndValidity();
this.betweenEndDateFormControl.updateValueAndValidity();
Expand Down Expand Up @@ -182,27 +177,4 @@ export class SearchDateRangeAdvancedComponent implements OnInit, OnDestroy {
return true;
}
}

// dateChanged(event: Event, formControl: FormControl<Date | null>) {
// clearTimeout(this.dateChangeDebounce);
// this.dateChangeDebounce = window.setTimeout(() => {
// if (!event?.target['value']) {
// formControl.errors.required = true;
// formControl.errors.dateFormatInvalid = false;
// } else {
// const date = parse(event.target['value'], this.dateFormat, new Date());
// if(!isValid(date)) {
// formControl.errors.dateFormatInvalid = true;
// } else {
// formControl.errors.dateFormatInvalid = false;
// formControl.setValue(date);
// }
// }
// }, 500);
// }

onLastDateValueChanged(event: Event) {
const value: string = event.target['value'];
event.target['value'] = value.replace(/\D*0*([1-9]*\d*)/g, '$1');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,4 @@ adf-search-filter-tabbed {
.mat-ink-bar {
display: none;
}

.mat-ink-bar {
display: none;
}
}

0 comments on commit 22153a1

Please sign in to comment.