import './index';

describe('component vnEntrySummary', () => {
    let controller;
    let $httpBackend;
    let $scope;

    beforeEach(angular.mock.module('entry', $translateProvider => {
        $translateProvider.translations('en', {});
    }));

    beforeEach(inject(($componentController, $rootScope, _$httpBackend_, _$httpParamSerializer_) => {
        $httpBackend = _$httpBackend_;
        $scope = $rootScope.$new();
        const $element = angular.element(`<vn-entry-summary></vn-entry-summary>`);
        controller = $componentController('vnEntrySummary', {$element, $scope});
    }));

    describe('entry setter/getter', () => {
        it('should check if value.id is defined', () => {
            jest.spyOn(controller, 'getEntryData');

            controller.entry = {id: 1};

            expect(controller.getEntryData).toHaveBeenCalledWith();
        });

        it('should return the entry and then call getEntryData()', () => {
            jest.spyOn(controller, 'getEntryData');
            controller.entry = {id: 99};

            expect(controller._entry.id).toEqual(99);
            expect(controller.getEntryData).toHaveBeenCalledWith();
        });
    });

    describe('getEntryData()', () => {
        it('should perform a get and then store data on the controller', () => {
            controller._entry = {id: 999};

            const query = `Entries/${controller._entry.id}/getEntry`;
            $httpBackend.expectGET(query).respond('I am the entryData');
            controller.getEntryData();
            $httpBackend.flush();

            expect(controller.entryData).toEqual('I am the entryData');
        });
    });
});