front and back unit tests
This commit is contained in:
parent
3a82ef0e06
commit
d156ca95ba
|
@ -738,7 +738,7 @@ INSERT INTO `vn`.`item`(`id`, `typeFk`, `size`, `inkFk`, `stems`, `originFk`, `d
|
|||
(1, 2, 70, 'AMA', 1, 1, NULL, 1, 06021010, 0, 2000000000, 0, NULL, 0, 66540, 1, NULL),
|
||||
(2, 2, 70, 'AZL', 1, 2, NULL, 1, 06021010, 0, 2000000000, 0, NULL, 0, 65540, 1, NULL),
|
||||
(3, 1, 60, 'AMR', 1, 3, NULL, 1, 05080000, 0, 4751000000, 0, NULL, 0, 61692, 1, NULL),
|
||||
(4, 1, 60, 'AMR', 1, 1, NULL, 1, 05080000, 1, 4751000000, 0, NULL, 0, 66090, 2, NULL),
|
||||
(4, 1, 60, 'AMR', 1, 1, 'Increases block', 1, 05080000, 1, 4751000000, 0, NULL, 0, 66090, 2, NULL),
|
||||
(5, 3, 30, 'GRE', 1, 2, NULL, 2, 06021010, 1, 4751000000, 0, NULL, 0, 67350, 2, NULL),
|
||||
(6, 5, 30, 'GRE', 1, 2, NULL, NULL, 06021010, 0, 4751000000, 0, NULL, 0, 67350, 2, NULL),
|
||||
(7, 5, 90, 'AZL', 1, 2, NULL, NULL, 06021010, 0, 4751000000, 0, NULL, 0, 67350, 2, NULL),
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
const app = require('vn-loopback/server/server');
|
||||
const model = app.models.Buy;
|
||||
|
||||
describe('Buy editLatestsBuys()', () => {
|
||||
it('should change the value of a given column for the selected buys', async() => {
|
||||
let ctx = {
|
||||
args: {
|
||||
search: 'Ranged weapon longbow 2m'
|
||||
}
|
||||
};
|
||||
|
||||
let [original] = await model.latestBuysFilter(ctx);
|
||||
|
||||
const column = {field: 'size', newValue: 99};
|
||||
const buys = [{itemFk: 1, id: 3}];
|
||||
|
||||
await model.editLatestBuys(column, buys);
|
||||
|
||||
let [result] = await model.latestBuysFilter(ctx);
|
||||
|
||||
expect(result.size).toEqual(99);
|
||||
|
||||
column.newValue = original.size;
|
||||
await model.editLatestBuys(column, buys);
|
||||
|
||||
let [restoredFixture] = await model.latestBuysFilter(ctx);
|
||||
|
||||
expect(restoredFixture.size).toEqual(original.size);
|
||||
});
|
||||
});
|
|
@ -1,15 +1,139 @@
|
|||
const app = require('vn-loopback/server/server');
|
||||
|
||||
fdescribe('Entry latests buys filter()', () => {
|
||||
describe('Buy latests buys filter()', () => {
|
||||
it('should return the entry matching "search"', async() => {
|
||||
let ctx = {
|
||||
args: {
|
||||
search: 1
|
||||
search: 'Ranged weapon longbow 2m'
|
||||
}
|
||||
};
|
||||
|
||||
let result = await app.models.Entry.latestBuysFilter(ctx);
|
||||
let results = await app.models.Buy.latestBuysFilter(ctx);
|
||||
let firstBuy = results[0];
|
||||
|
||||
expect(result[0].size).toEqual(300);
|
||||
expect(results.length).toEqual(1);
|
||||
expect(firstBuy.size).toEqual(70);
|
||||
});
|
||||
|
||||
it('should return the entry matching "id"', async() => {
|
||||
let ctx = {
|
||||
args: {
|
||||
id: 1
|
||||
}
|
||||
};
|
||||
|
||||
let results = await app.models.Buy.latestBuysFilter(ctx);
|
||||
|
||||
expect(results.length).toEqual(1);
|
||||
});
|
||||
|
||||
it('should return results matching "tags"', async() => {
|
||||
let ctx = {
|
||||
args: {
|
||||
tags: [
|
||||
{tagFk: 27, value: '2m'}
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
let results = await app.models.Buy.latestBuysFilter(ctx);
|
||||
|
||||
expect(results.length).toBe(2);
|
||||
});
|
||||
|
||||
it('should return results matching "categoryFk"', async() => {
|
||||
let ctx = {
|
||||
args: {
|
||||
categoryFk: 1
|
||||
}
|
||||
};
|
||||
|
||||
let results = await app.models.Buy.latestBuysFilter(ctx);
|
||||
|
||||
expect(results.length).toBe(4);
|
||||
});
|
||||
|
||||
it('should return results matching "typeFk"', async() => {
|
||||
let ctx = {
|
||||
args: {
|
||||
typeFk: 2
|
||||
}
|
||||
};
|
||||
|
||||
let results = await app.models.Buy.latestBuysFilter(ctx);
|
||||
|
||||
expect(results.length).toBe(4);
|
||||
});
|
||||
|
||||
it('should return results matching "active"', async() => {
|
||||
let ctx = {
|
||||
args: {
|
||||
active: true
|
||||
}
|
||||
};
|
||||
|
||||
let results = await app.models.Buy.latestBuysFilter(ctx);
|
||||
|
||||
expect(results.length).toBe(6);
|
||||
});
|
||||
|
||||
it('should return results matching "not active"', async() => {
|
||||
let ctx = {
|
||||
args: {
|
||||
active: false
|
||||
}
|
||||
};
|
||||
|
||||
let results = await app.models.Buy.latestBuysFilter(ctx);
|
||||
|
||||
expect(results.length).toBe(0);
|
||||
});
|
||||
|
||||
it('should return results matching "visible"', async() => {
|
||||
let ctx = {
|
||||
args: {
|
||||
visible: true
|
||||
}
|
||||
};
|
||||
|
||||
let results = await app.models.Buy.latestBuysFilter(ctx);
|
||||
|
||||
expect(results.length).toBe(5);
|
||||
});
|
||||
|
||||
it('should return results matching "not visible"', async() => {
|
||||
let ctx = {
|
||||
args: {
|
||||
visible: false
|
||||
}
|
||||
};
|
||||
|
||||
let results = await app.models.Buy.latestBuysFilter(ctx);
|
||||
|
||||
expect(results.length).toBe(0);
|
||||
});
|
||||
|
||||
it('should return results matching "salesPersonFk"', async() => {
|
||||
let ctx = {
|
||||
args: {
|
||||
salesPersonFk: 35
|
||||
}
|
||||
};
|
||||
|
||||
let results = await app.models.Buy.latestBuysFilter(ctx);
|
||||
|
||||
expect(results.length).toBe(6);
|
||||
});
|
||||
|
||||
it('should return results matching "description"', async() => {
|
||||
let ctx = {
|
||||
args: {
|
||||
description: 'Increases block'
|
||||
}
|
||||
};
|
||||
|
||||
let results = await app.models.Buy.latestBuysFilter(ctx);
|
||||
|
||||
expect(results.length).toBe(1);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
import './index.js';
|
||||
|
||||
describe('Entry Component vnEntryDescriptor', () => {
|
||||
let $httpBackend;
|
||||
let controller;
|
||||
const entry = {id: 2};
|
||||
|
||||
beforeEach(ngModule('entry'));
|
||||
|
||||
beforeEach(inject($componentController => {
|
||||
beforeEach(inject(($componentController, _$httpBackend_) => {
|
||||
$httpBackend = _$httpBackend_;
|
||||
controller = $componentController('vnEntryDescriptor', {$element: null}, {entry});
|
||||
}));
|
||||
|
||||
|
@ -24,4 +26,18 @@ describe('Entry Component vnEntryDescriptor', () => {
|
|||
expect(controller.vnReport.show).toHaveBeenCalledWith('entry-order', params);
|
||||
});
|
||||
});
|
||||
|
||||
describe('loadData()', () => {
|
||||
it('should perform ask for the entry', () => {
|
||||
let query = `Entries/${entry.id}`;
|
||||
jest.spyOn(controller, 'getData');
|
||||
|
||||
$httpBackend.expectGET(query).respond();
|
||||
controller.loadData();
|
||||
$httpBackend.flush();
|
||||
|
||||
expect(controller.getData).toHaveBeenCalledTimes(1);
|
||||
expect(controller.getData).toHaveBeenCalledWith(query, jasmine.any(Object));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
import './index.js';
|
||||
|
||||
xdescribe('Item', () => {
|
||||
describe('Component vnItemSearchPanel', () => {
|
||||
describe('Entry', () => {
|
||||
describe('Component vnLatestBuysSearchPanel', () => {
|
||||
let $element;
|
||||
let controller;
|
||||
|
||||
beforeEach(ngModule('item'));
|
||||
beforeEach(ngModule('entry'));
|
||||
|
||||
beforeEach(angular.mock.inject($componentController => {
|
||||
$element = angular.element(`<div></div>`);
|
||||
$element = angular.element(`<vn-latest-buys-search-panel></vn-latest-buys-search-panel>`);
|
||||
controller = $componentController('vnLatestBuysSearchPanel', {$element});
|
||||
}));
|
||||
|
||||
|
|
|
@ -47,7 +47,6 @@ export default class Controller extends Section {
|
|||
}
|
||||
|
||||
uncheck() {
|
||||
console.log('clicked!');
|
||||
const lines = this.checked;
|
||||
for (let line of lines) {
|
||||
if (line.checked)
|
||||
|
@ -73,8 +72,6 @@ export default class Controller extends Section {
|
|||
});
|
||||
|
||||
this.editedColumn = null;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,91 @@
|
|||
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();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue