test fixed

This commit is contained in:
Daniel Herrero 2017-11-07 11:43:18 +01:00
parent 5a1aca198b
commit ec0eb7f1d1
2 changed files with 24 additions and 6 deletions

View File

@ -1,8 +1,7 @@
import {module} from '../module';
export default class ColumnHeader {
constructor($attrs) {
this.$attrs = $attrs;
constructor() {
this.order = undefined;
this.mouseIsOver = false;
}
@ -23,20 +22,21 @@ export default class ColumnHeader {
return showArrow;
}
$onInit() {
if (this.$attrs.defaultOrder) {
this.order = this.$attrs.defaultOrder;
if (this.defaultOrder) {
this.order = this.defaultOrder;
this.onClick();
}
}
}
ColumnHeader.$inject = ['$attrs'];
ColumnHeader.$inject = [];
module.component('vnColumnHeader', {
template: require('./column-header.html'),
bindings: {
field: '@?',
text: '@?',
className: '@?'
className: '@?',
defaultOrder: '@?'
},
require: {
gridHeader: '^^vnGridHeader'

View File

@ -67,4 +67,22 @@ describe('Component vnColumnHeader', () => {
expect(result).toEqual(false);
});
});
describe('onInit()', () => {
it(`should never call onClick()`, () => {
spyOn(controller, 'onClick');
controller.$onInit();
expect(controller.onClick).not.toHaveBeenCalledWith();
});
it(`should define controllers order as per defaultOrder then call onClick()`, () => {
controller.defaultOrder = 'ASC';
spyOn(controller, 'onClick');
controller.$onInit();
expect(controller.order).toEqual('ASC');
expect(controller.onClick).toHaveBeenCalledWith();
});
});
});