<commit_before><commit_msg>Added ES tests<commit_after>/*global describe, it, expect, example, before, after, beforeEach, afterEach, mocha, sinon*/
'use strict';
var assert = require('chai').assert;
var $osf = require('js/osfHelpers');

var forgotPassword = require('../forgotPassword');

// Add sinon asserts to chai.assert, so we can do assert.calledWith instead of sinon.assert.calledWith
sinon.assert.expose(assert, {prefix: ''});

describe('forgotPassword', () => {
    describe('ViewModels', () => {

        describe('ForgtoPasswordViewModel', () => {
            var vm;

            var invalidUsername = 'notanemail';
            var validUsername = '<EMAIL>';

            beforeEach(() => {
                vm = new forgotPassword.ViewModel();
            });

            it('invalid email is not valid', () => {
                vm.username(invalidUsername);
                assert.isFalse(vm.username.isValid());
            });

            it('valid email is valid', () => {
                vm.username(validUsername);
                assert.isTrue(vm.username.isValid());
            });

            describe('submit', () => {
                var growlSpy;

                beforeEach(() => {
                    growlSpy = new sinon.stub($osf, 'growl');
                });

                afterEach(() => {
                    growlSpy.restore();
                });

                it('growl called if invalid username submitted', () => {
                    vm.username(invalidUsername);
                    vm.submit();
                    assert.isTrue(growlSpy.calledOnce);
                });
                it('growl not called with valid username', () => {
                    vm.username(validUsername);
                    vm.submit();
                    assert.isFalse(growlSpy.called);
                });
            });
        });
    });
});

{'fraction_non_alphanumeric': 0.14187035069075452, 'fraction_numerical': 0.0, 'mean_word_length': 1.5724043715846994, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 15, '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': '6880411', 'n_tokens_mistral': 496, 'n_tokens_neox': 463, 'n_words': 95}