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(''); controller = $componentController('vnMonitorSalesTickets', {$element}); })); describe('fetchParams()', () => { it('should return a range of dates with passed scope days', () => { let params = controller.fetchParams({ scopeDays: 2 }); const from = new Date(); 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', () => { let today = new Date(); let result = controller.compareDate(today); expect(result).toEqual('warning'); }); it('should return sucess when the date is in the future', () => { let futureDate = new Date(); 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', () => { let pastDate = new Date(); pastDate = pastDate.setDate(pastDate.getDate() - 10); let result = controller.compareDate(pastDate); expect(result).toEqual(undefined); }); }); 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('dateRange()', () => { it('should return two dates with the hours at the start and end of the given date', () => { const now = new Date(); 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'); }); }); 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(); }); }); });