unit test for notes and index plus small refactor on notes.js
This commit is contained in:
parent
fd39993794
commit
a732d796e8
|
@ -7,7 +7,7 @@ describe('Component vnClientIndex', () => {
|
|||
angular.mock.module('client');
|
||||
});
|
||||
|
||||
beforeEach(angular.mock.inject(function(_$componentController_, $rootScope, _$httpBackend_) {
|
||||
beforeEach(angular.mock.inject(function(_$componentController_) {
|
||||
$componentController = _$componentController_;
|
||||
}));
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ export default class Controller {
|
|||
this.$http = $http;
|
||||
this.$state = $state;
|
||||
}
|
||||
$onChanges(changes) {
|
||||
$onChanges() {
|
||||
if (this.client) {
|
||||
this.getObservation(this.client.id);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
import './notes.js';
|
||||
|
||||
describe('Component vnClientNotes', () => {
|
||||
let $componentController;
|
||||
let $state;
|
||||
let $httpBackend;
|
||||
|
||||
beforeEach(() => {
|
||||
angular.mock.module('client');
|
||||
});
|
||||
|
||||
beforeEach(angular.mock.inject(function(_$componentController_, _$state_, _$httpBackend_) {
|
||||
$componentController = _$componentController_;
|
||||
$state = _$state_;
|
||||
$httpBackend = _$httpBackend_;
|
||||
}));
|
||||
|
||||
describe('$onChanges()', () => {
|
||||
it(`should call getObservation() with the client id`, () => {
|
||||
let controller = $componentController('vnClientNotes', {$httpBackend: $httpBackend, $state: $state});
|
||||
controller.client = {
|
||||
id: 1234
|
||||
};
|
||||
spyOn(controller, 'getObservation').and.returnValue();
|
||||
controller.$onChanges();
|
||||
expect(controller.getObservation).toHaveBeenCalledWith(1234);
|
||||
});
|
||||
});
|
||||
|
||||
describe('$getObservation()', () => {
|
||||
it(`should request to GET the client notes`, () => {
|
||||
let controller = $componentController('vnClientNotes', {$httpBackend: $httpBackend, $state: $state});
|
||||
controller.client = {id: '1234'};
|
||||
let json = JSON.stringify({where: {clientFk: '1234'}, order: 'created DESC'});
|
||||
$httpBackend.when('GET', `/client/api/clientObservations?filter=${json}`).respond('ok');
|
||||
$httpBackend.expectGET(`/client/api/clientObservations?filter=${json}`, {Accept: 'application/json, text/plain, */*'});
|
||||
controller.getObservation();
|
||||
$httpBackend.flush();
|
||||
});
|
||||
});
|
||||
|
||||
describe('$newObservation()', () => {
|
||||
it(`should redirect the user to the newObservation view`, () => {
|
||||
let controller = $componentController('vnClientNotes', {$httpBackend: $httpBackend, $state: $state});
|
||||
controller.client = {id: '1234'};
|
||||
spyOn(controller.$state, 'go');
|
||||
controller.newObservation();
|
||||
expect(controller.$state.go).toHaveBeenCalledWith('clientCard.notes.create', Object({id: '1234'}));
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue