From 7fdf075a479f7a578d59d8e2b70d42c76df0a904 Mon Sep 17 00:00:00 2001 From: Aleksandar Kamenov Date: Thu, 23 Jan 2020 15:50:03 +0200 Subject: [PATCH] fix(progressbar): applying latest review changes Closes #5903 --- CHANGELOG.md | 5 +- .../services/direction/directionality.spec.ts | 62 ++++++++++++------- .../lib/services/direction/directionality.ts | 5 +- 3 files changed, 47 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 85cf87d581e..d5d6649be76 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,8 +21,6 @@ All notable changes for each version of this project will be documented in this - `IgxCarousel`: - **Breaking Changes** -The carousel slides are no longer array, they are changed to QueryList. - **Behavioural change** - When slides are more than 5, a label is shown instead of the indicators. The count limit of visible indicators can be changed with the input `maximumIndicatorsCount` -- Added `Directionality` service providing information about the text direction of the element's content. - ### New Features - `IgxGrid`, `IgxTreeGrid`, `IgxHierarchicalGrid`: @@ -107,6 +105,9 @@ All notable changes for each version of this project will be documented in this @include igx-progress-circular($theme); ``` + - RTL support +- `IgxLinearProgressBar`: + - RTL support ## 8.2.6 diff --git a/projects/igniteui-angular/src/lib/services/direction/directionality.spec.ts b/projects/igniteui-angular/src/lib/services/direction/directionality.spec.ts index 7a860c33da8..0bddaadc078 100644 --- a/projects/igniteui-angular/src/lib/services/direction/directionality.spec.ts +++ b/projects/igniteui-angular/src/lib/services/direction/directionality.spec.ts @@ -1,13 +1,14 @@ -import { TestBed } from '@angular/core/testing'; +import { TestBed, async, inject } from '@angular/core/testing'; import { Component } from '@angular/core'; import { IgxDirectionality, DIR_DOCUMENT } from './directionality'; +import { DOCUMENT } from '@angular/common'; interface FakeDoc { body: { dir?: string }; documentElement: { dir?: string }; } -describe('IgxDirectionality', () => { +describe('IgxDirectionality DI', () => { let fakeDoc: FakeDoc; beforeEach(async(() => { fakeDoc = {body: {}, documentElement: {}}; @@ -16,48 +17,65 @@ describe('IgxDirectionality', () => { declarations: [ InjectsIgxDirectionalityComponent ], - providers: [{provide: DIR_DOCUMENT, useFactory: () => fakeDoc}], }).compileComponents(); - }); + })); - it('should read dir from html if not specified on the body', () => { - const expectedRes = 'rtl'; - fakeDoc.documentElement.dir = expectedRes; + it('should inject the document through the injectionToken properly', () => { + const injectionToken = TestBed.inject(DIR_DOCUMENT); + const document = TestBed.inject(DOCUMENT); + + expect(injectionToken).toEqual(document); + expect(injectionToken).toEqual(jasmine.any(Document)); + expect(document).toBeTruthy(jasmine.any(Document)); + }); + it('should read dir from html if not specified on the body', inject([DOCUMENT], () => { const fixture = TestBed.createComponent(InjectsIgxDirectionalityComponent); const component = fixture.debugElement.componentInstance; - expect(component.dir.value).toEqual(expectedRes); + expect(component.dir.document).not.toBeNull(); + expect(component.dir.document).not.toBeUndefined(); + expect(component.dir.document).toEqual(jasmine.any(Document)); + })); + +}); +describe('IgxDirectionality', () => { + let fakeDoc: FakeDoc; + beforeEach(() => { + fakeDoc = {body: {}, documentElement: {}}; }); + let expectedRes: string; + let dirInstance: IgxDirectionality; + it('should read dir from html if not specified on the body', () => { + expectedRes = 'rtl'; + fakeDoc.documentElement.dir = expectedRes; + + dirInstance = new IgxDirectionality(fakeDoc); + expect(dirInstance.value).toEqual(expectedRes); + }); it('should read dir from body even it is also specified on the html element', () => { fakeDoc.documentElement.dir = 'ltr'; - const expectedRes = 'rtl'; + expectedRes = 'rtl'; fakeDoc.body.dir = expectedRes; - const fixture = TestBed.createComponent(InjectsIgxDirectionalityComponent); - const component = fixture.debugElement.componentInstance; - - expect(component.dir.value).toEqual(expectedRes); + dirInstance = new IgxDirectionality(fakeDoc); + expect(dirInstance.value).toEqual(expectedRes); }); it('should default to ltr if nothing specified', () => { - const expectedRes = 'ltr'; + expectedRes = 'ltr'; - const fixture = TestBed.createComponent(InjectsIgxDirectionalityComponent); - const component = fixture.debugElement.componentInstance; - - expect(component.dir.value).toEqual(expectedRes); + dirInstance = new IgxDirectionality(fakeDoc); + expect(dirInstance.value).toEqual(expectedRes); }); it('should default to ltr if invalid values are set both on body or html elements', () => { fakeDoc.documentElement.dir = 'none'; fakeDoc.body.dir = 'irrelevant'; - const fixture = TestBed.createComponent(InjectsIgxDirectionalityComponent); - const component = fixture.debugElement.componentInstance; - - expect(component.dir.value).toEqual('ltr'); + dirInstance = new IgxDirectionality(fakeDoc) + expect(dirInstance.value).toEqual('ltr'); }); }); diff --git a/projects/igniteui-angular/src/lib/services/direction/directionality.ts b/projects/igniteui-angular/src/lib/services/direction/directionality.ts index 8153314df4c..14741586a77 100644 --- a/projects/igniteui-angular/src/lib/services/direction/directionality.ts +++ b/projects/igniteui-angular/src/lib/services/direction/directionality.ts @@ -30,7 +30,6 @@ export function DIR_DOCUMENT_FACTORY(): Document { /** * @hidden - * @dynamic * * Bidirectional service that extracts the value of the direction attribute on the body or html elements. * @@ -47,6 +46,10 @@ export class IgxDirectionality { return this._dir; } + public get document() { + return this._document; + } + constructor(@Inject(DIR_DOCUMENT) document) { this._document = document; const bodyDir = this._document.body ? this._document.body.dir : null;