From fa64931cc214c3cda05ea553419f88894c8cb3ca Mon Sep 17 00:00:00 2001 From: Carlos Date: Mon, 4 Sep 2017 09:47:25 +0200 Subject: [PATCH] search-panel spec plus small refactor on it's js and html template. --- .../client/src/search-panel/search-panel.html | 46 +++++++++---------- .../client/src/search-panel/search-panel.js | 2 + .../src/search-panel/search-panel.spec.js | 37 +++++++++++++++ 3 files changed, 62 insertions(+), 23 deletions(-) create mode 100644 client/client/src/search-panel/search-panel.spec.js diff --git a/client/client/src/search-panel/search-panel.html b/client/client/src/search-panel/search-panel.html index 4e299c3ce..4374d31e1 100644 --- a/client/client/src/search-panel/search-panel.html +++ b/client/client/src/search-panel/search-panel.html @@ -1,25 +1,25 @@
-
- - - - - - - - - - - - - - - - - - - - - -
+
+ + + + + + + + + + + + + + + + + + + + + +
diff --git a/client/client/src/search-panel/search-panel.js b/client/client/src/search-panel/search-panel.js index 12b368c79..87f6308ce 100644 --- a/client/client/src/search-panel/search-panel.js +++ b/client/client/src/search-panel/search-panel.js @@ -3,6 +3,8 @@ import ngModule from '../module'; export default class Controller { constructor($window) { this.$window = $window; + // onSubmit() is defined by @vnSearchbar + this.onSubmit = () => {}; } onSearch() { this.setStorageValue(); diff --git a/client/client/src/search-panel/search-panel.spec.js b/client/client/src/search-panel/search-panel.spec.js new file mode 100644 index 000000000..e9f627129 --- /dev/null +++ b/client/client/src/search-panel/search-panel.spec.js @@ -0,0 +1,37 @@ +import './search-panel.js'; + +describe('Component vnClientSearchPanel', () => { + let $componentController; + let $window; + + beforeEach(() => { + angular.mock.module('client'); + }); + + beforeEach(angular.mock.inject(function(_$componentController_, _$window_) { + $componentController = _$componentController_; + $window = _$window_; + })); + + describe('onSearch()', () => { + it(`should call setStorageValue() and onSubmit()`, () => { + let controller = $componentController('vnClientSearchPanel', {$window: $window}); + spyOn(controller, 'setStorageValue'); + spyOn(controller, 'onSubmit'); + controller.setStorageValue(); + controller.onSubmit(); + expect(controller.setStorageValue).toHaveBeenCalled(); + expect(controller.onSubmit).toHaveBeenCalled(); + }); + }); + + describe('$onChanges()', () => { + it(`should set filter properties using the search values`, () => { + let controller = $componentController('vnClientSearchPanel', {$window: $window}); + expect(controller.filter).not.toBeDefined(); + spyOn(JSON, 'parse').and.returnValue({data: 'data'}); + controller.$onChanges(); + expect(controller.filter).toBe(JSON.parse({data: 'data'})); + }); + }); +});