search-panel spec plus small refactor on it's js and html template.

This commit is contained in:
Carlos 2017-09-04 09:47:25 +02:00
parent a732d796e8
commit fa64931cc2
3 changed files with 62 additions and 23 deletions

View File

@ -1,25 +1,25 @@
<div pad-large style="min-width: 30em">
<form ng-submit="$ctrl.onSearch()">
<vn-horizontal>
<vn-textfield vn-one label="Client id" model="$ctrl.filter.id" vn-focus></vn-textfield>
<vn-textfield vn-one label="Tax number" model="$ctrl.filter.fi"></vn-textfield>
</vn-horizontal>
<vn-horizontal>
<vn-textfield vn-one label="Name" model="$ctrl.filter.name"></vn-textfield>
</vn-horizontal>
<vn-horizontal>
<vn-textfield vn-one label="Social name" model="$ctrl.filter.socialName"></vn-textfield>
</vn-horizontal>
<vn-horizontal>
<vn-textfield vn-one label="City" model="$ctrl.filter.city"></vn-textfield>
<vn-textfield vn-one label="Postcode" model="$ctrl.filter.postcode"></vn-textfield>
</vn-horizontal>
<vn-horizontal>
<vn-textfield vn-one label="Email" model="$ctrl.filter.email"></vn-textfield>
<vn-textfield vn-one label="Phone" model="$ctrl.filter.phone"></vn-textfield>
</vn-horizontal>
<vn-horizontal margin-large-top>
<vn-submit label="Search"></vn-submit>
</vn-horizontal>
</form>
<form ng-submit="$ctrl.onSearch()">
<vn-horizontal>
<vn-textfield vn-one label="Client id" model="$ctrl.filter.id" vn-focus></vn-textfield>
<vn-textfield vn-one label="Tax number" model="$ctrl.filter.fi"></vn-textfield>
</vn-horizontal>
<vn-horizontal>
<vn-textfield vn-one label="Name" model="$ctrl.filter.name"></vn-textfield>
</vn-horizontal>
<vn-horizontal>
<vn-textfield vn-one label="Social name" model="$ctrl.filter.socialName"></vn-textfield>
</vn-horizontal>
<vn-horizontal>
<vn-textfield vn-one label="City" model="$ctrl.filter.city"></vn-textfield>
<vn-textfield vn-one label="Postcode" model="$ctrl.filter.postcode"></vn-textfield>
</vn-horizontal>
<vn-horizontal>
<vn-textfield vn-one label="Email" model="$ctrl.filter.email"></vn-textfield>
<vn-textfield vn-one label="Phone" model="$ctrl.filter.phone"></vn-textfield>
</vn-horizontal>
<vn-horizontal margin-large-top>
<vn-submit label="Search"></vn-submit>
</vn-horizontal>
</form>
</div>

View File

@ -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();

View File

@ -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'}));
});
});
});