test front worker.phone
gitea/salix/1858testworkerPhone This commit looks good Details

This commit is contained in:
Bernat Exposito Domenech 2019-12-12 12:23:31 +01:00
parent 8a2eda7c08
commit a87ce44f08
2 changed files with 26 additions and 3 deletions

View File

@ -24,7 +24,7 @@ class Controller {
onSubmit() {
this.$scope.watcher.check();
this.$scope.model.save().then(() => {
return this.$scope.model.save().then(() => {
this.$scope.watcher.updateOriginalData();
this.$scope.watcher.notifySaved();
this.card.reload();

View File

@ -1,4 +1,5 @@
import './index';
import watcher from 'core/mocks/watcher';
describe('Component vnWorkerPhones', () => {
let controller;
@ -8,8 +9,12 @@ describe('Component vnWorkerPhones', () => {
beforeEach(angular.mock.inject(($componentController, $rootScope) => {
let $scope = $rootScope.$new();
controller = $componentController('vnWorkerPhones', $scope);
controller.$scope.model = {link: 1};
controller.$scope.$applyAsync = () => {};
controller.$scope.watcher = watcher;
controller.$scope.model = {
link: 1,
save: () => {}
};
controller.card = {reload: () => {}};
}));
describe('setLink()', () => {
@ -21,4 +26,22 @@ describe('Component vnWorkerPhones', () => {
expect(controller.$scope.$applyAsync).toHaveBeenCalledWith(jasmine.any(Function));
});
});
describe('onSubmit()', () => {
it('should call watcher functions, reload the card and save the model', done => {
spyOn(controller.$scope.watcher, 'check');
spyOn(controller.$scope.model, 'save').and.returnValue(Promise.resolve());
spyOn(controller.$scope.watcher, 'updateOriginalData');
spyOn(controller.$scope.watcher, 'notifySaved');
spyOn(controller.card, 'reload');
controller.onSubmit();
controller.onSubmit().then(() => {
expect(controller.$scope.watcher.updateOriginalData).toHaveBeenCalledWith();
expect(controller.$scope.watcher.notifySaved).toHaveBeenCalledWith();
expect(controller.card.reload).toHaveBeenCalledWith();
done();
}).catch(done.fail);
});
});
});