Skip to content
Extraits de code Groupes Projets
validation-spec.js 2,39 ko
Newer Older
  • Learn to ignore specific revisions
  • danielgrippi's avatar
    danielgrippi a validé
    /*   Copyright (c) 2010-2011, Diaspora Inc.  This file is
    
    *   licensed under the Affero General Public License version 3 or later.  See
    *   the COPYRIGHT file.
    */
    
    describe("Validation", function() {
    
    Dan Hansen's avatar
    Dan Hansen a validé
      describe("rules", function() {
    
    root's avatar
    root a validé
        describe("username", function() {
          describe("characters", function() {
    
    Dan Hansen's avatar
    Dan Hansen a validé
            it("is the regex for checking if we allow what the user typed", function() { 
    
              expect((typeof Validation.rules.username.characters.test === "function")).toBeTruthy();
    
    Dan Hansen's avatar
    Dan Hansen a validé
            });
    
    root's avatar
    root a validé
          });
        });
    
        describe("email", function() {
          describe("characters", function() {
             it("is the regex for checking if the input is a valid list of e-mail addresses", function() {
               expect((typeof Validation.rules.email.characters.test === "function")).toBeTruthy();
             });
          });
        });  
    
    root's avatar
    root a validé
      });
    
      describe("whiteListed", function() {
         it("returns true if the keyCode is whitelisted", function() {
            expect(Validation.whiteListed(0)).toBeTruthy();
         });
    
         it("returns false if it's not", function() {
           expect(Validation.whiteListed(9001)).toBeFalsy();
         });
      });
    
    root's avatar
    root a validé
      describe("events", function() { 
        describe("usernameKeypress", function() { 
          it("doesn't allow the user to type anything but letters, numbers and underscores", function() { 
            expect(Validation.rules.username.characters.test("*")).toBeFalsy();
            expect(Validation.rules.username.characters.test("Aa_")).toBeTruthy();
            expect(Validation.rules.username.characters.test("ffffffffffffffffffffffffffffffffff")).toBeFalsy();
    
    root's avatar
    root a validé
        });
    
        describe("emailKeypress", function() {
          it("colors the border red if the input seems to be a invalid list", function() {
            expect(Validation.rules.email.characters.test("user@example.com")).toBeTruthy();
            expect(Validation.rules.email.characters.test("user@example.com, user@example.com")).toBeTruthy();
            expect(Validation.rules.email.characters.test("user@example.com, user@example.com, user@example.com")).toBeTruthy();
            expect(Validation.rules.email.characters.test("user@example.com user@example.com")).toBeFalsy();
            expect(Validation.rules.email.characters.test("user@examplecom")).toBeFalsy();
            expect(Validation.rules.email.characters.test("userexample.com")).toBeFalsy();
            expect(Validation.rules.email.characters.test("userexamplecom")).toBeFalsy();
          });
        });
    
    root's avatar
    root a validé
      });
    });