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

145 lines
4.9 KiB
JavaScript
Raw Normal View History

2018-07-31 09:08:22 +00:00
import './index';
describe('Client', () => {
2018-07-31 09:08:22 +00:00
describe('Component vnClientSampleCreate', () => {
let $scope;
let $httpBackend;
let $state;
let controller;
beforeEach(ngModule('client'));
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('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,
typeFK: 1
};
let event = {preventDefault: () => {}};
$httpBackend.whenGET(`/mailer/notification/MyReport/101/preview`).respond(true);
$httpBackend.expectGET(`/mailer/notification/MyReport/101/preview`);
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,
typeFK: 1
};
let event = {preventDefault: () => {}};
$httpBackend.whenGET(`/mailer/notification/MyReport/442/101/preview`).respond(true);
$httpBackend.expectGET(`/mailer/notification/MyReport/442/101/preview`);
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,
typeFK: 1
};
$httpBackend.whenGET(`/mailer/notification/MyReport/101`).respond(true);
$httpBackend.expectGET(`/mailer/notification/MyReport/101`);
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,
typeFK: 1
};
$httpBackend.whenGET(`/mailer/notification/MyReport/442/101`).respond(true);
$httpBackend.expectGET(`/mailer/notification/MyReport/442/101`);
controller.sendSample();
$httpBackend.flush();
expect(controller.$state.go).toHaveBeenCalledWith('client.card.sample.index');
});
});
});
});