From 2e58481f1556702215fd999adecd228b93f1026a Mon Sep 17 00:00:00 2001 From: Will Abson Date: Fri, 23 Sep 2016 18:19:34 +0100 Subject: [PATCH] Add additional tests for search control component Refs #737 --- .../alfresco-search-control.component.spec.ts | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) 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 32d420b882..258e7e4202 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 @@ -152,5 +152,51 @@ describe('AlfrescoSearchControlComponent', () => { }); + describe('component focus', () => { + + it('should fire an event when the search box receives focus', () => { + spyOn(component.expand, 'emit'); + let inputEl = element.querySelector('input'); + inputEl.dispatchEvent(new Event('focus')); + expect(component.expand.emit).toHaveBeenCalledWith({ + expanded: true + }); + }); + + it('should fire an event when the search box loses focus', () => { + spyOn(component.expand, 'emit'); + let inputEl = element.querySelector('input'); + inputEl.dispatchEvent(new Event('blur')); + expect(component.expand.emit).toHaveBeenCalledWith({ + expanded: false + }); + }); + + it('should NOT fire an event when the search box receives/loses focus but the component is not expandable', + () => { + spyOn(component.expand, 'emit'); + component.expandable = false; + let inputEl = element.querySelector('input'); + inputEl.dispatchEvent(new Event('focus')); + inputEl.dispatchEvent(new Event('blur')); + expect(component.expand.emit).not.toHaveBeenCalled(); + }); + + }); + + describe('file preview', () => { + + it('should emit a preview event when onFileClicked is called', () => { + spyOn(component.preview, 'emit'); + component.onFileClicked({ + value: 'node12345' + }); + expect(component.preview.emit).toHaveBeenCalledWith({ + 'value': 'node12345' + }); + }); + + }); + }); */