salix/client/client/src/sample/create/index.spec.js

150 lines
5.1 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 $componentController;
let $scope;
let $httpBackend;
let $state;
let controller;
beforeEach(() => {
angular.mock.module('client');
});
beforeEach(angular.mock.inject((_$componentController_, _$httpBackend_, $rootScope, _$state_) => {
$componentController = _$componentController_;
$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_;
$httpBackend.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({});
controller = $componentController('vnClientSampleCreate', {$scope: $scope}, {$state: $state});
}));
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');
});
});
});
});