92 lines
3.0 KiB
JavaScript
92 lines
3.0 KiB
JavaScript
import './index.js';
|
|
|
|
describe('Entry', () => {
|
|
describe('Component vnEntryLatestBuys', () => {
|
|
let controller;
|
|
let $httpBackend;
|
|
|
|
beforeEach(ngModule('entry'));
|
|
|
|
beforeEach(angular.mock.inject(($componentController, $compile, $rootScope, _$httpBackend_) => {
|
|
$httpBackend = _$httpBackend_;
|
|
let $element = $compile('<vn-entry-latest-buys></vn-entry-latest-buys')($rootScope);
|
|
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 = [
|
|
{checked: true, id: 1},
|
|
{checked: true, id: 2},
|
|
{checked: true, id: 3},
|
|
{checked: false, id: 4},
|
|
];
|
|
|
|
let result = controller.checked;
|
|
|
|
expect(result.length).toEqual(3);
|
|
});
|
|
});
|
|
|
|
describe('uncheck()', () => {
|
|
it(`should clear the selection of lines on the controller`, () => {
|
|
controller.$.model.data = [
|
|
{checked: true, id: 1},
|
|
{checked: true, id: 2},
|
|
{checked: true, id: 3},
|
|
{checked: false, id: 4},
|
|
];
|
|
|
|
let result = controller.checked;
|
|
|
|
expect(result.length).toEqual(3);
|
|
|
|
controller.uncheck();
|
|
|
|
result = controller.checked;
|
|
|
|
expect(result.length).toEqual(0);
|
|
});
|
|
});
|
|
|
|
describe('onEditAccept()', () => {
|
|
it(`should perform a query to update columns and then `, () => {
|
|
controller.editedColumn = {someColumnName: 'some Value'};
|
|
let query = 'Buys/editLatestBuys';
|
|
controller.$.model.data = [
|
|
{checked: true, id: 1},
|
|
{checked: true, id: 2},
|
|
{checked: true, id: 3},
|
|
{checked: false, id: 4},
|
|
];
|
|
|
|
expect(controller.editedColumn).toBeDefined();
|
|
|
|
$httpBackend.expectPOST(query).respond();
|
|
controller.onEditAccept();
|
|
$httpBackend.flush();
|
|
|
|
const result = controller.checked;
|
|
|
|
expect(result.length).toEqual(0);
|
|
expect(controller.editedColumn).toBeNull();
|
|
});
|
|
});
|
|
});
|
|
});
|