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