2020-01-15 12:27:14 +00:00
|
|
|
import './index';
|
|
|
|
|
2020-01-16 11:40:28 +00:00
|
|
|
describe('Ticket', () => {
|
|
|
|
describe('Component vnTicketSms', () => {
|
2020-01-15 12:27:14 +00:00
|
|
|
let controller;
|
|
|
|
let $httpBackend;
|
|
|
|
|
2020-01-16 11:40:28 +00:00
|
|
|
beforeEach(ngModule('ticket'));
|
2020-01-15 12:27:14 +00:00
|
|
|
|
2020-07-23 14:46:16 +00:00
|
|
|
beforeEach(inject(($componentController, $rootScope, _$httpBackend_) => {
|
2020-01-15 12:27:14 +00:00
|
|
|
$httpBackend = _$httpBackend_;
|
|
|
|
let $scope = $rootScope.$new();
|
2020-03-18 07:35:59 +00:00
|
|
|
const $element = angular.element('<vn-dialog></vn-dialog>');
|
2020-01-16 11:40:28 +00:00
|
|
|
controller = $componentController('vnTicketSms', {$element, $scope});
|
|
|
|
controller.$params = {id: 11};
|
2020-03-18 07:35:59 +00:00
|
|
|
controller.$.message = {
|
2020-02-14 11:01:17 +00:00
|
|
|
input: {
|
|
|
|
value: 'My SMS'
|
|
|
|
}
|
|
|
|
};
|
2020-01-15 12:27:14 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
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'};
|
|
|
|
|
2020-02-26 12:22:52 +00:00
|
|
|
jest.spyOn(controller.vnApp, 'showMessage');
|
2020-01-16 11:40:28 +00:00
|
|
|
$httpBackend.expect('POST', `Tickets/11/sendSms`, params).respond(200, params);
|
2020-01-15 12:27: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'};
|
|
|
|
|
2020-02-26 12:22:52 +00:00
|
|
|
jest.spyOn(controller.vnApp, 'showError');
|
2020-02-10 12:22:43 +00:00
|
|
|
|
|
|
|
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};
|
|
|
|
|
2020-02-26 12:22:52 +00:00
|
|
|
jest.spyOn(controller.vnApp, 'showError');
|
2020-02-10 12:22:43 +00:00
|
|
|
|
|
|
|
controller.onResponse('accept');
|
|
|
|
|
|
|
|
expect(controller.vnApp.showError).toHaveBeenCalledWith(`The message can't be empty`);
|
|
|
|
});
|
2020-01-15 12:27:14 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('charactersRemaining()', () => {
|
|
|
|
it('should return the characters remaining in a element', () => {
|
2020-03-18 07:35:59 +00:00
|
|
|
controller.$.message = {
|
2020-01-15 12:27:14 +00:00
|
|
|
input: {
|
2020-02-14 11:01:17 +00:00
|
|
|
value: 'My message 0€'
|
|
|
|
}
|
2020-01-15 12:27:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
let result = controller.charactersRemaining();
|
|
|
|
|
2020-02-14 11:01:17 +00:00
|
|
|
expect(result).toEqual(145);
|
2020-01-15 12:27:14 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|