Code coverage report for lib/asserters.js

Statements: 88.89% (32 / 36)      Branches: 72.73% (16 / 22)      Functions: 100% (13 / 13)      Lines: 100% (30 / 30)     

All files » lib/ » asserters.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 951   1 209               1   2 2 2 2                   1 2   2 2 2 2                     1   35 35 35                   1   7 7 7                     1   6 6   8 8 8 6           1                
var S = require('string');
 
function Asserter(_assert){
  this.assert = _assert;
}
 
/**
 * asserters.nonEmptyText
 *
 * @asserter
 */
var nonEmptyText = new Asserter(
  function (target, cb) {
    target.text(function(err, text) {
      Iif(err) { return cb(err); }
      var satisfied = text && S(text).trim().length >0;
      cb(null, satisfied, satisfied? text : undefined);
    });
  }
);
 
/**
 * asserters.textInclude(content) -> Asserter
 *
 * @asserter
 */
function textInclude(content) {
  return new Asserter(
    function(target, cb) {
      target.text(function(err, text) {
        Iif(err) { return cb(err); }
        var satisfied = text && S(text).contains(content);
        cb(null, satisfied, satisfied? text : undefined);
      });
    }
  );
}
 
/**
 * asserters.isVisible
 *
 * @asserter
 */
var isVisible = new Asserter(
  function(el,cb) {
    el.isVisible(function(err, isVisible) {
      Iif(err) { return cb(err); }
      cb(null, isVisible);
    });
  }
);
 
/**
 * asserters.isHidden
 *
 * @asserter
 */
var isHidden = new Asserter(
  function(el,cb) {
    el.isVisible(function(err, isVisible) {
      Iif(err) { return cb(err); }
      cb(null, !isVisible);
    });
  }
);
 
/**
 * asserters.jsCondition(jsConditionExpr) -> Asserter
 * jsConditionExpr: js script expression, should evaluate as boolean.
 * 
 * @asserter
 */
function jsCondition(jsConditionExpr, safe) {
  // jshint evil: true
  if(safe === undefined) { safe = false; }
  return new Asserter(
    function(browser, cb) {
      var _eval = safe? browser.safeEval : browser.eval;
      _eval.apply( browser , [jsConditionExpr, function(err, res) {
        if(err) {return cb(err);}
        cb(null, res, res);
      }]);
    }
  );
}
 
module.exports = {
  Asserter: Asserter,
  nonEmptyText: nonEmptyText,
  isVisible: isVisible,
  isHidden: isHidden,
  textInclude: textInclude,
  jsCondition: jsCondition
};