salix/modules/entry/front/latest-buys/index.spec.js

101 lines
3.3 KiB
JavaScript
Raw Normal View History

2020-08-27 13:14:30 +00:00
import './index.js';
describe('Entry', () => {
describe('Component vnEntryLatestBuys', () => {
let controller;
let $httpBackend;
beforeEach(ngModule('entry'));
2021-11-11 16:18:19 +00:00
beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_) => {
2020-08-27 13:14:30 +00:00
$httpBackend = _$httpBackend_;
2021-11-11 16:18:19 +00:00
const $element = angular.element('<vn-entry-latest-buys></vn-entry-latest-buys');
2020-08-27 13:14:30 +00:00
controller = $componentController('vnEntryLatestBuys', {$element});
controller.$ = {
model: {refresh: () => {}},
edit: {hide: () => {}}
};
}));
describe('get columns', () => {
it(`should return a set of columns`, () => {
let result = controller.columns;
let length = result.length;
let anyColumn = Object.keys(result[Math.floor(Math.random() * Math.floor(length))]);
expect(anyColumn).toContain('field', 'displayName');
});
});
describe('get checked', () => {
it(`should return a set of checked lines`, () => {
controller.$.model.data = [
2022-04-20 06:55:43 +00:00
{checked: true, id: 1},
{checked: true, id: 2},
{checked: true, id: 3},
{checked: false, id: 4},
2020-08-27 13:14:30 +00:00
];
let result = controller.checked;
expect(result.length).toEqual(3);
});
});
describe('onEditAccept()', () => {
2020-09-02 11:09:30 +00:00
it(`should perform a query to update columns`, () => {
controller.editedColumn = {field: 'my field', newValue: 'the new value'};
2021-11-11 16:18:19 +00:00
const query = 'Buys/editLatestBuys';
2020-08-27 13:14:30 +00:00
$httpBackend.expectPOST(query).respond();
controller.onEditAccept();
$httpBackend.flush();
const result = controller.checked;
expect(result.length).toEqual(0);
});
});
describe('reCheck()', () => {
it(`should recheck buys`, () => {
controller.$.model.data = [
{checked: false, id: 1},
{checked: false, id: 2},
{checked: false, id: 3},
{checked: false, id: 4},
];
controller.checkedBuys = [1, 2];
controller.reCheck();
expect(controller.$.model.data[0].checked).toEqual(true);
expect(controller.$.model.data[1].checked).toEqual(true);
expect(controller.$.model.data[2].checked).toEqual(false);
expect(controller.$.model.data[3].checked).toEqual(false);
});
});
describe('saveChecked()', () => {
it(`should check buy`, () => {
const buyCheck = 3;
controller.checkedBuys = [1, 2];
controller.saveChecked(buyCheck);
expect(controller.checkedBuys[2]).toEqual(buyCheck);
});
it(`should uncheck buy`, () => {
const buyUncheck = 3;
controller.checkedBuys = [1, 2, 3];
controller.saveChecked(buyUncheck);
expect(controller.checkedBuys[2]).toEqual(undefined);
});
});
2020-08-27 13:14:30 +00:00
});
});