Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ import { CheckOptionSelectedPipe } from '../../pipes/internal/check-option-selec
import { LabelByValuePipe } from '../../pipes/internal/label-by-value.pipe';
import { CpsMenuHideReason } from '../cps-menu/cps-menu.component';
import { CpsAutocompleteComponent } from './cps-autocomplete.component';
import { CPS_ROOT_FONT_SIZE_SERVICE } from '../../services/cps-root-font-size/cps-root-font-size.service';

const mockRootFontSizeService = {
fontSize: () => 16
};

describe('CpsAutocompleteComponent', () => {
let component: CpsAutocompleteComponent;
Expand All @@ -26,7 +31,14 @@ describe('CpsAutocompleteComponent', () => {
CpsAutocompleteComponent,
NoopAnimationsModule
],
providers: [LabelByValuePipe, CheckOptionSelectedPipe],
providers: [
LabelByValuePipe,
CheckOptionSelectedPipe,
{
provide: CPS_ROOT_FONT_SIZE_SERVICE,
useValue: mockRootFontSizeService
}
],
schemas: [NO_ERRORS_SCHEMA] // Ignore unknown elements and attributes
}).compileComponents();
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { CommonModule, DOCUMENT, isPlatformBrowser } from '@angular/common';
import { CommonModule } from '@angular/common';
import {
AfterViewInit,
ChangeDetectorRef,
Component,
ElementRef,
EventEmitter,
Inject,
inject,
Input,
OnChanges,
OnDestroy,
Expand All @@ -14,7 +14,6 @@
Output,
Self,
ViewChild,
PLATFORM_ID,
type SimpleChanges
} from '@angular/core';
import {
Expand All @@ -25,6 +24,7 @@
} from '@angular/forms';
import { Subject, debounceTime, distinctUntilChanged, takeUntil } from 'rxjs';
import { convertSize } from '../../utils/internal/size-utils';
import { CPS_ROOT_FONT_SIZE_SERVICE } from '../../services/cps-root-font-size/cps-root-font-size.service';
import {
generateUniqueId,
getComputedLabel
Expand Down Expand Up @@ -446,7 +446,10 @@
'cps-autocomplete-option'
);

private _rootFontSizePx = 16;
private readonly _cpsRootFontSizeService = inject(CPS_ROOT_FONT_SIZE_SERVICE);
private get _rootFontSizePx(): number {
return this._cpsRootFontSizeService?.fontSize() ?? 16;

Check warning on line 451 in projects/cps-ui-kit/src/lib/components/cps-autocomplete/cps-autocomplete.component.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
}

private _inputChangeSubject$ = new Subject<string>();
private _destroy$ = new Subject<void>();
Expand All @@ -456,8 +459,6 @@

constructor(
@Self() @Optional() private _control: NgControl,
@Inject(DOCUMENT) private document: Document,
@Inject(PLATFORM_ID) private platformId: object,
private cdRef: ChangeDetectorRef,
private _labelByValue: LabelByValuePipe
) {
Expand All @@ -475,11 +476,6 @@
}

ngOnInit() {
if (isPlatformBrowser(this.platformId)) {
this._rootFontSizePx = parseFloat(
getComputedStyle(this.document.documentElement).fontSize || '16'
);
}
this.virtualScrollItemSizePx =
this._rootFontSizePx * VIRTUAL_SCROLL_ITEM_SIZE_REM;
this.virtualListHeightRem =
Expand Down
Loading
Loading