Merge branch 'dev' of https://git.verdnatura.es/salix into dev

This commit is contained in:
gerard 2018-09-14 14:45:39 +02:00
commit ce8cd5708e
3 changed files with 178 additions and 0 deletions

View File

@ -1,5 +1,8 @@
module.exports.crudModel = {
data: [],
filter: {},
order: {},
insert: () => {
return new Promise(accept => {
accept();

View File

@ -0,0 +1,32 @@
import './index.js';
import {crudModel} from '../../../helpers/crudModelHelper';
describe('Order', () => {
describe('Component vnOrderCatalog', () => {
let $componentController;
let $scope;
let controller;
beforeEach(() => {
angular.mock.module('order');
});
beforeEach(angular.mock.inject((_$componentController_, $rootScope) => {
$componentController = _$componentController_;
$scope = $rootScope.$new();
$scope.model = crudModel;
controller = $componentController('vnOrderCatalog', {$scope: $scope});
}));
describe('setOrder()', () => {
it(`should apply filter order and call model refresh() method`, () => {
spyOn(controller.$scope.model, 'refresh');
controller.setOrder('relevancy DESC');
expect(controller.$scope.model.filter.order).toEqual('relevancy DESC');
expect(controller.$scope.model.refresh).toHaveBeenCalledWith();
});
});
});
});

View File

@ -0,0 +1,143 @@
import './index.js';
import {crudModel} from '../../../helpers/crudModelHelper';
describe('Order', () => {
describe('Component vnCatalogFilter', () => {
let $componentController;
let $httpBackend;
let $scope;
let $state;
let controller;
beforeEach(() => {
angular.mock.module('order');
});
beforeEach(angular.mock.inject((_$httpBackend_, _$componentController_, _$state_, $rootScope) => {
$componentController = _$componentController_;
$httpBackend = _$httpBackend_;
$httpBackend.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({});
$scope = $rootScope.$new();
$scope.model = crudModel;
$scope.search = {};
$state = _$state_;
$state.params.category = '{"id": 1, "value": "My Category"}';
$state.params.type = '{"id": 1, "value": "My type"}';
$state.current.name = 'my.current.state';
controller = $componentController('vnCatalogFilter', {$scope: $scope, $state});
controller.catalog = {
$scope: $scope
};
}));
describe('order() setter', () => {
it(`should call scope $$postDigest() method and apply filters from state params`, () => {
spyOn(controller.$scope, '$$postDigest').and.callThrough();
controller.order = {id: 4};
expect(controller.$scope.$$postDigest).toHaveBeenCalledWith(jasmine.any(Function));
$scope.$digest();
expect(controller.category).toEqual({id: 1, value: 'My Category'});
expect(controller.type).toEqual({id: 1, value: 'My type'});
});
});
describe('category() setter', () => {
it(`should set category property to null, call updateStateParams() method and not call applyFilters()`, () => {
spyOn(controller, 'updateStateParams');
controller.category = null;
expect(controller.updateStateParams).toHaveBeenCalledWith();
});
it(`should set category property and then call updateStateParams() and applyFilters() methods`, () => {
spyOn(controller, 'updateStateParams');
controller.category = {id: 2, value: 'My category'};
expect(controller.updateStateParams).toHaveBeenCalledWith();
});
});
describe('type() setter', () => {
it(`should set type property to null, call updateStateParams() method and not call applyFilters()`, () => {
spyOn(controller, 'updateStateParams');
spyOn(controller, 'applyFilters');
controller.type = null;
expect(controller.updateStateParams).toHaveBeenCalledWith();
expect(controller.applyFilters).not.toHaveBeenCalledWith();
});
it(`should set category property and then call updateStateParams() and applyFilters() methods`, () => {
spyOn(controller, 'updateStateParams');
spyOn(controller, 'applyFilters');
controller.type = {id: 2, value: 'My type'};
expect(controller.updateStateParams).toHaveBeenCalledWith();
expect(controller.applyFilters).toHaveBeenCalledWith();
});
});
describe('onSearch()', () => {
it(`should not add a new tag if the event key code doesn't equals to 'Enter'`, () => {
spyOn(controller, 'applyFilters');
controller.order = {id: 4};
controller.value = 'Color';
controller.onSearch({key: 'Tab'});
expect(controller.applyFilters).not.toHaveBeenCalledWith();
});
it(`should add a new tag if the event key code equals to 'Enter' an then call applyFilters()`, () => {
spyOn(controller, 'applyFilters');
controller.order = {id: 4};
controller.value = 'Color';
controller.onSearch({key: 'Enter'});
expect(controller.applyFilters).toHaveBeenCalledWith();
});
});
describe('applyFilters()', () => {
it(`should set type property to null, call updateStateParams() method and not call applyFilters()`, () => {
spyOn(controller.catalog.$scope.model, 'refresh');
controller.order = {id: 4};
$scope.$digest();
controller.applyFilters();
let result = {args: {orderFk: 4, categoryFk: 1, typeFk: 1}, tags: []};
expect(controller.catalog.$scope.model.params).toEqual(result);
expect(controller.catalog.$scope.model.refresh).toHaveBeenCalledWith();
});
});
describe('remove()', () => {
it(`should remove a filter from tags property and then call applyFilters()`, () => {
spyOn(controller, 'applyFilters');
controller.order = {id: 4};
controller.tags = [{tagFk: 1, value: 'Blue'}, {tagFk: 2, value: '70'}];
$scope.$digest();
controller.remove(0);
expect(controller.tags.length).toEqual(1);
expect(controller.tags[0].tagFk).toEqual(2);
expect(controller.applyFilters).toHaveBeenCalledWith();
});
});
describe('updateStateParams()', () => {
it(`should call state go() method passing category and type state params`, () => {
spyOn(controller.$state, 'go');
controller.order = {id: 4};
$scope.$digest();
let result = {category: '{"id":1,"value":"My Category"}', type: '{"id":1,"value":"My type"}'};
expect(controller.$state.go).toHaveBeenCalledWith('my.current.state', result);
});
});
});
});