70 lines
2.5 KiB
JavaScript
70 lines
2.5 KiB
JavaScript
import './index';
|
|
|
|
describe('Ticket', () => {
|
|
describe('Component vnTicketSms', () => {
|
|
let controller;
|
|
let $httpBackend;
|
|
let $element;
|
|
|
|
beforeEach(ngModule('ticket'));
|
|
|
|
beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_) => {
|
|
$httpBackend = _$httpBackend_;
|
|
let $scope = $rootScope.$new();
|
|
$element = angular.element('<vn-dialog></vn-dialog>');
|
|
controller = $componentController('vnTicketSms', {$element, $scope});
|
|
controller.$params = {id: 11};
|
|
}));
|
|
|
|
describe('onResponse()', () => {
|
|
it('should perform a POST query and show a success snackbar', () => {
|
|
let params = {destinationFk: 101, destination: 111111111, message: 'My SMS'};
|
|
controller.sms = {destinationFk: 101, destination: 111111111, message: 'My SMS'};
|
|
|
|
spyOn(controller.vnApp, 'showMessage');
|
|
$httpBackend.expect('POST', `Tickets/11/sendSms`, params).respond(200, params);
|
|
|
|
controller.onResponse('accept');
|
|
$httpBackend.flush();
|
|
|
|
expect(controller.vnApp.showMessage).toHaveBeenCalledWith('SMS sent!');
|
|
});
|
|
|
|
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`);
|
|
});
|
|
});
|
|
|
|
describe('charactersRemaining()', () => {
|
|
it('should return the characters remaining in a element', () => {
|
|
controller.$scope.message = {
|
|
input: {
|
|
textLength: 50
|
|
},
|
|
maxlength: 150
|
|
};
|
|
|
|
let result = controller.charactersRemaining();
|
|
|
|
expect(result).toEqual(100);
|
|
});
|
|
});
|
|
});
|
|
});
|