2018-09-14 12:18:39 +00:00
|
|
|
import './index.js';
|
2018-12-27 11:54:16 +00:00
|
|
|
import crudModel from 'core/mocks/crud-model';
|
2018-09-14 12:18:39 +00:00
|
|
|
|
|
|
|
describe('Order', () => {
|
|
|
|
describe('Component vnOrderCatalog', () => {
|
|
|
|
let $scope;
|
|
|
|
let controller;
|
|
|
|
|
2019-09-13 14:09:14 +00:00
|
|
|
beforeEach(angular.mock.module('order', $translateProvider => {
|
|
|
|
$translateProvider.translations('en', {});
|
|
|
|
}));
|
2018-09-14 12:18:39 +00:00
|
|
|
|
2018-12-22 10:59:26 +00:00
|
|
|
beforeEach(angular.mock.inject(($componentController, $rootScope) => {
|
2018-09-14 12:18:39 +00:00
|
|
|
$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`, () => {
|
|
|
|
$scope.model.data = [{id: 1, name: 'My Item', tags: [
|
2019-02-19 14:13:27 +00:00
|
|
|
{tagFk: 4, name: 'Length'},
|
|
|
|
{tagFk: 5, name: 'Color'}
|
2018-10-31 13:56:54 +00:00
|
|
|
]}];
|
2019-02-19 14:13:27 +00:00
|
|
|
let expectedResult = [{field: 'showOrder, price', name: 'Color'}];
|
|
|
|
let unexpectedResult = [{tagFk: 5, name: 'Color'}];
|
2018-10-31 13:56:54 +00:00
|
|
|
controller.onDataChange();
|
|
|
|
|
2019-02-19 14:13:27 +00:00
|
|
|
expect(controller.fieldList.length).toEqual(5);
|
|
|
|
expect(controller.fieldList).toEqual(jasmine.arrayContaining(expectedResult));
|
|
|
|
expect(controller.fieldList).not.toEqual(jasmine.arrayContaining(unexpectedResult));
|
2018-10-31 13:56:54 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
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
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|