2018-09-14 12:18:39 +00:00
|
|
|
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;
|
2018-10-31 13:56:54 +00:00
|
|
|
$scope.field = {};
|
2018-09-14 12:18:39 +00:00
|
|
|
controller = $componentController('vnOrderCatalog', {$scope: $scope});
|
|
|
|
}));
|
|
|
|
|
2018-10-31 13:56:54 +00:00
|
|
|
describe('onDataChange()', () => {
|
|
|
|
it(`should return an object with order params`, () => {
|
|
|
|
let expectedList = [
|
|
|
|
{field: 'relevancy DESC, name', name: 'Name'},
|
|
|
|
{field: 'price', name: 'Price'},
|
|
|
|
{field: 4, name: 'Length', isTag: true}
|
|
|
|
];
|
|
|
|
$scope.model.data = [{id: 1, name: 'My Item', tags: [
|
|
|
|
{tagFk: 4, name: 'Length'}
|
|
|
|
]}];
|
2018-09-14 12:18:39 +00:00
|
|
|
|
2018-10-31 13:56:54 +00:00
|
|
|
controller.onDataChange();
|
|
|
|
|
|
|
|
expect(controller.fieldList).toEqual(expectedList);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('getOrderBy()', () => {
|
|
|
|
it(`should return an object with order params`, () => {
|
|
|
|
controller.field = 'relevancy DESC, name';
|
|
|
|
controller.way = 'DESC';
|
|
|
|
let expectedResult = {field: 'relevancy DESC, name', way: 'DESC'};
|
|
|
|
let result = controller.getOrderBy();
|
|
|
|
|
|
|
|
expect(result).toEqual(expectedResult);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('applyOrder()', () => {
|
|
|
|
it(`should apply order param to model calling getOrderBy()`, () => {
|
|
|
|
controller.field = 'relevancy DESC, name';
|
|
|
|
controller.way = 'ASC';
|
|
|
|
let expectedOrder = {orderBy: controller.getOrderBy()};
|
|
|
|
spyOn(controller, 'getOrderBy').and.callThrough();
|
|
|
|
spyOn(controller.$scope.model, 'addFilter');
|
|
|
|
controller.applyOrder();
|
|
|
|
|
|
|
|
expect(controller.getOrderBy).toHaveBeenCalledWith();
|
|
|
|
expect(controller.$scope.model.addFilter).toHaveBeenCalledWith(null, expectedOrder);
|
2018-09-14 12:18:39 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|