Tarea #505 /summary/index.js Front unit test
This commit is contained in:
parent
6f8fa86786
commit
86805769fe
|
@ -0,0 +1,41 @@
|
|||
import './index.js';
|
||||
|
||||
describe('Item', () => {
|
||||
describe('Component summary', () => {
|
||||
let $componentController;
|
||||
let controller;
|
||||
let $httpBackend;
|
||||
|
||||
beforeEach(() => {
|
||||
angular.mock.module('item');
|
||||
});
|
||||
|
||||
beforeEach(angular.mock.inject((_$componentController_, _$httpBackend_) => {
|
||||
$componentController = _$componentController_;
|
||||
$httpBackend = _$httpBackend_;
|
||||
$httpBackend.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({});
|
||||
controller = $componentController('vnItemSummary');
|
||||
controller.item = {id: 1};
|
||||
}));
|
||||
|
||||
describe('getSummary()', () => {
|
||||
it("should perform a query to set summary", () => {
|
||||
$httpBackend.when('GET', `/item/api/Items/1/getSummary`).respond(200, 24);
|
||||
$httpBackend.expect('GET', `/item/api/Items/1/getSummary`);
|
||||
controller.getSummary();
|
||||
$httpBackend.flush();
|
||||
|
||||
expect(controller.summary).toEqual(24);
|
||||
});
|
||||
});
|
||||
|
||||
describe('$onChanges()', () => {
|
||||
it("should call getSummary when item.id is defined", () => {
|
||||
spyOn(controller, 'getSummary');
|
||||
controller.$onChanges();
|
||||
|
||||
expect(controller.getSummary).toHaveBeenCalledWith();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue