4856-worker.time-control #1375
|
@ -5,12 +5,14 @@ describe('Component vnWorkerTimeControl', () => {
|
|||
let $scope;
|
||||
let $element;
|
||||
let controller;
|
||||
let $httpParamSerializer;
|
||||
|
||||
beforeEach(ngModule('worker'));
|
||||
|
||||
beforeEach(inject(($componentController, $rootScope, $stateParams, _$httpBackend_) => {
|
||||
beforeEach(inject(($componentController, $rootScope, $stateParams, _$httpBackend_, _$httpParamSerializer_) => {
|
||||
$stateParams.id = 1;
|
||||
$httpBackend = _$httpBackend_;
|
||||
$httpParamSerializer = _$httpParamSerializer_;
|
||||
$scope = $rootScope.$new();
|
||||
$element = angular.element('<vn-worker-time-control></vn-worker-time-control>');
|
||||
controller = $componentController('vnWorkerTimeControl', {$element, $scope});
|
||||
|
@ -132,27 +134,142 @@ describe('Component vnWorkerTimeControl', () => {
|
|||
});
|
||||
});
|
||||
|
||||
// describe('$postLink() ', () => {
|
||||
// it(`should set the controller date as today if no timestamp is defined`, () => {
|
||||
// controller.$.model = {applyFilter: jest.fn().mockReturnValue(Promise.resolve())};
|
||||
// controller.$params = {timestamp: undefined};
|
||||
// controller.$postLink();
|
||||
describe('$postLink() ', () => {
|
||||
it(`should set the controller date as today if no timestamp is defined`, () => {
|
||||
controller.$.model = {applyFilter: jest.fn().mockReturnValue(Promise.resolve())};
|
||||
controller.$params = {timestamp: undefined};
|
||||
controller.$postLink();
|
||||
|
||||
// expect(controller.date).toEqual(jasmine.any(Date));
|
||||
// });
|
||||
expect(controller.date).toEqual(jasmine.any(Date));
|
||||
});
|
||||
|
||||
// it(`should set the controller date using the received timestamp`, () => {
|
||||
// const timestamp = 1;
|
||||
// const date = new Date(timestamp);
|
||||
it(`should set the controller date using the received timestamp`, () => {
|
||||
const timestamp = 1;
|
||||
const date = new Date(timestamp);
|
||||
|
||||
// controller.$.model = {applyFilter: jest.fn().mockReturnValue(Promise.resolve())};
|
||||
// controller.$.calendar = {};
|
||||
// controller.$params = {timestamp: timestamp};
|
||||
controller.$.model = {applyFilter: jest.fn().mockReturnValue(Promise.resolve())};
|
||||
controller.$.calendar = {};
|
||||
controller.$params = {timestamp: timestamp};
|
||||
|
||||
// controller.$postLink();
|
||||
controller.$postLink();
|
||||
|
||||
// expect(controller.date.toDateString()).toEqual(date.toDateString());
|
||||
// });
|
||||
// });
|
||||
expect(controller.date.toDateString()).toEqual(date.toDateString());
|
||||
});
|
||||
});
|
||||
|
||||
describe('getWeekData() ', () => {
|
||||
it(`should make a query an then update the state and reason`, () => {
|
||||
const today = Date.vnNew();
|
||||
const response = [
|
||||
{
|
||||
state: 'SENDED',
|
||||
reason: null
|
||||
}
|
||||
];
|
||||
|
||||
controller._date = today;
|
||||
|
||||
$httpBackend.whenRoute('GET', 'WorkerTimeControlMails')
|
||||
.respond(response);
|
||||
|
||||
controller.getWeekData();
|
||||
$httpBackend.flush();
|
||||
|
||||
expect(controller.state).toBe('SENDED');
|
||||
expect(controller.reason).toBe(null);
|
||||
});
|
||||
});
|
||||
|
||||
describe('isSatisfied() ', () => {
|
||||
it(`should make a query an then call three methods`, () => {
|
||||
const today = Date.vnNew();
|
||||
jest.spyOn(controller, 'getWeekData').mockReturnThis();
|
||||
jest.spyOn(controller, 'getMailStates').mockReturnThis();
|
||||
jest.spyOn(controller.vnApp, 'showSuccess');
|
||||
|
||||
controller.$.model = {applyFilter: jest.fn().mockReturnValue(Promise.resolve())};
|
||||
controller.worker = {id: 1};
|
||||
controller.date = today;
|
||||
controller.weekNumber = 1;
|
||||
|
||||
$httpBackend.expect('POST', 'WorkerTimeControls/updateWorkerTimeControlMail').respond();
|
||||
controller.isSatisfied();
|
||||
$httpBackend.flush();
|
||||
|
||||
expect(controller.getMailStates).toHaveBeenCalledWith(controller.date);
|
||||
expect(controller.getWeekData).toHaveBeenCalled();
|
||||
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('isUnsatisfied() ', () => {
|
||||
it(`should throw an error is reason is empty`, () => {
|
||||
let error;
|
||||
try {
|
||||
controller.isUnsatisfied();
|
||||
} catch (e) {
|
||||
error = e;
|
||||
}
|
||||
|
||||
expect(error).toBeDefined();
|
||||
expect(error.message).toBe(`You must indicate a reason`);
|
||||
});
|
||||
|
||||
it(`should make a query an then call three methods`, () => {
|
||||
const today = Date.vnNew();
|
||||
jest.spyOn(controller, 'getWeekData').mockReturnThis();
|
||||
jest.spyOn(controller, 'getMailStates').mockReturnThis();
|
||||
jest.spyOn(controller.vnApp, 'showSuccess');
|
||||
|
||||
controller.$.model = {applyFilter: jest.fn().mockReturnValue(Promise.resolve())};
|
||||
controller.worker = {id: 1};
|
||||
controller.date = today;
|
||||
controller.weekNumber = 1;
|
||||
controller.reason = 'reason';
|
||||
|
||||
$httpBackend.expect('POST', 'WorkerTimeControls/updateWorkerTimeControlMail').respond();
|
||||
controller.isSatisfied();
|
||||
$httpBackend.flush();
|
||||
|
||||
expect(controller.getMailStates).toHaveBeenCalledWith(controller.date);
|
||||
expect(controller.getWeekData).toHaveBeenCalled();
|
||||
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('resendEmail() ', () => {
|
||||
it(`should make a query an then call showSuccess method`, () => {
|
||||
const today = Date.vnNew();
|
||||
jest.spyOn(controller, 'getWeekData').mockReturnThis();
|
||||
jest.spyOn(controller.vnApp, 'showSuccess');
|
||||
|
||||
controller.$.model = {applyFilter: jest.fn().mockReturnValue(Promise.resolve())};
|
||||
controller.worker = {id: 1};
|
||||
controller.worker = {user: {emailUser: {email: 'employee@verdnatura.es'}}};
|
||||
controller.date = today;
|
||||
controller.weekNumber = 1;
|
||||
|
||||
$httpBackend.expect('POST', 'WorkerTimeControls/weekly-hour-hecord-email').respond();
|
||||
controller.resendEmail();
|
||||
$httpBackend.flush();
|
||||
|
||||
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('getMailStates() ', () => {
|
||||
it(`should make a query an then call showSuccess method`, () => {
|
||||
const today = Date.vnNew();
|
||||
jest.spyOn(controller, 'repaint').mockReturnThis();
|
||||
|
||||
controller.$params = {id: 1};
|
||||
|
||||
$httpBackend.expect('GET', `WorkerTimeControls/1/getMailStates?month=1&year=2001`).respond();
|
||||
controller.getMailStates(today);
|
||||
$httpBackend.flush();
|
||||
|
||||
expect(controller.repaint).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue