From 22153a15514bd574003a02a0616771e2d84e480e Mon Sep 17 00:00:00 2001 From: Jatin_Chugh Date: Mon, 24 Jul 2023 14:52:35 +0530 Subject: [PATCH] duplicate code removed after rebasing my branch --- ...te-range-advanced-tabbed.component.spec.ts | 4 - ...ch-date-range-advanced-tabbed.component.ts | 70 ---------- ...arch-date-range-advanced.component.spec.ts | 121 ------------------ .../search-date-range-advanced.component.ts | 28 ---- .../search-filter-tabbed.component.scss | 4 - 5 files changed, 227 deletions(-) diff --git a/lib/content-services/src/lib/search/components/search-date-range-advanced-tabbed/search-date-range-advanced-tabbed.component.spec.ts b/lib/content-services/src/lib/search/components/search-date-range-advanced-tabbed/search-date-range-advanced-tabbed.component.spec.ts index 7309eff9d8a..c57141917e8 100644 --- a/lib/content-services/src/lib/search/components/search-date-range-advanced-tabbed/search-date-range-advanced-tabbed.component.spec.ts +++ b/lib/content-services/src/lib/search/components/search-date-range-advanced-tabbed/search-date-range-advanced-tabbed.component.spec.ts @@ -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', () => { diff --git a/lib/content-services/src/lib/search/components/search-date-range-advanced-tabbed/search-date-range-advanced-tabbed.component.ts b/lib/content-services/src/lib/search/components/search-date-range-advanced-tabbed/search-date-range-advanced-tabbed.component.ts index 905d7db16d1..2e20e2b6105 100644 --- a/lib/content-services/src/lib/search/components/search-date-range-advanced-tabbed/search-date-range-advanced-tabbed.component.ts +++ b/lib/content-services/src/lib/search/components/search-date-range-advanced-tabbed/search-date-range-advanced-tabbed.component.ts @@ -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, 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): 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, 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, 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}`; - } - }); - } } diff --git a/lib/content-services/src/lib/search/components/search-date-range-advanced-tabbed/search-date-range-advanced/search-date-range-advanced.component.spec.ts b/lib/content-services/src/lib/search/components/search-date-range-advanced-tabbed/search-date-range-advanced/search-date-range-advanced.component.spec.ts index 099d6509b12..fa570f6c6be 100644 --- a/lib/content-services/src/lib/search/components/search-date-range-advanced-tabbed/search-date-range-advanced/search-date-range-advanced.component.spec.ts +++ b/lib/content-services/src/lib/search/components/search-date-range-advanced-tabbed/search-date-range-advanced/search-date-range-advanced.component.spec.ts @@ -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); - }); }); diff --git a/lib/content-services/src/lib/search/components/search-date-range-advanced-tabbed/search-date-range-advanced/search-date-range-advanced.component.ts b/lib/content-services/src/lib/search/components/search-date-range-advanced-tabbed/search-date-range-advanced/search-date-range-advanced.component.ts index ccb6947089e..d0792a9c196 100644 --- a/lib/content-services/src/lib/search/components/search-date-range-advanced-tabbed/search-date-range-advanced/search-date-range-advanced.component.ts +++ b/lib/content-services/src/lib/search/components/search-date-range-advanced-tabbed/search-date-range-advanced/search-date-range-advanced.component.ts @@ -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(); @@ -182,27 +177,4 @@ export class SearchDateRangeAdvancedComponent implements OnInit, OnDestroy { return true; } } - - // dateChanged(event: Event, formControl: FormControl) { - // 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'); - } } diff --git a/lib/content-services/src/lib/search/components/search-filter-tabbed/search-filter-tabbed.component.scss b/lib/content-services/src/lib/search/components/search-filter-tabbed/search-filter-tabbed.component.scss index ff0f0f82f5b..fa74c8d502d 100644 --- a/lib/content-services/src/lib/search/components/search-filter-tabbed/search-filter-tabbed.component.scss +++ b/lib/content-services/src/lib/search/components/search-filter-tabbed/search-filter-tabbed.component.scss @@ -17,8 +17,4 @@ adf-search-filter-tabbed { .mat-ink-bar { display: none; } - - .mat-ink-bar { - display: none; - } }