2021-05-12 07:12:46 +00:00
|
|
|
import './index.js';
|
|
|
|
describe('Component vnMonitorSalesTickets', () => {
|
|
|
|
let controller;
|
|
|
|
let $window;
|
|
|
|
let tickets = [{
|
|
|
|
id: 1,
|
|
|
|
clientFk: 1,
|
|
|
|
checked: false,
|
|
|
|
totalWithVat: 10.5
|
|
|
|
}, {
|
|
|
|
id: 2,
|
|
|
|
clientFk: 1,
|
|
|
|
checked: true,
|
|
|
|
totalWithVat: 20.5
|
|
|
|
}, {
|
|
|
|
id: 3,
|
|
|
|
clientFk: 1,
|
|
|
|
checked: true,
|
|
|
|
totalWithVat: 30
|
|
|
|
}];
|
|
|
|
|
|
|
|
beforeEach(ngModule('monitor'));
|
|
|
|
|
|
|
|
beforeEach(inject(($componentController, _$window_) => {
|
|
|
|
$window = _$window_;
|
|
|
|
const $element = angular.element('<vn-monitor-sales-tickets></vn-monitor-sales-tickets>');
|
|
|
|
controller = $componentController('vnMonitorSalesTickets', {$element});
|
|
|
|
}));
|
|
|
|
|
|
|
|
describe('fetchParams()', () => {
|
|
|
|
it('should return a range of dates with passed scope days', () => {
|
|
|
|
let params = controller.fetchParams({
|
|
|
|
scopeDays: 2
|
|
|
|
});
|
2023-01-16 14:18:24 +00:00
|
|
|
const from = Date.vnNew();
|
2021-05-12 07:12:46 +00:00
|
|
|
from.setHours(0, 0, 0, 0);
|
|
|
|
const to = new Date(from.getTime());
|
|
|
|
to.setDate(to.getDate() + params.scopeDays);
|
|
|
|
to.setHours(23, 59, 59, 999);
|
|
|
|
|
|
|
|
const expectedParams = {
|
|
|
|
from,
|
|
|
|
scopeDays: params.scopeDays,
|
|
|
|
to
|
|
|
|
};
|
|
|
|
|
|
|
|
expect(params).toEqual(expectedParams);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return default value for scope days', () => {
|
|
|
|
let params = controller.fetchParams({
|
|
|
|
scopeDays: 1
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(params.scopeDays).toEqual(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return the given scope days', () => {
|
|
|
|
let params = controller.fetchParams({
|
|
|
|
scopeDays: 2
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(params.scopeDays).toEqual(2);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('compareDate()', () => {
|
|
|
|
it('should return warning when the date is the present', () => {
|
2023-01-16 14:18:24 +00:00
|
|
|
let today = Date.vnNew();
|
2021-05-12 07:12:46 +00:00
|
|
|
let result = controller.compareDate(today);
|
|
|
|
|
|
|
|
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();
|
2021-05-12 07:12:46 +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();
|
2021-05-12 07:12:46 +00:00
|
|
|
pastDate = pastDate.setDate(pastDate.getDate() - 10);
|
|
|
|
let result = controller.compareDate(pastDate);
|
|
|
|
|
|
|
|
expect(result).toEqual(undefined);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-06-16 09:15:17 +00:00
|
|
|
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');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-11-18 10:04:51 +00:00
|
|
|
describe('dateRange()', () => {
|
|
|
|
it('should return two dates with the hours at the start and end of the given date', () => {
|
2023-01-16 14:18:24 +00:00
|
|
|
const now = Date.vnNew();
|
2021-11-18 10:04:51 +00:00
|
|
|
|
|
|
|
const today = now.getDate();
|
|
|
|
|
|
|
|
const dateRange = controller.dateRange(now);
|
|
|
|
const start = dateRange[0].toString();
|
|
|
|
const end = dateRange[1].toString();
|
|
|
|
|
|
|
|
expect(start).toContain(today);
|
|
|
|
expect(start).toContain('00:00:00');
|
|
|
|
|
|
|
|
expect(end).toContain(today);
|
|
|
|
expect(end).toContain('23:59:59');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-05-12 07:12:46 +00:00
|
|
|
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, tickets[0]);
|
|
|
|
|
|
|
|
expect(controller.$.summary.show).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|