2018-06-28 12:43:59 +00:00
|
|
|
import './index.js';
|
|
|
|
import template from './index.html';
|
|
|
|
|
2018-06-28 13:47:14 +00:00
|
|
|
describe('Component vnTh', () => {
|
2018-06-28 12:43:59 +00:00
|
|
|
let $componentController;
|
|
|
|
let controller;
|
|
|
|
let $element;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
angular.mock.module('client');
|
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(angular.mock.inject(_$componentController_ => {
|
|
|
|
$componentController = _$componentController_;
|
|
|
|
$element = angular.element(`<div>${template}</div>`);
|
|
|
|
controller = $componentController('vnTh', {$element: $element});
|
|
|
|
controller.table = {setOrder: () => {}};
|
|
|
|
controller.column = {
|
|
|
|
getAttribute: () => 'MyField',
|
|
|
|
classList: {
|
|
|
|
add: () => {},
|
|
|
|
remove: () => {}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}));
|
|
|
|
|
|
|
|
describe('toggleOrder()', () => {
|
|
|
|
it(`should change the ordenation to DESC (descendant) if it was ASC (ascendant)`, () => {
|
|
|
|
controller.order = 'ASC';
|
|
|
|
controller.toggleOrder();
|
|
|
|
|
|
|
|
expect(controller.order).toEqual('DESC');
|
|
|
|
});
|
|
|
|
|
|
|
|
it(`should change the ordenation to ASC (ascendant) if it wasnt ASC`, () => {
|
|
|
|
controller.order = 'DESC or any other value that might occur';
|
|
|
|
controller.toggleOrder();
|
|
|
|
|
|
|
|
expect(controller.order).toEqual('ASC');
|
|
|
|
});
|
|
|
|
|
|
|
|
it(`should call the setOrder() function after changing a value`, () => {
|
|
|
|
spyOn(controller.table, 'setOrder');
|
|
|
|
controller.order = 'Change me!';
|
|
|
|
|
|
|
|
expect(controller.table.setOrder).toHaveBeenCalledWith('MyField', 'Change me!');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('onInit()', () => {
|
|
|
|
it(`should define controllers order as per defaultOrder then call setOrder()`, () => {
|
|
|
|
controller.defaultOrder = 'DESC';
|
|
|
|
spyOn(controller.table, 'setOrder');
|
|
|
|
controller.$onInit();
|
|
|
|
|
|
|
|
expect(controller.order).toEqual('DESC');
|
|
|
|
expect(controller.table.setOrder).toHaveBeenCalledWith('MyField', 'DESC');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|