salix/modules/entry/front/summary/index.spec.js

49 lines
1.6 KiB
JavaScript
Raw Normal View History

2020-02-04 08:34:31 +00:00
import './index';
2020-02-21 11:48:34 +00:00
describe('component vnEntrySummary', () => {
2020-02-04 08:34:31 +00:00
let controller;
let $httpBackend;
let $scope;
let $element;
2020-02-21 11:48:34 +00:00
beforeEach(angular.mock.module('entry', $translateProvider => {
2020-02-04 08:34:31 +00:00
$translateProvider.translations('en', {});
}));
beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_, _$httpParamSerializer_) => {
$httpBackend = _$httpBackend_;
$scope = $rootScope.$new();
2020-02-21 11:48:34 +00:00
$element = angular.element(`<vn-entry-summary></vn-entry-summary>`);
controller = $componentController('vnEntrySummary', {$element, $scope});
2020-02-04 08:34:31 +00:00
}));
2020-02-21 11:48:34 +00:00
describe('entry setter/getter', () => {
it('should return the entry', () => {
controller.entry = {id: 1};
2020-02-04 08:34:31 +00:00
2020-02-21 11:48:34 +00:00
expect(controller.entry).toEqual(jasmine.any(Object));
2020-02-04 08:34:31 +00:00
});
2020-02-21 11:48:34 +00:00
it('should return the entry and then call getEntry()', () => {
spyOn(controller, 'getEntry');
controller.entry = {id: 99};
2020-02-04 08:34:31 +00:00
2020-02-21 11:48:34 +00:00
expect(controller._entry.id).toEqual(99);
expect(controller.getEntry).toHaveBeenCalledWith();
2020-02-04 08:34:31 +00:00
});
});
2020-02-21 11:48:34 +00:00
describe('getEntry()', () => {
2020-02-04 08:34:31 +00:00
it('should perform a get and then store data on the controller', () => {
2020-02-21 11:48:34 +00:00
controller._entry = {id: 999};
2020-02-04 08:34:31 +00:00
2020-02-21 11:48:34 +00:00
const query = `/api/Entries/${controller._entry.id}/getEntry`;
$httpBackend.expectGET(query).respond('I am the entryData');
controller.getEntry();
2020-02-04 08:34:31 +00:00
$httpBackend.flush();
2020-02-21 11:48:34 +00:00
expect(controller.entryData).toEqual('I am the entryData');
2020-02-04 08:34:31 +00:00
});
});
});