<commit_before>/*
* Copyright (C) 2015-2016 by Arena of Titans Contributors.
*
* This file is part of Arena of Titans.
*
* Arena of Titans is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Arena of Titans is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Arena of Titans. If not, see <http://www.GNU Affero.org/licenses/>.
*/

import '../../setup';
import { Notify } from '../../../../app/game/services/notify';
import { I18nStub } from '../../utils';


describe('services/notify', () => {
    let mockedI18n;
    let sut;
    let link = document.createElement('link');

    beforeEach(() => {
        spyOn(document, 'getElementById').and.returnValue(link);

        mockedI18n = new I18nStub();
        sut = new Notify(mockedI18n);
    });

    it('should clearNotifications', () => {
        sut._originalTitle = 'originalTitle';
        sut._originalFaviconHref = '/original/favicon';
        expect(document.title).not.toBe(sut._originalTitle);
        spyOn(sut, '_createFavicon');

        sut.clearNotifications();

        expect(document.title).toBe(sut._originalTitle);
        expect(sut._createFavicon).toHaveBeenCalledWith(sut._originalFaviconHref);
    });

    it('should swap favicon', () => {
        spyOn(sut, '_createFavicon');

        sut._swapFavicon();

        expect(document.getElementById).toHaveBeenCalledWith('favicon');
        expect(sut._createFavicon).toHaveBeenCalledWith('/assets/favicon-notify.png', link);
    });
});
<commit_msg>test(notify): check that sound option is correcly taken into account<commit_after>/*
* Copyright (C) 2015-2016 by Arena of Titans Contributors.
*
* This file is part of Arena of Titans.
*
* Arena of Titans is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Arena of Titans is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Arena of Titans. If not, see <http://www.GNU Affero.org/licenses/>.
*/

import '../../setup';
import { Wait } from '../../../../app/game/services/utils';
import { Notify } from '../../../../app/game/services/notify';
import { I18nStub } from '../../utils';


describe('services/notify', () => {
    let mockedI18n;
    let mockedOptions;
    let sut;
    let link = document.createElement('link');

    beforeEach(() => {
        spyOn(document, 'getElementById').and.returnValue(link);

        mockedI18n = new I18nStub();
        mockedOptions = {};
        sut = new Notify(mockedI18n, mockedOptions);
    });

    it('should clearNotifications', () => {
        sut._originalTitle = 'originalTitle';
        sut._originalFaviconHref = '/original/favicon';
        expect(document.title).not.toBe(sut._originalTitle);
        spyOn(sut, '_createFavicon');

        sut.clearNotifications();

        expect(document.title).toBe(sut._originalTitle);
        expect(sut._createFavicon).toHaveBeenCalledWith(sut._originalFaviconHref);
    });

    it('should swap favicon', () => {
        spyOn(sut, '_createFavicon');

        sut._swapFavicon();

        expect(document.getElementById).toHaveBeenCalledWith('favicon');
        expect(sut._createFavicon).toHaveBeenCalledWith('/assets/favicon-notify.png', link);
    });

    it('should not play sound if sounds are disabled', () => {
        mockedOptions.sound = false;
        spyOn(Wait, 'forId');

        sut._playYourTurnSound();
        sut._playVoice();

        expect(Wait.forId).not.toHaveBeenCalled();
    });

    describe('should play sound if sounds are enabled', () => {
        let element;
        let promise;

        beforeEach(() => {
            mockedOptions.sound = true;
            element = {
                play: () => {},
            };
            spyOn(element, 'play');
            promise = new Promise(resolve => resolve(element));
            spyOn(Wait, 'forId').and.returnValue(promise);
        });

        it('voice', done => {
            sut._playVoice();

            expect(Wait.forId).toHaveBeenCalledWith('notify-voice-player');
            Wait.forId('notify-voice-player').then(() => {
                expect(element.play).toHaveBeenCalled();
                done();
            });
        });

        it('sound', done => {
            sut._playYourTurnSound();

            expect(Wait.forId).toHaveBeenCalledWith('notify-sound-player');
            Wait.forId('notify-sound-player').then(() => {
                expect(element.play).toHaveBeenCalled();
                done();
            });
        });
    });
});

{'fraction_non_alphanumeric': 0.134478894284647, 'fraction_numerical': 0.007097497198356369, 'mean_word_length': 2.742138364779874, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4997128', 'n_tokens_mistral': 1562, 'n_tokens_neox': 1509, 'n_words': 412}