salix/modules/client/front/summary/index.spec.js

130 lines
4.5 KiB
JavaScript
Raw Normal View History

2018-08-09 13:10:45 +00:00
import './index';
describe('Client', () => {
describe('Component vnClientSummary', () => {
let controller;
let $httpBackend;
2021-06-16 09:40:00 +00:00
let $window;
2018-08-09 13:10:45 +00:00
beforeEach(ngModule('client'));
2018-08-09 13:10:45 +00:00
2021-06-16 09:40:00 +00:00
beforeEach(inject(($componentController, _$httpBackend_, _$window_) => {
$window = _$window_;
2018-08-09 13:10:45 +00:00
$httpBackend = _$httpBackend_;
2020-03-17 10:17:50 +00:00
const $element = angular.element('<vn-client-summary></vn-client-summary>');
2021-06-16 09:40:00 +00:00
controller = $componentController('vnClientSummary', {$element});
controller.client = {id: 1101};
2018-08-09 13:10:45 +00:00
}));
describe('$onChanges()', () => {
2020-02-26 12:22:52 +00:00
it('should perform a GET query and then define the summary property', () => {
2018-08-09 13:10:45 +00:00
let res = {name: 'Superman', classifications: []};
2018-10-19 06:40:32 +00:00
2020-02-27 06:19:42 +00:00
jest.spyOn(controller, 'sumRisk').mockReturnThis();
$httpBackend.expect('GET', `Clients/1101/summary`).respond(200, res);
2018-10-19 06:40:32 +00:00
2018-08-09 13:10:45 +00:00
controller.$onChanges();
$httpBackend.flush();
expect(controller.summary).toBeDefined();
expect(controller.summary.name).toEqual('Superman');
});
2018-10-19 06:40:32 +00:00
});
2018-08-09 13:10:45 +00:00
2018-10-19 06:40:32 +00:00
describe('sumRisk()', () => {
it('should sum property amount of an array', () => {
controller.summary = {
clientRisks: [{
companyFk: 442,
amount: 100
},
{
companyFk: 567,
amount: 200
}]};
2018-08-09 13:10:45 +00:00
2018-10-19 06:40:32 +00:00
let result = controller.sumRisk();
expect(result).toEqual(300);
2018-08-09 13:10:45 +00:00
});
});
2021-06-16 09:40:00 +00:00
describe('chipColor()', () => {
it('should return warning when the date is the present', () => {
let today = new Date();
let result = controller.chipColor(today);
expect(result).toEqual('warning');
});
it('should return success when the date is in the future', () => {
let futureDate = new Date();
futureDate = futureDate.setDate(futureDate.getDate() + 10);
let result = controller.chipColor(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.chipColor(pastDate);
expect(result).toEqual(undefined);
});
});
describe('stateColor()', () => {
it('should return "success" when the alertLevelCode property is "OK"', () => {
2021-06-18 14:14:30 +00:00
const result = controller.stateColor({ticketState: {code: 'OK'}});
2021-06-16 09:40:00 +00:00
expect(result).toEqual('success');
});
it('should return "notice" when the alertLevelCode property is "FREE"', () => {
2021-06-18 14:14:30 +00:00
const result = controller.stateColor({ticketState: {code: 'FREE'}});
2021-06-16 09:40:00 +00:00
expect(result).toEqual('notice');
});
it('should return "warning" when the alertLevel property is "1', () => {
2021-06-18 14:14:30 +00:00
const result = controller.stateColor({ticketState: {code: 'PACKING', alertLevel: 1}});
2021-06-16 09:40:00 +00:00
expect(result).toEqual('warning');
});
it('should return "alert" when the alertLevel property is "0"', () => {
2021-06-18 14:14:30 +00:00
const result = controller.stateColor({ticketState: {code: 'FIXING', alertLevel: 0}});
2021-06-16 09:40:00 +00:00
expect(result).toEqual('alert');
});
});
describe('totalPriceColor()', () => {
it('should return "warning" when the ticket amount is less than 50€', () => {
const result = controller.totalPriceColor({totalWithVat: '8.50'});
expect(result).toEqual('warning');
});
});
describe('preview()', () => {
it('should show the dialog summary', () => {
controller.$.summary = {show: () => {}};
jest.spyOn(controller.$.summary, 'show');
const ticket = {id: 1, clientFk: 1101};
2021-06-16 09:40:00 +00:00
const event = new MouseEvent('click', {
view: $window,
bubbles: true,
cancelable: true
});
controller.preview(event, ticket);
expect(controller.$.summary.show).toHaveBeenCalledWith();
});
});
2018-08-09 13:10:45 +00:00
});
});