<commit_before>/*jslint node: true */
'use strict';

describe('rgiNewRefDialogCtrl', function () {
    beforeEach(module('app'));

    var $scope, $rootScope, $timeout, rgiAllowedFileExtensionGuideSrvc, ngDialog, rgiDialogFactory, rgiDocumentSrvc,
        rgiFileUploaderSrvc, rgiIdentitySrvc, rgiIntervieweeSrvc, rgiNotifier, rgiRequestSubmitterSrvc,
        stubs = {}, spies = {}, ANSWER = 'ANSWER', FILE_URL = 'http://domain.com/file.png',
        currentUserBackup, currentUser = {role: 'user-role', _id: 'user-id'};

    beforeEach(inject(
        function (
            $controller,
            _$rootScope_,
            _$timeout_,
            _ngDialog_,
            _rgiAllowedFileExtensionGuideSrvc_,
            _rgiDialogFactory_,
            _rgiDocumentSrvc_,
            _rgiFileUploaderSrvc_,
            _rgiIdentitySrvc_,
            _rgiIntervieweeSrvc_,
            _rgiNotifier_,
            _rgiRequestSubmitterSrvc_
        ) {
            $rootScope = _$rootScope_;
            $timeout = _$timeout_;
            ngDialog = _ngDialog_;
            rgiAllowedFileExtensionGuideSrvc = _rgiAllowedFileExtensionGuideSrvc_;
            rgiDialogFactory = _rgiDialogFactory_;
            rgiDocumentSrvc = _rgiDocumentSrvc_;
            rgiFileUploaderSrvc = _rgiFileUploaderSrvc_;
            rgiIdentitySrvc = _rgiIdentitySrvc_;
            rgiIntervieweeSrvc = _rgiIntervieweeSrvc_;
            rgiNotifier = _rgiNotifier_;
            rgiRequestSubmitterSrvc = _rgiRequestSubmitterSrvc_;

            $scope = $rootScope.$new();
            $scope.$parent.answer = ANSWER;

            stubs.AllowedFileExtensionGuideGetList = sinon.stub(rgiAllowedFileExtensionGuideSrvc, 'getList', function() {
                return ['png'];
            });

            spies.documentSrvcQuery = sinon.spy(function(criteria, callback) {
                callback([]);
            });
            stubs.documentSrvcQuery = sinon.stub(rgiDocumentSrvc, 'query', spies.documentSrvcQuery);

            spies.fileUploaderGet = sinon.spy(function() {
                return {queue: [], filters: []};
            });
            stubs.fileUploaderGet = sinon.stub(rgiFileUploaderSrvc, 'get', spies.fileUploaderGet);

            spies.intervieweeQuery = sinon.spy();
            stubs.intervieweeQuery = sinon.stub(rgiIntervieweeSrvc, 'query', spies.intervieweeQuery);

            currentUserBackup = _.cloneDeep(rgiIdentitySrvc.currentUser);
            rgiIdentitySrvc.currentUser = currentUser;

            $scope.closeThisDialog = sinon.spy();
            $controller('rgiNewRefDialogCtrl', {$scope: $scope});
        }
    ));

    it('loads user documents', function () {
        spies.documentSrvcQuery.withArgs({users: currentUser._id}).called.should.be.equal(true);
    });

    it('resets file upload status', function () {
        $scope.fileUploading.should.be.equal(false);
    });

    it('copies answer from the parent scope', function () {
        $scope.answer_update.should.be.equal(ANSWER);
    });

    it('loads interviewees data', function () {
        spies.intervieweeQuery.called.should.be.equal(true);
    });

    it('initializes file uploader', function() {
        spies.fileUploaderGet.withArgs({isHTML5: true, withCredentials: true, url: 'file-upload'}).called.should.be.equal(true);
    });

    it('sets selected document', function() {
        $scope.selected_doc.should.be.equal('none');
    });

    it('initializes the role options', function() {
        $scope.role_opts.should.deep.equal([
            {text: 'Government', value: 'government'},
            {text: 'CSO', value: 'cso'},
            {text: 'Industry', value: 'industry'},
            {text: 'Expert', value: 'expert'},
            {text: 'Other', value: 'other'}]);<commit_msg>fix the unit test suite for the 'New Reference' dialog controller<commit_after>/*jslint node: true */
'use strict';

describe('rgiNewRefDialogCtrl', function () {
    beforeEach(module('app'));

    var $scope, $rootScope, $timeout, rgiAllowedFileExtensionGuideSrvc, ngDialog, rgiDialogFactory, rgiDocumentSrvc,
        rgiFileUploaderSrvc, rgiIdentitySrvc, rgiIntervieweeSrvc, rgiNotifier, rgiRequestSubmitterSrvc,
        stubs = {}, spies = {}, ANSWER = 'ANSWER', FILE_URL = 'http://domain.com/file.png',
        currentUserBackup, currentUser = {role: 'user-role', _id: 'user-id'};

    beforeEach(inject(
        function (
            $controller,
            _$rootScope_,
            _$timeout_,
            _ngDialog_,
            _rgiAllowedFileExtensionGuideSrvc_,
            _rgiDialogFactory_,
            _rgiDocumentSrvc_,
            _rgiFileUploaderSrvc_,
            _rgiIdentitySrvc_,
            _rgiIntervieweeSrvc_,
            _rgiNotifier_,
            _rgiRequestSubmitterSrvc_
        ) {
            $rootScope = _$rootScope_;
            $timeout = _$timeout_;
            ngDialog = _ngDialog_;
            rgiAllowedFileExtensionGuideSrvc = _rgiAllowedFileExtensionGuideSrvc_;
            rgiDialogFactory = _rgiDialogFactory_;
            rgiDocumentSrvc = _rgiDocumentSrvc_;
            rgiFileUploaderSrvc = _rgiFileUploaderSrvc_;
            rgiIdentitySrvc = _rgiIdentitySrvc_;
            rgiIntervieweeSrvc = _rgiIntervieweeSrvc_;
            rgiNotifier = _rgiNotifier_;
            rgiRequestSubmitterSrvc = _rgiRequestSubmitterSrvc_;

            $scope = $rootScope.$new();
            $scope.$parent.answer = ANSWER;

            stubs.AllowedFileExtensionGuideGetList = sinon.stub(rgiAllowedFileExtensionGuideSrvc, 'getList', function() {
                return ['png'];
            });

            spies.documentSrvcQuery = sinon.spy(function(criteria, callback) {
                callback({data: []});
            });
            stubs.documentSrvcQuery = sinon.stub(rgiDocumentSrvc, 'query', spies.documentSrvcQuery);

            spies.fileUploaderGet = sinon.spy(function() {
                return {queue: [], filters: []};
            });
            stubs.fileUploaderGet = sinon.stub(rgiFileUploaderSrvc, 'get', spies.fileUploaderGet);

            spies.intervieweeQuery = sinon.spy();
            stubs.intervieweeQuery = sinon.stub(rgiIntervieweeSrvc, 'query', spies.intervieweeQuery);

            currentUserBackup = _.cloneDeep(rgiIdentitySrvc.currentUser);
            rgiIdentitySrvc.currentUser = currentUser;

            $scope.closeThisDialog = sinon.spy();
            $controller('rgiNewRefDialogCtrl', {$scope: $scope});
        }
    ));

    it('loads user documents', function () {
        spies.documentSrvcQuery.withArgs({skip: 0, limit: 500, users: currentUser._id}).called.should.be.equal(true);
    });

    it('resets file upload status', function () {
        $scope.fileUploading.should.be.equal(false);
    });

    it('copies answer from the parent scope', function () {
        $scope.answer_update.should.be.equal(ANSWER);
    });

    it('loads interviewees data', function () {
        spies.intervieweeQuery.called.should.be.equal(true);
    });

    it('initializes file uploader', function() {
        spies.fileUploaderGet.withArgs({isHTML5: true, withCredentials: true, url: 'file-upload'}).called.should.be.equal(true);
    });

    it('sets selected document', function() {
        $scope.selected_doc.should.be.equal('none');
    });

    it('initializes the role options', function() {
        $scope.role_opts.should.deep.equal([
            {text: 'Government', value: 'government'},
            {text: 'CSO', value: 'cso'},
            {text: 'Industry', value: 'industry'},
            {text: 'Expert', value: 'expert'},
            {text: 'Other', value: 'other'}]);
{'fraction_non_alphanumeric': 0.12063782512089923, 'fraction_numerical': 0.0007842112142203634, 'mean_word_length': 2.5393154486586496, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2277680', 'n_tokens_mistral': 2428, 'n_tokens_neox': 2297, 'n_words': 367}