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

51 lines
1.7 KiB
JavaScript

import './index';
import watcher from 'core/mocks/watcher';
describe('Component vnClientPhones', () => {
let controller;
let $element;
let $scope;
beforeEach(ngModule('client'));
beforeEach(angular.mock.inject(($componentController, $rootScope) => {
$scope = $rootScope.$new();
$element = angular.element('<div></div>');
$scope.watcher = watcher;
$scope.model = {
link: 1,
save: () => {}
};
controller = $componentController('vnClientPhones', {$element, $scope});
controller.card = {reload: () => {}};
}));
describe('setLink()', () => {
it('set the link in the model and refreshes it', () => {
spyOn(controller.$, '$applyAsync');
let value = {id: 106};
controller.setLink(value);
expect(controller.$.$applyAsync).toHaveBeenCalledWith(jasmine.any(Function));
});
});
describe('onSubmit()', () => {
it('should call watcher functions, reload the card and save the model', done => {
spyOn(controller.$.watcher, 'check');
spyOn(controller.$.model, 'save').and.returnValue(Promise.resolve());
spyOn(controller.$.watcher, 'updateOriginalData');
spyOn(controller.$.watcher, 'notifySaved');
spyOn(controller.card, 'reload');
controller.onSubmit();
controller.onSubmit().then(() => {
expect(controller.$.watcher.updateOriginalData).toHaveBeenCalledWith();
expect(controller.$.watcher.notifySaved).toHaveBeenCalledWith();
expect(controller.card.reload).toHaveBeenCalledWith();
done();
}).catch(done.fail);
});
});
});