Updated unit tests
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
d2169000f4
commit
88616862cb
|
@ -1,6 +1,6 @@
|
||||||
const app = require('vn-loopback/server/server');
|
const app = require('vn-loopback/server/server');
|
||||||
|
|
||||||
fdescribe('SalesMonitor clientsFilter()', () => {
|
describe('SalesMonitor clientsFilter()', () => {
|
||||||
it('should return the clients web activity', async() => {
|
it('should return the clients web activity', async() => {
|
||||||
const ctx = {req: {accessToken: {userId: 18}}, args: {}};
|
const ctx = {req: {accessToken: {userId: 18}}, args: {}};
|
||||||
const filter = {order: 'dated DESC'};
|
const filter = {order: 'dated DESC'};
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
import './index';
|
import './index';
|
||||||
|
|
||||||
describe('Ticket Component vnTicketSearchPanel', () => {
|
describe('Monitor Component vnMonitorSalesSearchPanel', () => {
|
||||||
let $httpBackend;
|
let $httpBackend;
|
||||||
let controller;
|
let controller;
|
||||||
|
|
||||||
beforeEach(ngModule('ticket'));
|
beforeEach(ngModule('monitor'));
|
||||||
|
|
||||||
beforeEach(inject(($componentController, _$httpBackend_) => {
|
beforeEach(inject(($componentController, _$httpBackend_) => {
|
||||||
$httpBackend = _$httpBackend_;
|
$httpBackend = _$httpBackend_;
|
||||||
controller = $componentController('vnTicketSearchPanel', {$element: null});
|
controller = $componentController('vnMonitorSalesSearchPanel', {$element: null});
|
||||||
controller.$t = () => {};
|
controller.$t = () => {};
|
||||||
controller.filter = {};
|
controller.filter = {};
|
||||||
}));
|
}));
|
||||||
|
|
|
@ -0,0 +1,133 @@
|
||||||
|
import './index.js';
|
||||||
|
describe('Component vnMonitorSalesTickets', () => {
|
||||||
|
let controller;
|
||||||
|
let $window;
|
||||||
|
let tickets = [{
|
||||||
|
id: 1,
|
||||||
|
clientFk: 1,
|
||||||
|
checked: false,
|
||||||
|
totalWithVat: 10.5
|
||||||
|
}, {
|
||||||
|
id: 2,
|
||||||
|
clientFk: 1,
|
||||||
|
checked: true,
|
||||||
|
totalWithVat: 20.5
|
||||||
|
}, {
|
||||||
|
id: 3,
|
||||||
|
clientFk: 1,
|
||||||
|
checked: true,
|
||||||
|
totalWithVat: 30
|
||||||
|
}];
|
||||||
|
|
||||||
|
beforeEach(ngModule('monitor'));
|
||||||
|
|
||||||
|
beforeEach(inject(($componentController, _$window_) => {
|
||||||
|
$window = _$window_;
|
||||||
|
const $element = angular.element('<vn-monitor-sales-tickets></vn-monitor-sales-tickets>');
|
||||||
|
controller = $componentController('vnMonitorSalesTickets', {$element});
|
||||||
|
}));
|
||||||
|
|
||||||
|
describe('fetchParams()', () => {
|
||||||
|
it('should return a range of dates with passed scope days', () => {
|
||||||
|
let params = controller.fetchParams({
|
||||||
|
scopeDays: 2
|
||||||
|
});
|
||||||
|
const from = new Date();
|
||||||
|
from.setHours(0, 0, 0, 0);
|
||||||
|
const to = new Date(from.getTime());
|
||||||
|
to.setDate(to.getDate() + params.scopeDays);
|
||||||
|
to.setHours(23, 59, 59, 999);
|
||||||
|
|
||||||
|
const expectedParams = {
|
||||||
|
from,
|
||||||
|
scopeDays: params.scopeDays,
|
||||||
|
to
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(params).toEqual(expectedParams);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return default value for scope days', () => {
|
||||||
|
let params = controller.fetchParams({
|
||||||
|
scopeDays: 1
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(params.scopeDays).toEqual(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return the given scope days', () => {
|
||||||
|
let params = controller.fetchParams({
|
||||||
|
scopeDays: 2
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(params.scopeDays).toEqual(2);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('compareDate()', () => {
|
||||||
|
it('should return warning when the date is the present', () => {
|
||||||
|
let today = new Date();
|
||||||
|
let result = controller.compareDate(today);
|
||||||
|
|
||||||
|
expect(result).toEqual('warning');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return sucess when the date is in the future', () => {
|
||||||
|
let futureDate = new Date();
|
||||||
|
futureDate = futureDate.setDate(futureDate.getDate() + 10);
|
||||||
|
let result = controller.compareDate(futureDate);
|
||||||
|
|
||||||
|
expect(result).toEqual('success');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return undefined when the date is in the past', () => {
|
||||||
|
let pastDate = new Date();
|
||||||
|
pastDate = pastDate.setDate(pastDate.getDate() - 10);
|
||||||
|
let result = controller.compareDate(pastDate);
|
||||||
|
|
||||||
|
expect(result).toEqual(undefined);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('stateColor()', () => {
|
||||||
|
it('should return "success" when the alertLevelCode property is "OK"', () => {
|
||||||
|
const result = controller.stateColor({alertLevelCode: 'OK'});
|
||||||
|
|
||||||
|
expect(result).toEqual('success');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return "notice" when the alertLevelCode property is "FREE"', () => {
|
||||||
|
const result = controller.stateColor({alertLevelCode: 'FREE'});
|
||||||
|
|
||||||
|
expect(result).toEqual('notice');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return "warning" when the alertLevel property is "1', () => {
|
||||||
|
const result = controller.stateColor({alertLevel: 1});
|
||||||
|
|
||||||
|
expect(result).toEqual('warning');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return "alert" when the alertLevel property is "0"', () => {
|
||||||
|
const result = controller.stateColor({alertLevel: 0});
|
||||||
|
|
||||||
|
expect(result).toEqual('alert');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('preview()', () => {
|
||||||
|
it('should show the dialog summary', () => {
|
||||||
|
controller.$.summary = {show: () => {}};
|
||||||
|
jest.spyOn(controller.$.summary, 'show');
|
||||||
|
|
||||||
|
let event = new MouseEvent('click', {
|
||||||
|
view: $window,
|
||||||
|
bubbles: true,
|
||||||
|
cancelable: true
|
||||||
|
});
|
||||||
|
controller.preview(event, tickets[0]);
|
||||||
|
|
||||||
|
expect(controller.$.summary.show).toHaveBeenCalledWith();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -23,11 +23,11 @@ describe('order filter()', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should call the filter method with a complex advanced search', async() => {
|
it('should call the filter method with a complex advanced search', async() => {
|
||||||
const filter = {where: {'o.confirmed': false, 'c.salesPersonFk': 19}};
|
const filter = {where: {'o.confirmed': false, 'c.salesPersonFk': 18}};
|
||||||
const result = await app.models.Order.filter(ctx, filter);
|
const result = await app.models.Order.filter(ctx, filter);
|
||||||
|
|
||||||
expect(result.length).toEqual(7);
|
expect(result.length).toEqual(9);
|
||||||
expect(result[0].id).toEqual(16);
|
expect(result[0].id).toEqual(7);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return the orders matching the showEmpty on false', async() => {
|
it('should return the orders matching the showEmpty on false', async() => {
|
||||||
|
|
|
@ -89,18 +89,18 @@ describe('ticket filter()', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return the tickets from the worker team', async() => {
|
it('should return the tickets from the worker team', async() => {
|
||||||
const ctx = {req: {accessToken: {userId: 9}}, args: {myTeam: true}};
|
const ctx = {req: {accessToken: {userId: 18}}, args: {myTeam: true}};
|
||||||
const filter = {};
|
const filter = {};
|
||||||
const result = await app.models.Ticket.filter(ctx, filter);
|
const result = await app.models.Ticket.filter(ctx, filter);
|
||||||
|
|
||||||
expect(result.length).toEqual(17);
|
expect(result.length).toEqual(20);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return the tickets that are not from the worker team', async() => {
|
it('should return the tickets that are not from the worker team', async() => {
|
||||||
const ctx = {req: {accessToken: {userId: 9}}, args: {myTeam: false}};
|
const ctx = {req: {accessToken: {userId: 18}}, args: {myTeam: false}};
|
||||||
const filter = {};
|
const filter = {};
|
||||||
const result = await app.models.Ticket.filter(ctx, filter);
|
const result = await app.models.Ticket.filter(ctx, filter);
|
||||||
|
|
||||||
expect(result.length).toEqual(7);
|
expect(result.length).toEqual(4);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue