65 lines
2.5 KiB
JavaScript
65 lines
2.5 KiB
JavaScript
import './index.js';
|
|
import crudModel from 'core/mocks/crud-model';
|
|
|
|
describe('Order', () => {
|
|
describe('Component vnOrderCatalog', () => {
|
|
let $scope;
|
|
let controller;
|
|
|
|
beforeEach(ngModule('order'));
|
|
|
|
beforeEach(angular.mock.inject(($componentController, $rootScope) => {
|
|
$scope = $rootScope.$new();
|
|
$scope.model = crudModel;
|
|
$scope.field = {};
|
|
controller = $componentController('vnOrderCatalog', {$scope: $scope});
|
|
}));
|
|
|
|
describe('onDataChange()', () => {
|
|
it(`should return an object with order params`, () => {
|
|
$scope.model.data = [{id: 1, name: 'My Item', tags: [
|
|
{tagFk: 4, name: 'Length'},
|
|
{tagFk: 5, name: 'Color'}
|
|
]}];
|
|
let expectedResult = [{field: 'showOrder, price', name: 'Color'}];
|
|
let unexpectedResult = [{tagFk: 5, name: 'Color'}];
|
|
controller.onDataChange();
|
|
|
|
expect(controller.orderFields.length).toEqual(5);
|
|
expect(controller.orderFields).toEqual(jasmine.arrayContaining(expectedResult));
|
|
expect(controller.orderFields).not.toEqual(jasmine.arrayContaining(unexpectedResult));
|
|
});
|
|
});
|
|
|
|
describe('getOrderBy()', () => {
|
|
it(`should return an object with order params`, () => {
|
|
controller.orderField = 'relevancy DESC, name';
|
|
controller.orderWay = 'DESC';
|
|
let expectedResult = {
|
|
field: 'relevancy DESC, name',
|
|
way: 'DESC',
|
|
isTag: false
|
|
};
|
|
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);
|
|
});
|
|
});
|
|
});
|
|
});
|
|
|