Update unit test coverage
This commit is contained in:
parent
53fa3aa785
commit
1461b25987
@ -25,12 +25,7 @@ export class ContextMenu {
|
||||
|
||||
let parentElement = el.nativeElement.parentElement;
|
||||
|
||||
parentElement.oncontextmenu = (event: MouseEvent) => {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
|
||||
this.onParentContextMenu(event);
|
||||
};
|
||||
parentElement.oncontextmenu = this.eventHandler;
|
||||
}
|
||||
|
||||
getText(item: ContextMenuItem): SafeHtml {
|
||||
@ -43,6 +38,13 @@ export class ContextMenu {
|
||||
}
|
||||
}
|
||||
|
||||
private eventHandler(event: MouseEvent) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
|
||||
this.onParentContextMenu(event);
|
||||
}
|
||||
|
||||
private onParentContextMenu(event: MouseEvent) {
|
||||
this.menuService.closeAllMenus();
|
||||
this.isOpen = true;
|
||||
|
@ -86,6 +86,23 @@ global.window.Reflect = Reflect;
|
||||
global.RxJs = require('rxjs/Rx');
|
||||
global.expect = chai.expect;
|
||||
|
||||
global.ElementRefMock = {
|
||||
nativeElement: {
|
||||
parentElement: {
|
||||
oncontextmenu: () => {}
|
||||
},
|
||||
firstElementChild: {
|
||||
style: {},
|
||||
getBoundingClientRect: () => {
|
||||
return {
|
||||
width: 10,
|
||||
height: 10
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
global.Chartist = {
|
||||
Pie(id, data, opts) {
|
||||
this.sum = function() { return 100; };
|
||||
@ -197,6 +214,23 @@ global.ModalServiceMock = function() {
|
||||
};
|
||||
};
|
||||
|
||||
global.ContextMenuServiceMock = function() {
|
||||
var register = new RxJs.Subject(),
|
||||
closeAll = new RxJs.Subject();
|
||||
|
||||
return {
|
||||
registerCalled: register.asObservable(),
|
||||
closeAllCalled: closeAll.asObservable(),
|
||||
|
||||
registerMenu: () => {
|
||||
register.next(true);
|
||||
},
|
||||
closeAllMenus: () => {
|
||||
closeAll.next(true);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
global.StringsServiceMock = {
|
||||
stringsChanged: {
|
||||
subscribe(callback) {
|
||||
|
@ -6,7 +6,7 @@ var dirs = '../../../../',
|
||||
|
||||
describe('AutoActions', () => {
|
||||
var autoActions,
|
||||
modalService;
|
||||
imodalService;
|
||||
|
||||
beforeEach(() => {
|
||||
modalService = new ModalServiceMock();
|
||||
|
39
test/app/shared/context-menu/context-menu.component.spec.js
Normal file
39
test/app/shared/context-menu/context-menu.component.spec.js
Normal file
@ -0,0 +1,39 @@
|
||||
/* global expect ElementRefMock ContextMenuServiceMock SanitizerMock */
|
||||
var path = '../../../../build/shared/context-menu/',
|
||||
ContextMenu = require(path + 'context-menu.component.js').ContextMenu;
|
||||
|
||||
describe('ContextMenu', () => {
|
||||
var contextMenu,
|
||||
contextMenuService;
|
||||
|
||||
beforeEach(() => {
|
||||
contextMenuService = new ContextMenuServiceMock();
|
||||
contextMenu = new ContextMenu(ElementRefMock, contextMenuService, SanitizerMock);
|
||||
});
|
||||
|
||||
it('has a function to get menu item text', () => {
|
||||
expect(contextMenu.getText({ text: 'testing' })).to.equal('testing');
|
||||
});
|
||||
|
||||
it('has a function to call a callback', (done) => {
|
||||
var callback = () => {
|
||||
done();
|
||||
};
|
||||
|
||||
contextMenu.callAction(callback);
|
||||
});
|
||||
|
||||
it('captures the parent oncontextmenu event', (done) => {
|
||||
contextMenuService.closeAllCalled.subscribe( called => {
|
||||
expect(called).to.equal(true);
|
||||
done();
|
||||
});
|
||||
|
||||
contextMenu.eventHandler({
|
||||
pageX: 10, pageY: 10,
|
||||
preventDefault: () => {},
|
||||
stopPropagation: () => {}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
30
test/app/shared/context-menu/context-menu.service.spec.js
Normal file
30
test/app/shared/context-menu/context-menu.service.spec.js
Normal file
@ -0,0 +1,30 @@
|
||||
/* global expect */
|
||||
var path = '../../../../build/shared/context-menu/',
|
||||
ContextMenuItem = require(path + 'context-menu-item.model.js').ContextMenuItem,
|
||||
ContextMenuService = require(path + 'context-menu.service.js').ContextMenuService;
|
||||
|
||||
describe('ContextMenu', () => {
|
||||
var contextMenuService;
|
||||
|
||||
beforeEach(() => {
|
||||
contextMenuService = new ContextMenuService();
|
||||
});
|
||||
|
||||
it('has a menus array', () => {
|
||||
expect(contextMenuService.menus).to.be.an('array');
|
||||
});
|
||||
|
||||
it('has a registerMenu function', () => {
|
||||
contextMenuService.registerMenu(new ContextMenuItem());
|
||||
|
||||
expect(contextMenuService.menus.length).to.equal(1);
|
||||
});
|
||||
|
||||
it('has a closeAllMenus function', () => {
|
||||
contextMenuService.registerMenu({ isOpen: true });
|
||||
contextMenuService.closeAllMenus({});
|
||||
|
||||
expect(contextMenuService.menus[0].isOpen).to.equal(false);
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user