import './index.js'; import template from './index.html'; describe('Component vnTh', () => { let $componentController; let controller; let $element; beforeEach(() => { angular.mock.module('client'); }); beforeEach(angular.mock.inject(_$componentController_ => { $componentController = _$componentController_; $element = angular.element(`
${template}
`); 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'); }); }); });