From b2f81393a25fab2d0a766e104e08f761e191e9de Mon Sep 17 00:00:00 2001 From: Denys Vuika Date: Thu, 23 Jun 2016 14:08:57 +0100 Subject: [PATCH] Unit test fixes --- .../alfresco-search-control.component.spec.ts | 59 ++++++++++++------- 1 file changed, 37 insertions(+), 22 deletions(-) diff --git a/ng2-components/ng2-alfresco-search/src/components/alfresco-search-control.component.spec.ts b/ng2-components/ng2-alfresco-search/src/components/alfresco-search-control.component.spec.ts index 95cc4e9c3b..6891a677e7 100644 --- a/ng2-components/ng2-alfresco-search/src/components/alfresco-search-control.component.spec.ts +++ b/ng2-components/ng2-alfresco-search/src/components/alfresco-search-control.component.spec.ts @@ -73,11 +73,15 @@ describe('AlfrescoSearchControlComponent', () => { it('should display a text input field by default', inject([TestComponentBuilder], (tcb: TestComponentBuilder) => { - return tcb.createAsync(AlfrescoSearchControlComponent).then((componentFixture) => { - const element = componentFixture.nativeElement; - expect(element.querySelectorAll('input[type="text"]').length).toBe(1); - }); - })); + return tcb + .createAsync(AlfrescoSearchControlComponent) + .then((componentFixture) => { + const element = componentFixture.nativeElement; + componentFixture.detectChanges(); + expect(element.querySelectorAll('input[type="text"]').length).toBe(1); + }); + }) + ); it('should display a search input field when specified', inject([TestComponentBuilder], (tcb: TestComponentBuilder) => { @@ -91,12 +95,16 @@ describe('AlfrescoSearchControlComponent', () => { it('should set browser autocomplete to off by default', inject([TestComponentBuilder], (tcb: TestComponentBuilder) => { - return tcb.createAsync(AlfrescoSearchControlComponent).then((componentFixture) => { - const element = componentFixture.nativeElement; - expect(element.querySelectorAll('input[type="text"]')[0].getAttribute('autocomplete')) - .toBe('off'); + return tcb + .createAsync(AlfrescoSearchControlComponent) + .then((componentFixture) => { + const element = componentFixture.nativeElement; + componentFixture.detectChanges(); + let attr = element.querySelectorAll('input[type="text"]')[0].getAttribute('autocomplete'); + expect(attr).toBe('off'); }); - })); + }) + ); it('should set browser autocomplete to on when configured', inject([TestComponentBuilder], (tcb: TestComponentBuilder) => { @@ -111,22 +119,29 @@ describe('AlfrescoSearchControlComponent', () => { it('should show an expanding control by default', inject([TestComponentBuilder], (tcb: TestComponentBuilder) => { - return tcb.createAsync(AlfrescoSearchControlComponent).then((componentFixture) => { - const element = componentFixture.nativeElement; - expect(element.querySelectorAll('div.mdl-textfield--expandable').length).toBe(1); - expect(element.querySelectorAll('div.mdl-textfield__expandable-holder').length).toBe(1); + return tcb + .createAsync(AlfrescoSearchControlComponent) + .then((componentFixture) => { + const element = componentFixture.nativeElement; + componentFixture.detectChanges(); + expect(element.querySelectorAll('div.mdl-textfield--expandable').length).toBe(1); + expect(element.querySelectorAll('div.mdl-textfield__expandable-holder').length).toBe(1); }); - })); + }) + ); it('should show a normal non-expanding control when configured', inject([TestComponentBuilder], (tcb: TestComponentBuilder) => { - return tcb.createAsync(AlfrescoSearchControlComponent).then((componentFixture) => { - const element = componentFixture.nativeElement; - componentFixture.componentInstance.expandable = true; - componentFixture.detectChanges(); - expect(element.querySelectorAll('div.mdl-textfield--expandable').length).toBe(0); - expect(element.querySelectorAll('div.mdl-textfield__expandable-holder').length).toBe(0); + return tcb + .createAsync(AlfrescoSearchControlComponent) + .then((componentFixture) => { + const element = componentFixture.nativeElement; + componentFixture.componentInstance.expandable = true; + componentFixture.detectChanges(); + expect(element.querySelectorAll('div.mdl-textfield--expandable').length).toBe(0); + expect(element.querySelectorAll('div.mdl-textfield__expandable-holder').length).toBe(0); }); - })); + }) + ); }); });