salix/client/ticket/src/index/index.spec.js

99 lines
3.7 KiB
JavaScript
Raw Normal View History

import './index.js';
2018-04-19 12:56:05 +00:00
describe('ticket', () => {
describe('Component vnTicketIndex', () => {
2018-04-19 12:56:05 +00:00
let $componentController;
let controller;
beforeEach(() => {
angular.mock.module('ticket');
});
beforeEach(angular.mock.inject(_$componentController_ => {
$componentController = _$componentController_;
controller = $componentController('vnTicketIndex');
2018-04-19 12:56:05 +00:00
}));
2018-08-13 07:32:33 +00:00
describe('exprBuilder()', () => {
it('should return a formated object with the id in case of search', () => {
let param = 'search';
let value = 1;
let result = controller.exprBuilder(param, value);
expect(result).toEqual({id: 1});
});
it('should return a formated object with the nickname in case of search', () => {
let param = 'search';
let value = 'Bruce';
let result = controller.exprBuilder(param, value);
2018-08-30 09:02:50 +00:00
expect(result).toEqual({nickname: {like: 'Bruce'}});
2018-08-13 07:32:33 +00:00
});
it('should return a formated object with the date in case of from', () => {
let param = 'from';
let value = 'Fri Aug 10 2018 11:39:21 GMT+0200';
let result = controller.exprBuilder(param, value);
expect(result).toEqual({shipped: {gte: 'Fri Aug 10 2018 11:39:21 GMT+0200'}});
});
it('should return a formated object with the date in case of to', () => {
let param = 'to';
let value = 'Fri Aug 10 2018 11:39:21 GMT+0200';
let result = controller.exprBuilder(param, value);
expect(result).toEqual({shipped: {lte: 'Fri Aug 10 2018 11:39:21 GMT+0200'}});
});
it('should return a formated object with the nickname in case of nickname', () => {
let param = 'nickname';
let value = 'Bruce';
let result = controller.exprBuilder(param, value);
2018-08-30 09:02:50 +00:00
expect(result).toEqual({nickname: {like: 'Bruce'}});
2018-08-13 07:32:33 +00:00
});
it('should return a formated object with the warehouseFk in case of warehouseFk', () => {
let param = 'warehouseFk';
let value = 'Silla';
let result = controller.exprBuilder(param, value);
expect(result).toEqual({warehouseFk: 'Silla'});
});
});
2018-04-19 12:56:05 +00:00
describe('compareDate()', () => {
it('should return warning when the date is the present', () => {
let date = new Date();
let result = controller.compareDate(date);
expect(result).toEqual('warning');
});
2018-08-13 07:32:33 +00:00
it('should return sucess when the date is in the future', () => {
let futureDate = '2518-05-19T00:00:00.000Z';
let result = controller.compareDate(futureDate);
2018-04-19 12:56:05 +00:00
expect(result).toEqual('success');
});
});
describe('preview()', () => {
it('should call preventDefault and stopImmediatePropagation from event and show', () => {
let event = jasmine.createSpyObj('event', ['preventDefault', 'stopImmediatePropagation']);
2018-08-30 09:02:50 +00:00
controller.$scope = {dialogSummaryTicket: {show: () => {}}};
spyOn(controller.$scope.dialogSummaryTicket, 'show');
2018-04-19 12:56:05 +00:00
let ticket = {};
controller.preview(event, ticket);
expect(event.preventDefault).toHaveBeenCalledWith();
expect(event.stopImmediatePropagation).toHaveBeenCalledWith();
2018-08-30 09:02:50 +00:00
expect(controller.$scope.dialogSummaryTicket.show).toHaveBeenCalledWith();
2018-04-19 12:56:05 +00:00
});
});
});
});