feat: Added getStartFontSizeFromWeight method tests

This commit is contained in:
Giacomo Ferlaino 2020-03-13 22:10:33 +01:00
parent e0c4c6dd99
commit 2e73f1c9ee
2 changed files with 25 additions and 1 deletions

View file

@ -137,7 +137,7 @@ export class Ng2FittextDirective
} }
} }
private getStartFontSizeFromHeight(): number { getStartFontSizeFromHeight(): number {
return this.container return this.container
? this.container.clientHeight ? this.container.clientHeight
: this.el.nativeElement.parentElement.clientHeight; : this.el.nativeElement.parentElement.clientHeight;

View file

@ -144,4 +144,28 @@ describe('Class: Ng2FittextDirective', () => {
).toBe(true); ).toBe(true);
}); });
}); });
describe('Method: getStartFontSizeFromHeight', () => {
it('Should return the container clientHeight value if the container is present', () => {
const containerClientHeight = 10;
ng2FittextDirective.container = {
clientHeight: containerClientHeight,
} as HTMLElement;
expect(ng2FittextDirective.getStartFontSizeFromHeight()).toEqual(
containerClientHeight
);
});
it('Should return the parentElement clientHeight value if no container is present', () => {
const parentlientHeight = 11;
elMock.nativeElement = {
parentElement: {
clientHeight: parentlientHeight,
},
} as HTMLElement;
expect(ng2FittextDirective.getStartFontSizeFromHeight()).toEqual(
parentlientHeight
);
});
});
}); });