<commit_before>'use strict';
import app from '../../app';

describe('Board controller', () => {
    // let BoardCtrl;
    let stubBoardService;
    let sandbox;
    let deferred;
    let BoardCtrl;
    let $scope;
    let res = {
        data: [
            {
                name: 'test',
                href: 'test.com',
                description: 'Lorem ipsum',
                complaintFrom: 'test2.com',
            }
        ]
    };


    beforeEach(() => {
        sandbox = sinon.sandbox.create();
        angular.mock.module(app);
        angular.mock.inject(($controller, $q, _$rootScope_) => {
            deferred = $q.defer();
            stubBoardService = sandbox.stub({
                getAllScammers: () => {
                }
            });

            stubBoardService.getAllScammers.returns(deferred.promise);

            $scope = _$rootScope_.$new();

            BoardCtrl = $controller('BoardCtrl', {
                boardService: stubBoardService,
            });
        });
    });




    afterEach(function() {
        sandbox.restore();
    });

    it('should have right title', () => {
        expect(BoardCtrl).to.be.an('object');
        expect(BoardCtrl.title).to.be.a('string');
        expect(BoardCtrl.title).to.equal('BoardOfShame Список мошенников');
    });

    describe('activate() method', () => {
        it('should use BoardService', (done) => {

            BoardCtrl.activate().then((data) => {
                expect(data).to.deep.equal(res.data);
                done();
            });

            deferred.resolve(res);
            $scope.$apply();

        });

        it('should return scammers data if promise successful', (done) => {

            BoardCtrl.activate().then((data) => {
                expect(data).to.deep.equal(res.data);
                done();
            });

            deferred.resolve(res);
            $scope.$apply();
        });

        it('should return false data if promise rejected', (done) => {

            BoardCtrl.activate().then((data) => {
                expect(data).to.be.false;
                done();
            });

            deferred.reject(res);
            $scope.$apply();
        });

        it('should call console.error if promise rejected', (done) => {

            sandbox.spy(console, 'error');<commit_msg>Improved BoardCtrl unit tests<commit_after>'use strict';
import app from '../../app';

describe('Board controller', () => {
    // let BoardCtrl;
    let stubBoardService;
    let stubMetaDataService;
    let stubMenuService;
    let sandbox;
    let deferred;
    let BoardCtrl;
    let $scope;
    let res = {
        data: [
            {
                name: 'test',
                href: 'test.com',
                description: 'Lorem ipsum',
                complaintFrom: 'test2.com',
            }
        ]
    };
    let pageTitle = 'BoardOfShame Список мошенников';


    beforeEach(() => {
        sandbox = sinon.sandbox.create();
        angular.mock.module(app);
        angular.mock.inject(($controller, $q, _$rootScope_) => {
            deferred = $q.defer();

            stubBoardService = sandbox.stub({
                getAllScammers: () => {
                }
            });

            stubBoardService.getAllScammers.returns(deferred.promise);


            stubMetaDataService = sandbox.stub({
                setPageTitle: () => {
                }
            });

            stubMenuService = sandbox.stub({
                setActiveItem: () => {
                }
            });

            $scope = _$rootScope_.$new();

            BoardCtrl = $controller('BoardCtrl', {
                metaDataService: stubMetaDataService,
                menuService: stubMenuService,
                boardService: stubBoardService,
            });
        });
    });




    afterEach(function() {
        sandbox.restore();
    });

    it('should have right title', () => {
        expect(BoardCtrl).to.be.an('object');
        expect(BoardCtrl.title).to.be.a('string');
        expect(BoardCtrl.title).to.equal(pageTitle);
    });


    it('should use menuService and send proper args to it', (done) => {

        BoardCtrl.activate();
        expect(stubMenuService.setActiveItem.calledWith('/')).to.be.true;
        done();

    });

    it('should use metaDataService and send proper args to it', (done) => {

        BoardCtrl.activate();
        expect(stubMetaDataService.setPageTitle.calledWith(pageTitle)).to.be.true;
        done();

    });

    describe('activate() method', () => {
        it('should use boardService', (done) => {

            BoardCtrl.activate();
            expect(stubBoardService.getAllScammers.called).to.be.true;
            done();

        });

        it('should return scammers data if promise successful', (done) => {

            BoardCtrl.activate().then((data) => {
                expect(data).to.deep.equal(res.data);
                done();
            });

            deferred.resolve(res);
            $scope.$apply();
        });

        it('should return false data if promise rejected', (done) => {

            BoardCtrl.activate().then((data) => {
                expect(data).to.be.false;
                done();
            });

            deferred.reject(res);
            $scope.$apply();
        });

        it('should call console.error if promise rejected', (done) => {

            sandbox.spy(console, 'error');
{'fraction_non_alphanumeric': 0.14729680029422582, 'fraction_numerical': 0.0003677822728944465, 'mean_word_length': 1.6048850574712643, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 32, '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': '5617329', 'n_tokens_mistral': 1528, 'n_tokens_neox': 1455, 'n_words': 259}