2022-10-20 13:04:25 +00:00
|
|
|
import './index';
|
|
|
|
|
2022-10-24 06:22:04 +00:00
|
|
|
describe('Route', () => {
|
|
|
|
describe('Component vnRouteSms', () => {
|
2022-10-20 13:04:25 +00:00
|
|
|
let controller;
|
|
|
|
let $httpBackend;
|
|
|
|
|
2022-10-24 06:22:04 +00:00
|
|
|
beforeEach(ngModule('route'));
|
2022-10-20 13:04:25 +00:00
|
|
|
|
|
|
|
beforeEach(inject(($componentController, $rootScope, _$httpBackend_) => {
|
|
|
|
$httpBackend = _$httpBackend_;
|
|
|
|
let $scope = $rootScope.$new();
|
|
|
|
const $element = angular.element('<vn-dialog></vn-dialog>');
|
2022-10-24 06:22:04 +00:00
|
|
|
controller = $componentController('vnRouteSms', {$element, $scope});
|
2022-10-20 13:04:25 +00:00
|
|
|
controller.$.message = {
|
|
|
|
input: {
|
|
|
|
value: 'My SMS'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}));
|
|
|
|
|
|
|
|
describe('onResponse()', () => {
|
|
|
|
it('should perform a POST query and show a success snackbar', () => {
|
2022-10-24 06:22:04 +00:00
|
|
|
let params = {destinationFk: 1101, destination: 111111111, message: 'My SMS'};
|
|
|
|
controller.sms = {destinationFk: 1101, destination: 111111111, message: 'My SMS'};
|
2022-10-20 13:04:25 +00:00
|
|
|
|
|
|
|
jest.spyOn(controller.vnApp, 'showMessage');
|
2022-10-24 06:22:04 +00:00
|
|
|
$httpBackend.expect('POST', `Routes/sendSms`, params).respond(200, params);
|
2022-10-20 13:04:25 +00:00
|
|
|
|
|
|
|
controller.onResponse();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.vnApp.showMessage).toHaveBeenCalledWith('SMS sent!');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should call onResponse without the destination and show an error snackbar', () => {
|
|
|
|
controller.sms = {destinationFk: 1101, message: 'My SMS'};
|
|
|
|
|
|
|
|
jest.spyOn(controller.vnApp, 'showError');
|
|
|
|
|
|
|
|
controller.onResponse();
|
|
|
|
|
|
|
|
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: 1101, destination: 222222222};
|
|
|
|
|
|
|
|
jest.spyOn(controller.vnApp, 'showError');
|
|
|
|
|
|
|
|
controller.onResponse();
|
|
|
|
|
|
|
|
expect(controller.vnApp.showError).toHaveBeenCalledWith(`The message can't be empty`);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('charactersRemaining()', () => {
|
|
|
|
it('should return the characters remaining in a element', () => {
|
|
|
|
controller.$.message = {
|
|
|
|
input: {
|
|
|
|
value: 'My message 0€'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
let result = controller.charactersRemaining();
|
|
|
|
|
|
|
|
expect(result).toEqual(145);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|