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

51 lines
1.7 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', () => {
2020-02-25 09:39:21 +00:00
it('should check if value.id is defined', () => {
2020-02-26 12:22:52 +00:00
jest.spyOn(controller, 'getEntryData');
2020-02-25 09:39:21 +00:00
2020-02-21 11:48:34 +00:00
controller.entry = {id: 1};
2020-02-04 08:34:31 +00:00
2020-02-25 09:39:21 +00:00
expect(controller.getEntryData).toHaveBeenCalledWith();
2020-02-04 08:34:31 +00:00
});
2020-02-25 09:39:21 +00:00
it('should return the entry and then call getEntryData()', () => {
2020-02-26 12:22:52 +00:00
jest.spyOn(controller, 'getEntryData');
2020-02-21 11:48:34 +00:00
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);
2020-02-25 09:39:21 +00:00
expect(controller.getEntryData).toHaveBeenCalledWith();
2020-02-04 08:34:31 +00:00
});
});
2020-02-25 09:39:21 +00:00
describe('getEntryData()', () => {
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');
2020-02-25 09:39:21 +00:00
controller.getEntryData();
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
});
});
});