From 7cf57d05f1a3d3863b996e12d0bbf3d594ba6a05 Mon Sep 17 00:00:00 2001 From: Carlos Date: Fri, 13 Oct 2017 10:45:06 +0200 Subject: [PATCH] Client side unit test for grid-header --- .../core/src/grid-header/grid-header.spec.js | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 client/core/src/grid-header/grid-header.spec.js diff --git a/client/core/src/grid-header/grid-header.spec.js b/client/core/src/grid-header/grid-header.spec.js new file mode 100644 index 000000000..4b9e20da0 --- /dev/null +++ b/client/core/src/grid-header/grid-header.spec.js @@ -0,0 +1,44 @@ +import './grid-header.js'; + +describe('Component vnGridHeader', () => { + let $componentController; + + beforeEach(() => { + angular.mock.module('client'); + }); + + beforeEach(angular.mock.inject(_$componentController_ => { + $componentController = _$componentController_; + })); + + describe('selectColum()', () => { + it(`should set controller currentColumn to equal the argument received`, () => { + let controller = $componentController('vnGridHeader', {}); + let col = {columnStuff: 'some stuff'}; + controller.selectColum(col); + + expect(controller.currentColumn).toEqual(col); + }); + + it(`should set controller currentColumn.order to undefined then set currentColumn to equal the argument received`, () => { + let controller = $componentController('vnGridHeader', {}); + controller.currentColumn = {field: 'some field', order: 'ordered'}; + let col = {columnStuff: 'some stuff'}; + controller.selectColum(col); + + expect(controller.currentColumn.order).not.toBeDefined(); + expect(controller.currentColumn).toEqual(col); + }); + + it(`should set controller currentColumn.order to undefined then call onOrder passing currentColumn as argument`, () => { + let controller = $componentController('vnGridHeader', {}); + controller.onOrder = () => {}; + spyOn(controller, 'onOrder'); + let col = {columnStuff: 'some stuff'}; + controller.selectColum(col); + + expect(controller.currentColumn).toEqual(col); + expect(controller.onOrder).toHaveBeenCalledWith(col); + }); + }); +});