salix/modules/client/front/sms/index.spec.js

75 lines
2.6 KiB
JavaScript
Raw Normal View History

import './index';
describe('Client', () => {
describe('Component vnClientSms', () => {
let controller;
let $httpBackend;
let $element;
beforeEach(ngModule('client'));
2020-01-14 08:10:54 +00:00
beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_) => {
$httpBackend = _$httpBackend_;
2020-01-14 08:10:54 +00:00
let $scope = $rootScope.$new();
$element = angular.element('<vn-dialog></vn-dialog>');
2020-01-14 08:10:54 +00:00
controller = $componentController('vnClientSms', {$element, $scope});
controller.client = {id: 101};
2020-01-16 11:40:28 +00:00
controller.$params = {id: 101};
2020-02-14 11:01:17 +00:00
controller.$scope.message = {
input: {
value: 'My SMS'
}
};
}));
describe('onResponse()', () => {
it('should perform a POST query and show a success snackbar', () => {
2019-04-16 06:21:20 +00:00
let params = {destinationFk: 101, destination: 111111111, message: 'My SMS'};
controller.sms = {destinationFk: 101, destination: 111111111, message: 'My SMS'};
spyOn(controller.vnApp, 'showMessage');
2020-01-16 11:40:28 +00:00
$httpBackend.expect('POST', `Clients/101/sendSms`, params).respond(200, params);
2019-10-30 15:57:14 +00:00
controller.onResponse('accept');
$httpBackend.flush();
expect(controller.vnApp.showMessage).toHaveBeenCalledWith('SMS sent!');
});
2020-02-10 12:22:43 +00:00
it('should call onResponse without the destination and show an error snackbar', () => {
controller.sms = {destinationFk: 101, message: 'My SMS'};
spyOn(controller.vnApp, 'showError');
controller.onResponse('accept');
expect(controller.vnApp.showError).toHaveBeenCalledWith(`The destination can't be empty`);
});
it('should call onResponse without the message and show an error snackbar', () => {
controller.sms = {destinationFk: 101, destination: 222222222};
spyOn(controller.vnApp, 'showError');
controller.onResponse('accept');
expect(controller.vnApp.showError).toHaveBeenCalledWith(`The message can't be empty`);
});
});
2020-01-14 08:10:54 +00:00
describe('charactersRemaining()', () => {
it('should return the characters remaining in a element', () => {
controller.$scope.message = {
input: {
2020-02-14 11:01:17 +00:00
value: 'My message 0€'
}
2020-01-14 08:10:54 +00:00
};
let result = controller.charactersRemaining();
2020-02-14 11:01:17 +00:00
expect(result).toEqual(145);
2020-01-14 08:10:54 +00:00
});
});
});
});