From 28909da94e72553b119deb86cad8c7dbde8cfb24 Mon Sep 17 00:00:00 2001 From: Carlos Date: Thu, 5 Oct 2017 09:58:15 +0200 Subject: [PATCH] client side unit test for column-header --- .../src/column-header/column-header.spec.js | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 client/core/src/column-header/column-header.spec.js diff --git a/client/core/src/column-header/column-header.spec.js b/client/core/src/column-header/column-header.spec.js new file mode 100644 index 000000000..247b75993 --- /dev/null +++ b/client/core/src/column-header/column-header.spec.js @@ -0,0 +1,68 @@ +import './column-header.js'; + +describe('Component vnColumnHeader', () => { + let $componentController; + + beforeEach(() => { + angular.mock.module('client'); + }); + + beforeEach(angular.mock.inject(_$componentController_ => { + $componentController = _$componentController_; + })); + + describe('onClick()', () => { + it(`should change the ordenation to DESC (descendant) if it was ASC (ascendant)`, () => { + let controller = $componentController('vnColumnHeader', {}, {gridHeader: {selectColum: () => {}}}); + controller.order = 'ASC'; + controller.onClick(); + + expect(controller.order).toEqual('DESC'); + }); + + it(`should change the ordenation to ASC (ascendant) if it wasnt ASC`, () => { + let controller = $componentController('vnColumnHeader', {}, {gridHeader: {selectColum: () => {}}}); + controller.order = 'DESC or any other value that might occur'; + controller.onClick(); + + expect(controller.order).toEqual('ASC'); + }); + + it(`should call the selectColum() function after changing a value`, () => { + let controller = $componentController('vnColumnHeader', {}, {gridHeader: {selectColum: () => {}}}); + controller.order = 'Change me!'; + spyOn(controller.gridHeader, 'selectColum'); + controller.onClick(); + + expect(controller.gridHeader.selectColum).toHaveBeenCalledWith(controller); + }); + }); + + describe('showArrow()', () => { + it(`should return true when the type is DESC and MouseIsOver`, () => { + let controller = $componentController('vnColumnHeader', {}, {gridHeader: {selectColum: () => {}}}); + controller.mouseIsOver = true; + let result = controller.showArrow('DESC'); + + expect(result).toEqual(true); + }); + + it(`should return true if many conditions are true`, () => { + let controller = $componentController('vnColumnHeader', {}, {gridHeader: {currentColumn: {field: 'fields should be identical'}}}); + controller.field = 'fields should be identical'; + controller.order = 'ASC'; + let result = controller.showArrow('ASC'); + + expect(result).toEqual(true); + }); + + it(`should return false without type being DESC or any other values being true`, () => { + let controller = $componentController('vnColumnHeader', {}, {gridHeader: {currentColumn: {field: 'this field isnt the same as controllers field'}}}); + controller.field = 'I am the controllers field'; + controller.order = 'ASC'; + let result = controller.showArrow('ASC'); + + expect(result).toEqual(false); + }); + }); +});