2020-07-02 05:46:55 +00:00
|
|
|
import './index.js';
|
|
|
|
describe('Component vnOrderIndex', () => {
|
|
|
|
let controller;
|
|
|
|
let $window;
|
|
|
|
let orders = [{
|
|
|
|
id: 1,
|
|
|
|
clientFk: 1,
|
|
|
|
isConfirmed: false
|
|
|
|
}, {
|
|
|
|
id: 2,
|
|
|
|
clientFk: 1,
|
|
|
|
isConfirmed: false
|
|
|
|
}, {
|
|
|
|
id: 3,
|
|
|
|
clientFk: 1,
|
|
|
|
isConfirmed: true
|
|
|
|
}];
|
|
|
|
|
|
|
|
beforeEach(ngModule('order'));
|
|
|
|
|
2020-10-26 07:38:43 +00:00
|
|
|
beforeEach(inject(($componentController, _$window_) => {
|
2020-07-02 05:46:55 +00:00
|
|
|
$window = _$window_;
|
|
|
|
const $element = angular.element('<vn-order-index></vn-order-index>');
|
|
|
|
controller = $componentController('vnOrderIndex', {$element});
|
|
|
|
}));
|
|
|
|
|
|
|
|
describe('compareDate()', () => {
|
|
|
|
it('should return warning when the date is the present', () => {
|
2023-01-16 14:18:24 +00:00
|
|
|
let curDate = Date.vnNew();
|
2020-07-02 05:46:55 +00:00
|
|
|
let result = controller.compareDate(curDate);
|
|
|
|
|
|
|
|
expect(result).toEqual('warning');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return sucess when the date is in the future', () => {
|
2023-01-16 14:18:24 +00:00
|
|
|
let futureDate = Date.vnNew();
|
2020-07-02 05:46:55 +00:00
|
|
|
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', () => {
|
2023-01-16 14:18:24 +00:00
|
|
|
let pastDate = Date.vnNew();
|
2020-07-02 05:46:55 +00:00
|
|
|
pastDate = pastDate.setDate(pastDate.getDate() - 10);
|
|
|
|
let result = controller.compareDate(pastDate);
|
|
|
|
|
|
|
|
expect(result).toEqual(undefined);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
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, orders[0]);
|
|
|
|
|
|
|
|
expect(controller.$.summary.show).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|