UNPKG

i-react-utils

Version:
294 lines (293 loc) 9.13 kB
<!doctype html> <html lang="en"> <head> <title>Code coverage report for PasswordStrengthMeter.js</title> <meta charset="utf-8" /> <link rel="stylesheet" href="prettify.css" /> <link rel="stylesheet" href="base.css" /> <meta name="viewport" content="width=device-width, initial-scale=1"> <style type='text/css'> .coverage-summary .sorter { background-image: url(sort-arrow-sprite.png); } </style> </head> <body> <div class='wrapper'> <div class='pad1'> <h1> <a href="index.html">All files</a> PasswordStrengthMeter.js </h1> <div class='clearfix'> <div class='fl pad1y space-right2'> <span class="strong">86.67% </span> <span class="quiet">Statements</span> <span class='fraction'>26/30</span> </div> <div class='fl pad1y space-right2'> <span class="strong">94.44% </span> <span class="quiet">Branches</span> <span class='fraction'>17/18</span> </div> <div class='fl pad1y space-right2'> <span class="strong">85.71% </span> <span class="quiet">Functions</span> <span class='fraction'>6/7</span> </div> <div class='fl pad1y space-right2'> <span class="strong">86.67% </span> <span class="quiet">Lines</span> <span class='fraction'>26/30</span> </div> </div> </div> <div class='status-line high'></div> <pre><table class="coverage"> <tr><td class="line-count quiet">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</td><td class="line-coverage quiet"><span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">3x</span> <span class="cline-any cline-yes">3x</span> <span class="cline-any cline-yes">3x</span> <span class="cline-any cline-yes">3x</span> <span class="cline-any cline-yes">3x</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">3x</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">3x</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">3x</span> <span class="cline-any cline-yes">3x</span> <span class="cline-any cline-yes">2x</span> <span class="cline-any cline-yes">10x</span> <span class="cline-any cline-yes">5x</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">3x</span> <span class="cline-any cline-yes">3x</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">3x</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">6x</span> <span class="cline-any cline-yes">6x</span> <span class="cline-any cline-yes">6x</span> <span class="cline-any cline-yes">6x</span> <span class="cline-any cline-yes">6x</span> <span class="cline-any cline-yes">6x</span> <span class="cline-any cline-yes">2x</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">6x</span> <span class="cline-any cline-yes">6x</span> <span class="cline-any cline-yes">1x</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">6x</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span></td><td class="text"><pre class="prettyprint lang-js">import React from 'react'; import {shallowCopyExcept} from './utils'; &nbsp; export default class PasswordStrengthMeter extends React.Component { static propTypes = { minLength : React.PropTypes.number, // min password length strengthThreshold : React.PropTypes.number.isRequired, // lowest security level possible password : React.PropTypes.string.isRequired, // password rules : React.PropTypes.array }; &nbsp; static defaultProps = { minLength : 0, rules : [new RegExp('[a-z]'), new RegExp('[A-Z]'), new RegExp('[0-9]'), new RegExp('[\\W]'), new RegExp('.{9,}')] }; &nbsp; constructor(props) { super(); this.state = { level : 0, length : 0 }; this.props = props; this._calculate = this._calculate.bind(this); this._prepare(props); } &nbsp; _prepare(props) { this.divProps = shallowCopyExcept({}, props, ['rules','password','strengthThreshold','minLength']); } &nbsp; _calculate(password) { <span class="missing-if-branch" title="if path not taken" >I</span>if (password === undefined || password === null) { <span class="cstat-no" title="statement not covered" > password = '';</span> } let level = 0; if (password.length &gt; 0 &amp;&amp; password.length &gt;= this.props.minLength) { this.props.rules.forEach((r) =&gt; { if (r.test(password)) { level++; } }); } this.setState({level : level, length : password.length }); return level; } &nbsp; componentDidMount() { this._calculate(this.props.password); } &nbsp; <span class="fstat-no" title="function not covered" > co</span>mponentWillReceiveProps(nextProps) { <span class="cstat-no" title="statement not covered" > this.props = nextProps;</span> <span class="cstat-no" title="statement not covered" > this._prepare(nextProps);</span> <span class="cstat-no" title="statement not covered" > this._calculate(nextProps.password);</span> } &nbsp; &nbsp; render() { const {length,level} = this.state; const max = this.props.rules.length + 1; const step = 100 / max; const prc = ( step * (level + (length &gt; 0 ? 1 : 0)) ) + "%"; let cl = 'progress-bar-danger'; if (level &gt;= this.props.strengthThreshold) { cl = 'progress-bar-warning'; } let i = Math.floor((max -1 - this.props.strengthThreshold) / 2) + this.props.strengthThreshold; if (level == max -1 || level &gt;= i) { cl = 'progress-bar-success' } return ( &lt;div {... this.divProps} className="password-strength-meter progress"&gt; &lt;div className={`progress-bar ${cl} password-strength-meter-bar`} style={{width: prc}}&gt;{this.props.children}&lt;/div&gt; &lt;/div&gt; ); } &nbsp; } &nbsp;</pre></td></tr> </table></pre> <div class='push'></div><!-- for sticky footer --> </div><!-- /wrapper --> <div class='footer quiet pad2 space-top1 center small'> Code coverage generated by <a href="https://istanbul.js.org/" target="_blank">istanbul</a> at Sun Dec 17 2017 22:40:08 GMT+0100 (CET) </div> </div> <script src="prettify.js"></script> <script> window.onload = function () { if (typeof prettyPrint === 'function') { prettyPrint(); } }; </script> <script src="sorter.js"></script> </body> </html>