import { MenuComponent } from "../src/components/fec-menu/menu.component"; import { MenuItem } from "../src/components/fec-menu/menu-item"; import { MenuService } from "../src/components/fec-menu/menu.service"; import { Observable } from "rxjs/Rx"; let mockVHttpService = { getMenuItems(url: string) : Observable { return Observable.of([ {label: 'placeholder', menuId: 'placeholderId', expanded: false}]); } }; describe('MenuComponent', () => { var menu: MenuComponent = new MenuComponent(null, null); describe('ngOnInit', () => { it('calls getMenuItems when url is defined and menuItems is not defined', () => { menu.url = "example.com"; menu.menuItems = undefined; spyOn(menu, 'getMenuItems'); menu.ngOnInit(); expect(menu.getMenuItems).toHaveBeenCalled(); }); }); describe('backgroundClick', () => { it('for autoClose dropdown menu, after click outside of menu area, the dropdown menu must be unexpanded', () => { menu.autoClose = true; menu.menuItems = [ {expanded: true}]; menu.containsElement = function(){return false;}; menu.backgroundClick({target: ''}); expect(menu.menuItems[0].expanded).toBe(false); }); it('for autoClose dropdown menu, after click inside of menu area, the dropdown menu must be still expanded', ()=> { menu.autoClose = true; menu.menuItems = [ {expanded: true}]; menu.containsElement = function(){return true;}; menu.backgroundClick({target: ''}); expect(menu.menuItems[0].expanded).toBe(true); }); it('for not autoClose dropdown menu, after click outside of menu area, the dropdown menu must be still expanded', ()=> { menu.autoClose = false; menu.menuItems = [ {expanded: true}]; menu.containsElement = function(){return false;}; menu.backgroundClick({target: ''}); expect(menu.menuItems[0].expanded).toBe(true); }); }); });