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

155 lines
5.4 KiB
JavaScript
Raw Normal View History

2018-08-09 13:10:45 +00:00
import './index';
import crudModel from 'core/mocks/crud-model';
2018-08-09 13:10:45 +00:00
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};
controller.$.ticketsModel = crudModel;
2018-08-09 13:10:45 +00:00
}));
describe('client() setter', () => {
it('should call to the loadData() and loadTickets() methods', () => {
controller.loadData = jest.fn();
controller.loadTickets = jest.fn();
controller.client = {id: 1102};
expect(controller.loadData).toHaveBeenCalledWith();
expect(controller.loadTickets).toHaveBeenCalledWith();
});
});
describe('loadData()', () => {
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
controller.loadData();
2018-08-09 13:10:45 +00:00
$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
describe('loadTickets()', () => {
it('should call to the model refresh() method', () => {
jest.spyOn(controller.$.ticketsModel, 'refresh');
controller.loadTickets();
controller.$.$apply();
expect(controller.$.ticketsModel.refresh).toHaveBeenCalledWith();
});
});
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', () => {
2023-01-16 14:18:24 +00:00
let today = Date.vnNew();
2021-06-16 09:40:00 +00:00
let result = controller.chipColor(today);
expect(result).toEqual('warning');
});
it('should return success when the date is in the future', () => {
2023-01-16 14:18:24 +00:00
let futureDate = Date.vnNew();
2021-06-16 09:40:00 +00:00
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', () => {
2023-01-16 14:18:24 +00:00
let pastDate = Date.vnNew();
2021-06-16 09:40:00 +00:00
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
});
});