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

185 lines
6.3 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', () => {
2019-11-06 08:32:54 +00:00
let $httpParamSerializer;
2018-07-31 09:08:22 +00:00
let $scope;
2019-11-11 10:23:39 +00:00
let $element;
2018-07-31 09:08:22 +00:00
let $httpBackend;
let $state;
let controller;
beforeEach(ngModule('client'));
2018-07-31 09:08:22 +00:00
2019-11-06 08:32:54 +00:00
beforeEach(angular.mock.inject(($componentController, _$httpBackend_, $rootScope, _$state_, _$httpParamSerializer_) => {
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_;
2019-11-06 08:32:54 +00:00
$httpParamSerializer = _$httpParamSerializer_;
2019-11-11 10:23:39 +00:00
$element = angular.element('<vn-client-sample-create></vn-client-sample-create>');
controller = $componentController('vnClientSampleCreate', {$element, $scope});
2018-07-31 09:08:22 +00:00
}));
2019-11-06 09:55:04 +00:00
describe('showPreview()', () => {
2018-07-31 09:08:22 +00:00
it(`should perform a query (GET) and open a sample preview`, () => {
2019-11-11 10:23:39 +00:00
spyOn(controller.$.showPreview, 'show');
2019-11-06 09:55:04 +00:00
const element = document.createElement('div');
document.body.querySelector = () => {
return {
querySelector: () => {
return element;
}
};
};
2018-07-31 09:08:22 +00:00
2019-11-11 10:23:39 +00:00
controller.$.sampleType.selection = {
2018-07-31 09:08:22 +00:00
hasCompany: false,
code: 'MyReport'
};
controller.clientSample = {
clientFk: 101
2018-07-31 09:08:22 +00:00
};
let event = {preventDefault: () => {}};
2019-11-06 08:32:54 +00:00
const params = {
clientId: 101,
isPreview: true
};
const serializedParams = $httpParamSerializer(params);
$httpBackend.when('GET', `email/MyReport?${serializedParams}`).respond(true);
$httpBackend.expect('GET', `email/MyReport?${serializedParams}`);
2018-07-31 09:08:22 +00:00
controller.showPreview(event);
$httpBackend.flush();
2019-11-11 10:23:39 +00:00
expect(controller.$.showPreview.show).toHaveBeenCalledWith();
2018-07-31 09:08:22 +00:00
});
it(`should perform a query (GET) with companyFk param and open a sample preview`, () => {
2019-11-11 10:23:39 +00:00
spyOn(controller.$.showPreview, 'show');
2019-11-06 09:55:04 +00:00
const element = document.createElement('div');
document.body.querySelector = () => {
return {
querySelector: () => {
return element;
}
};
};
2018-07-31 09:08:22 +00:00
2019-11-11 10:23:39 +00:00
controller.$.sampleType.selection = {
2018-07-31 09:08:22 +00:00
hasCompany: true,
code: 'MyReport'
};
controller.clientSample = {
clientFk: 101,
companyFk: 442
2018-07-31 09:08:22 +00:00
};
let event = {preventDefault: () => {}};
2019-11-06 08:32:54 +00:00
const params = {
clientId: 101,
companyId: 442,
isPreview: true
};
const serializedParams = $httpParamSerializer(params);
$httpBackend.when('GET', `email/MyReport?${serializedParams}`).respond(true);
$httpBackend.expect('GET', `email/MyReport?${serializedParams}`);
2018-07-31 09:08:22 +00:00
controller.showPreview(event);
$httpBackend.flush();
2019-11-11 10:23:39 +00:00
expect(controller.$.showPreview.show).toHaveBeenCalledWith();
2018-07-31 09:08:22 +00:00
});
});
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');
2019-11-11 10:23:39 +00:00
controller.$.sampleType.selection = {
2018-07-31 09:08:22 +00:00
hasCompany: false,
code: 'MyReport'
};
controller.clientSample = {
clientFk: 101
2018-07-31 09:08:22 +00:00
};
2019-11-06 08:32:54 +00:00
const params = {
clientId: 101
};
const serializedParams = $httpParamSerializer(params);
$httpBackend.when('GET', `email/MyReport?${serializedParams}`).respond(true);
$httpBackend.expect('GET', `email/MyReport?${serializedParams}`);
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');
2019-11-11 10:23:39 +00:00
controller.$.sampleType.selection = {
2018-07-31 09:08:22 +00:00
hasCompany: true,
code: 'MyReport'
};
controller.clientSample = {
clientFk: 101,
companyFk: 442
2018-07-31 09:08:22 +00:00
};
2019-11-06 08:32:54 +00:00
const params = {
clientId: 101,
companyId: 442
};
const serializedParams = $httpParamSerializer(params);
$httpBackend.when('GET', `email/MyReport?${serializedParams}`).respond(true);
$httpBackend.expect('GET', `email/MyReport?${serializedParams}`);
2018-07-31 09:08:22 +00:00
controller.sendSample();
$httpBackend.flush();
expect(controller.$state.go).toHaveBeenCalledWith('client.card.sample.index');
});
});
});
});