2018-05-25 08:03:45 +00:00
|
|
|
import './index.js';
|
2018-04-19 12:56:05 +00:00
|
|
|
|
2018-10-30 12:58:02 +00:00
|
|
|
describe('Component vnTicketIndex', () => {
|
|
|
|
let $element;
|
|
|
|
let $ctrl;
|
|
|
|
let $window;
|
|
|
|
let tickets = [{
|
|
|
|
id: 1,
|
|
|
|
clientFk: 1,
|
|
|
|
salesPersonFk: 9,
|
|
|
|
shipped: new Date(),
|
|
|
|
nickname: 'Test',
|
|
|
|
total: 10.5
|
|
|
|
}];
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
ngModule('client');
|
|
|
|
ngModule('item');
|
|
|
|
ngModule('ticket');
|
|
|
|
});
|
2018-08-13 07:32:33 +00:00
|
|
|
|
2018-10-30 12:58:02 +00:00
|
|
|
beforeEach(inject(($compile, $rootScope, $httpBackend, _$window_) => {
|
|
|
|
$window = _$window_;
|
|
|
|
$element = $compile('<vn-ticket-index></vn-ticket-index>')($rootScope);
|
|
|
|
$ctrl = $element.controller('vnTicketIndex');
|
2018-08-13 07:32:33 +00:00
|
|
|
|
2018-10-30 12:58:02 +00:00
|
|
|
$httpBackend.whenGET(/\/ticket\/api\/Tickets\/filter.*/).respond(tickets);
|
|
|
|
$httpBackend.flush();
|
|
|
|
}));
|
2018-08-13 07:32:33 +00:00
|
|
|
|
2018-10-30 12:58:02 +00:00
|
|
|
afterEach(() => {
|
|
|
|
$element.remove();
|
|
|
|
});
|
2018-08-13 07:32:33 +00:00
|
|
|
|
2018-10-30 12:58:02 +00:00
|
|
|
describe('compareDate()', () => {
|
|
|
|
it('should return warning when the date is the present', () => {
|
|
|
|
let curDate = new Date();
|
|
|
|
let result = $ctrl.compareDate(curDate);
|
2018-08-13 07:32:33 +00:00
|
|
|
|
2018-10-30 12:58:02 +00:00
|
|
|
expect(result).toEqual('warning');
|
|
|
|
});
|
2018-08-13 07:32:33 +00:00
|
|
|
|
2018-10-30 12:58:02 +00:00
|
|
|
it('should return sucess when the date is in the future', () => {
|
|
|
|
let futureDate = new Date();
|
|
|
|
futureDate = futureDate.setDate(futureDate.getDate() + 10);
|
|
|
|
let result = $ctrl.compareDate(futureDate);
|
2018-08-13 07:32:33 +00:00
|
|
|
|
2018-10-30 12:58:02 +00:00
|
|
|
expect(result).toEqual('success');
|
|
|
|
});
|
2018-08-13 07:32:33 +00:00
|
|
|
|
2018-10-30 12:58:02 +00:00
|
|
|
it('should return undefined when the date is in the past', () => {
|
|
|
|
let pastDate = new Date();
|
|
|
|
pastDate = pastDate.setDate(pastDate.getDate() - 10);
|
|
|
|
let result = $ctrl.compareDate(pastDate);
|
2018-08-13 07:32:33 +00:00
|
|
|
|
2018-10-30 12:58:02 +00:00
|
|
|
expect(result).toEqual(undefined);
|
2018-08-13 07:32:33 +00:00
|
|
|
});
|
2018-10-30 12:58:02 +00:00
|
|
|
});
|
2018-08-13 07:32:33 +00:00
|
|
|
|
2018-10-30 12:58:02 +00:00
|
|
|
describe('showDescriptor()', () => {
|
|
|
|
it('should show the descriptor popover', () => {
|
|
|
|
spyOn($ctrl.$.descriptor, 'show');
|
2018-04-19 12:56:05 +00:00
|
|
|
|
2018-10-30 12:58:02 +00:00
|
|
|
let event = new MouseEvent('click', {
|
|
|
|
view: $window,
|
|
|
|
bubbles: true,
|
|
|
|
cancelable: true
|
2018-04-19 12:56:05 +00:00
|
|
|
});
|
2018-10-30 12:58:02 +00:00
|
|
|
$ctrl.showDescriptor(event, tickets[0].clientFk);
|
2018-04-19 12:56:05 +00:00
|
|
|
|
2018-10-30 12:58:02 +00:00
|
|
|
expect($ctrl.$.descriptor.show).toHaveBeenCalledWith();
|
2018-04-19 12:56:05 +00:00
|
|
|
});
|
2018-10-30 12:58:02 +00:00
|
|
|
});
|
2018-04-19 12:56:05 +00:00
|
|
|
|
2018-10-30 12:58:02 +00:00
|
|
|
describe('preview()', () => {
|
|
|
|
it('should show the dialog summary', () => {
|
|
|
|
spyOn($ctrl.$.summary, 'show');
|
2018-04-19 12:56:05 +00:00
|
|
|
|
2018-10-30 12:58:02 +00:00
|
|
|
let event = new MouseEvent('click', {
|
|
|
|
view: $window,
|
|
|
|
bubbles: true,
|
|
|
|
cancelable: true
|
2018-04-19 12:56:05 +00:00
|
|
|
});
|
2018-10-30 12:58:02 +00:00
|
|
|
$ctrl.preview(event, tickets[0]);
|
|
|
|
|
|
|
|
expect($ctrl.$.summary.show).toHaveBeenCalledWith();
|
2018-04-19 12:56:05 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|