From 88616862cbbaf1891a27426f38bb8318acc30b31 Mon Sep 17 00:00:00 2001 From: joan Date: Wed, 12 May 2021 09:12:46 +0200 Subject: [PATCH] Updated unit tests --- .../sales-monitor/specs/clientsFilter.spec.js | 2 +- .../front/index/search-panel/index.spec.js | 6 +- .../monitor/front/index/tickets/index.spec.js | 133 ++++++++++++++++++ .../back/methods/order/specs/filter.spec.js | 6 +- .../back/methods/ticket/specs/filter.spec.js | 8 +- 5 files changed, 144 insertions(+), 11 deletions(-) create mode 100644 modules/monitor/front/index/tickets/index.spec.js diff --git a/modules/monitor/back/methods/sales-monitor/specs/clientsFilter.spec.js b/modules/monitor/back/methods/sales-monitor/specs/clientsFilter.spec.js index c01c65433..c930b5dfb 100644 --- a/modules/monitor/back/methods/sales-monitor/specs/clientsFilter.spec.js +++ b/modules/monitor/back/methods/sales-monitor/specs/clientsFilter.spec.js @@ -1,6 +1,6 @@ const app = require('vn-loopback/server/server'); -fdescribe('SalesMonitor clientsFilter()', () => { +describe('SalesMonitor clientsFilter()', () => { it('should return the clients web activity', async() => { const ctx = {req: {accessToken: {userId: 18}}, args: {}}; const filter = {order: 'dated DESC'}; diff --git a/modules/monitor/front/index/search-panel/index.spec.js b/modules/monitor/front/index/search-panel/index.spec.js index f3a2f39ed..0d19fd35f 100644 --- a/modules/monitor/front/index/search-panel/index.spec.js +++ b/modules/monitor/front/index/search-panel/index.spec.js @@ -1,14 +1,14 @@ import './index'; -describe('Ticket Component vnTicketSearchPanel', () => { +describe('Monitor Component vnMonitorSalesSearchPanel', () => { let $httpBackend; let controller; - beforeEach(ngModule('ticket')); + beforeEach(ngModule('monitor')); beforeEach(inject(($componentController, _$httpBackend_) => { $httpBackend = _$httpBackend_; - controller = $componentController('vnTicketSearchPanel', {$element: null}); + controller = $componentController('vnMonitorSalesSearchPanel', {$element: null}); controller.$t = () => {}; controller.filter = {}; })); diff --git a/modules/monitor/front/index/tickets/index.spec.js b/modules/monitor/front/index/tickets/index.spec.js new file mode 100644 index 000000000..fc689140a --- /dev/null +++ b/modules/monitor/front/index/tickets/index.spec.js @@ -0,0 +1,133 @@ +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('stateColor()', () => { + it('should return "success" when the alertLevelCode property is "OK"', () => { + const result = controller.stateColor({alertLevelCode: 'OK'}); + + expect(result).toEqual('success'); + }); + + it('should return "notice" when the alertLevelCode property is "FREE"', () => { + const result = controller.stateColor({alertLevelCode: 'FREE'}); + + expect(result).toEqual('notice'); + }); + + it('should return "warning" when the alertLevel property is "1', () => { + const result = controller.stateColor({alertLevel: 1}); + + expect(result).toEqual('warning'); + }); + + it('should return "alert" when the alertLevel property is "0"', () => { + const result = controller.stateColor({alertLevel: 0}); + + expect(result).toEqual('alert'); + }); + }); + + 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(); + }); + }); +}); diff --git a/modules/order/back/methods/order/specs/filter.spec.js b/modules/order/back/methods/order/specs/filter.spec.js index 1e6022ccb..1cc434cf1 100644 --- a/modules/order/back/methods/order/specs/filter.spec.js +++ b/modules/order/back/methods/order/specs/filter.spec.js @@ -23,11 +23,11 @@ describe('order filter()', () => { }); it('should call the filter method with a complex advanced search', async() => { - const filter = {where: {'o.confirmed': false, 'c.salesPersonFk': 19}}; + const filter = {where: {'o.confirmed': false, 'c.salesPersonFk': 18}}; const result = await app.models.Order.filter(ctx, filter); - expect(result.length).toEqual(7); - expect(result[0].id).toEqual(16); + expect(result.length).toEqual(9); + expect(result[0].id).toEqual(7); }); it('should return the orders matching the showEmpty on false', async() => { diff --git a/modules/ticket/back/methods/ticket/specs/filter.spec.js b/modules/ticket/back/methods/ticket/specs/filter.spec.js index 2ca8bcf44..7798b156e 100644 --- a/modules/ticket/back/methods/ticket/specs/filter.spec.js +++ b/modules/ticket/back/methods/ticket/specs/filter.spec.js @@ -89,18 +89,18 @@ describe('ticket filter()', () => { }); it('should return the tickets from the worker team', async() => { - const ctx = {req: {accessToken: {userId: 9}}, args: {myTeam: true}}; + const ctx = {req: {accessToken: {userId: 18}}, args: {myTeam: true}}; const filter = {}; const result = await app.models.Ticket.filter(ctx, filter); - expect(result.length).toEqual(17); + expect(result.length).toEqual(20); }); it('should return the tickets that are not from the worker team', async() => { - const ctx = {req: {accessToken: {userId: 9}}, args: {myTeam: false}}; + const ctx = {req: {accessToken: {userId: 18}}, args: {myTeam: false}}; const filter = {}; const result = await app.models.Ticket.filter(ctx, filter); - expect(result.length).toEqual(7); + expect(result.length).toEqual(4); }); });