import './index';

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

    let role = {id: 1, name: 'foo'};

    beforeEach(ngModule('account'));

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

    describe('onDelete()', () => {
        it('should delete entity and go to index', () => {
            controller.$state.go = jest.fn();
            jest.spyOn(controller.vnApp, 'showSuccess');

            $httpBackend.expectDELETE('Roles/1').respond();
            controller.onDelete();
            $httpBackend.flush();

            expect(controller.$state.go).toHaveBeenCalledWith('account.role');
            expect(controller.vnApp.showSuccess).toHaveBeenCalled();
        });
    });
});