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

49 lines
1.6 KiB
JavaScript

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