{"size": 1366, "ext": "js", "max_stars_repo_path": "src/test/resources/js/home/navbarControllerSpec.js", "max_stars_repo_name": "pivotal-legacy/sputnik", "max_stars_repo_stars_event_min_datetime": "2015-03-17T03:47:31.000Z", "max_stars_repo_stars_event_max_datetime": "2015-03-17T03:47:31.000Z", "max_issues_repo_path": "src/test/resources/js/home/navbarControllerSpec.js", "max_issues_repo_name": "pivotal/sputnik", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/test/resources/js/home/navbarControllerSpec.js", "max_forks_repo_name": "pivotal/sputnik", "max_forks_repo_forks_event_min_datetime": "2018-08-12T18:00:09.000Z", "max_forks_repo_forks_event_max_datetime": "2018-08-12T18:00:09.000Z"}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": 1, "avg_line_length": 30.3555555556, "max_line_length": 93, "alphanum_fraction": 0.5775988287}
describe('navbarController', function () {
    var $scope, profileRepository, profileDeferred, signoutDeferred, $http, $window;

    beforeEach(module('navbar'));

    beforeEach(inject(function ($rootScope, $q, _$http_, $controller, _profileRepository_) {
        $scope = $rootScope.$new();
        $http = _$http_;
        $window = {location: {}};
        profileRepository = _profileRepository_;

        profileDeferred = $q.defer();
        signoutDeferred = $q.defer();

        spyOn(profileRepository, "get").and.returnValue({$promise: profileDeferred.promise});
        spyOn($http, "post").and.returnValue(signoutDeferred.promise);

        $controller('navbarController', {
            $scope: $scope,
            $http: $http,
            $window: $window,
            profileRepository: profileRepository
        });
    }));

    it('sets profile', function () {
        profileDeferred.resolve("profile");

        $scope.$apply();
        expect($scope.profile).toEqual("profile");
    });

    describe('signout', function () {
        it('signs the user out and redirects the user', function () {
            $scope.signout();

            expect($http.post).toHaveBeenCalledWith('/signout', {});

            signoutDeferred.resolve();
            $scope.$apply();

            expect($window.location.href).toEqual('/');
        });
    });
});