import './index';

describe('vnRouteDescriptorPopover', () => {
    let controller;
    let $httpBackend;

    beforeEach(ngModule('route'));

    beforeEach(inject(($componentController, _$httpBackend_) => {
        $httpBackend = _$httpBackend_;
        controller = $componentController('vnRouteDescriptor', {$element: null});
    }));

    describe('loadData()', () => {
        it(`should perform a get query to store the client data into the controller`, () => {
            const id = 1;
            const response = 'foo';

            $httpBackend.expectRoute('GET', `Routes/${id}`).respond(response);
            controller.id = id;
            $httpBackend.flush();

            expect(controller.route).toEqual(response);
        });
    });

    describe('deleteCurrentRoute()', () => {
        it(`should perform a delete query to delete the current route`, () => {
            const id = 1;

            jest.spyOn(controller.vnApp, 'showSuccess');

            controller._id = id;
            $httpBackend.expectDELETE(`Routes/${id}`).respond(200);
            controller.deleteCurrentRoute();
            $httpBackend.flush();

            expect(controller.route).toBeUndefined();
            expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Route deleted');
        });
    });
});