salix/modules/client/front/sample/create/index.spec.js

159 lines
5.5 KiB
JavaScript
Raw Normal View History

2018-07-31 09:08:22 +00:00
import './index';
2019-01-30 07:28:09 +00:00
describe('Client', () => {
2018-07-31 09:08:22 +00:00
describe('Component vnClientSampleCreate', () => {
let $scope;
let $httpBackend;
let $state;
let controller;
2019-09-13 14:09:14 +00:00
beforeEach(angular.mock.module('client', $translateProvider => {
$translateProvider.translations('en', {});
}));
2018-07-31 09:08:22 +00:00
beforeEach(angular.mock.inject(($componentController, _$httpBackend_, $rootScope, _$state_) => {
2018-07-31 09:08:22 +00:00
$scope = $rootScope.$new();
$scope.sampleType = {};
$scope.watcher = {
check: () => {},
realSubmit: () => {
return {
then: callback => {
callback();
}
};
}
};
$scope.showPreview = {
element: {
querySelector: () => {
return {
innerHTML: () => {}
};
}
},
show: () => {}
};
$state = _$state_;
$state.params.id = 101;
$httpBackend = _$httpBackend_;
controller = $componentController('vnClientSampleCreate', {$scope, $state});
2018-07-31 09:08:22 +00:00
}));
describe('jsonToQuery()', () => {
it(`should convert a JSON object with clientFk property to query params`, () => {
let myObject = {clientFk: 101};
let result = controller.jsonToQuery(myObject);
expect(result).toEqual('clientFk=101');
});
it(`should convert a JSON object with clientFk and companyFk properties to query params`, () => {
let myObject = {clientFk: 101, companyFk: 442};
let result = controller.jsonToQuery(myObject);
expect(result).toEqual('clientFk=101&companyFk=442');
});
});
2018-07-31 09:08:22 +00:00
describe('showPreview()', () => {
it(`should perform a query (GET) and open a sample preview`, () => {
spyOn(controller.$scope.showPreview, 'show');
controller.$scope.sampleType.selection = {
hasCompany: false,
code: 'MyReport'
};
controller.clientSample = {
clientFk: 101
2018-07-31 09:08:22 +00:00
};
let event = {preventDefault: () => {}};
$httpBackend.when('GET', `/api/email/MyReport?clientFk=101`).respond(true);
$httpBackend.expect('GET', `/api/email/MyReport?clientFk=101`);
2018-07-31 09:08:22 +00:00
controller.showPreview(event);
$httpBackend.flush();
expect(controller.$scope.showPreview.show).toHaveBeenCalledWith();
});
it(`should perform a query (GET) with companyFk param and open a sample preview`, () => {
spyOn(controller.$scope.showPreview, 'show');
controller.$scope.sampleType.selection = {
hasCompany: true,
code: 'MyReport'
};
controller.clientSample = {
clientFk: 101,
companyFk: 442
2018-07-31 09:08:22 +00:00
};
let event = {preventDefault: () => {}};
$httpBackend.when('GET', `/api/email/MyReport?clientFk=101&companyFk=442`).respond(true);
$httpBackend.expect('GET', `/api/email/MyReport?clientFk=101&companyFk=442`);
2018-07-31 09:08:22 +00:00
controller.showPreview(event);
$httpBackend.flush();
expect(controller.$scope.showPreview.show).toHaveBeenCalledWith();
});
});
describe('onSubmit()', () => {
it(`should call sendSample() method`, () => {
spyOn(controller, 'sendSample');
controller.onSubmit();
expect(controller.sendSample).toHaveBeenCalledWith();
});
});
describe('sendSample()', () => {
it(`should perform a query (GET) and call go() method`, () => {
spyOn(controller.$state, 'go');
controller.$scope.sampleType.selection = {
hasCompany: false,
code: 'MyReport'
};
controller.clientSample = {
clientFk: 101
2018-07-31 09:08:22 +00:00
};
$httpBackend.when('POST', `/api/email/MyReport?clientFk=101`).respond(true);
$httpBackend.expect('POST', `/api/email/MyReport?clientFk=101`);
2018-07-31 09:08:22 +00:00
controller.sendSample();
$httpBackend.flush();
expect(controller.$state.go).toHaveBeenCalledWith('client.card.sample.index');
});
it(`should perform a query (GET) with companyFk param and call go() method`, () => {
spyOn(controller.$state, 'go');
controller.$scope.sampleType.selection = {
hasCompany: true,
code: 'MyReport'
};
controller.clientSample = {
clientFk: 101,
companyFk: 442
2018-07-31 09:08:22 +00:00
};
$httpBackend.when('POST', `/api/email/MyReport?clientFk=101&companyFk=442`).respond(true);
$httpBackend.expect('POST', `/api/email/MyReport?clientFk=101&companyFk=442`);
2018-07-31 09:08:22 +00:00
controller.sendSample();
$httpBackend.flush();
expect(controller.$state.go).toHaveBeenCalledWith('client.card.sample.index');
});
});
});
});