|
@@ -1,29 +1,29 @@ |
|
|
import test from 'ava'; |
|
|
import test from 'ava'; |
|
|
|
|
|
import jsdom from 'jsdom'; |
|
|
import {getLoginForm, getScore, getBestByScore, getFormInfo} from '../extension/form-parser'; |
|
|
import {getLoginForm, getScore, getBestByScore, getFormInfo} from '../extension/form-parser'; |
|
|
|
|
|
|
|
|
test('form get a score of 10 if with a Log in button', t => { |
|
|
test('form get a score of 10 if with a Log in button', t => { |
|
|
const document = require('jsdom').jsdom(`<form><button type="submit"> Log in </button></form>`); |
|
|
|
|
|
|
|
|
const document = jsdom.jsdom(`<form><button type="submit"> Log in </button></form>`); |
|
|
t.is(getScore(document.forms[0]), 10); |
|
|
t.is(getScore(document.forms[0]), 10); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
test('form get a score of 10 with a Sign in button', t => { |
|
|
test('form get a score of 10 with a Sign in button', t => { |
|
|
const document = require('jsdom').jsdom(`<form><button type="submit"> Sign In </button></form>`); |
|
|
|
|
|
|
|
|
const document = jsdom.jsdom(`<form><button type="submit"> Sign In </button></form>`); |
|
|
t.is(getScore(document.forms[0]), 10); |
|
|
t.is(getScore(document.forms[0]), 10); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
test('form get a score case insensitive', t => { |
|
|
test('form get a score case insensitive', t => { |
|
|
const document = require('jsdom').jsdom(`<form><button type="submit">lOg iN</button></form>`); |
|
|
|
|
|
|
|
|
const document = jsdom.jsdom(`<form><button type="submit">lOg iN</button></form>`); |
|
|
t.is(getScore(document.forms[0]), 10); |
|
|
t.is(getScore(document.forms[0]), 10); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
test('form get a score of 10 if input type submit', t => { |
|
|
test('form get a score of 10 if input type submit', t => { |
|
|
const document = require('jsdom').jsdom(`<form><input value="Log In" type="submit"/></form>`); |
|
|
|
|
|
|
|
|
const document = jsdom.jsdom(`<form><input value="Log In" type="submit"/></form>`); |
|
|
t.is(getScore(document.forms[0]), 10); |
|
|
t.is(getScore(document.forms[0]), 10); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test('form get a score of 0 if form not a login or signup form', t => { |
|
|
test('form get a score of 0 if form not a login or signup form', t => { |
|
|
const document = require('jsdom').jsdom(`<form><input value="title" type="text"/></form>`); |
|
|
|
|
|
|
|
|
const document = jsdom.jsdom(`<form><input value="title" type="text"/></form>`); |
|
|
t.is(getScore(document.forms[0]), 0); |
|
|
t.is(getScore(document.forms[0]), 0); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
@@ -38,7 +38,7 @@ test('filter empty forms array', t => { |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
test('get login form', t => { |
|
|
test('get login form', t => { |
|
|
const document = require('jsdom').jsdom(`<!doctype html><html><body> |
|
|
|
|
|
|
|
|
const document = jsdom.jsdom(`<!doctype html><html><body> |
|
|
<form action="/signup" method="post"> |
|
|
<form action="/signup" method="post"> |
|
|
<input name="user[name]" maxlength="20" placeholder="Full name" type="text"> |
|
|
<input name="user[name]" maxlength="20" placeholder="Full name" type="text"> |
|
|
<input name="user[email]" placeholder="Email" type="text"> |
|
|
<input name="user[email]" placeholder="Email" type="text"> |
|
@@ -59,25 +59,25 @@ test('get login form', t => { |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
test('get no form if not password field in', t => { |
|
|
test('get no form if not password field in', t => { |
|
|
const document = require('jsdom').jsdom(`<!doctype html><html><body><form><input value="title" type="text"/></form></body></html>`); |
|
|
|
|
|
|
|
|
const document = jsdom.jsdom(`<!doctype html><html><body><form><input value="title" type="text"/></form></body></html>`); |
|
|
t.is(getLoginForm(document), null); |
|
|
t.is(getLoginForm(document), null); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
test('get usefull field in form', t => { |
|
|
test('get usefull field in form', t => { |
|
|
const document = require('jsdom').jsdom(`<form><input id="passwordField" type="password" name="password"/></form>`); |
|
|
|
|
|
|
|
|
const document = jsdom.jsdom(`<form><input id="passwordField" type="password" name="password"/></form>`); |
|
|
t.is(getFormInfo(document.forms[0]).passwordField, document.getElementById('passwordField')); |
|
|
t.is(getFormInfo(document.forms[0]).passwordField, document.getElementById('passwordField')); |
|
|
t.is(getFormInfo(document.forms[0]).loginField, null); |
|
|
t.is(getFormInfo(document.forms[0]).loginField, null); |
|
|
t.is(getFormInfo(document.forms[0]).button, null); |
|
|
t.is(getFormInfo(document.forms[0]).button, null); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
test('test get option fields in form', t => { |
|
|
test('test get option fields in form', t => { |
|
|
const document = require('jsdom').jsdom(`<form><input id="usernameField" type="text" name="username"/><input type="password" name="password"/><button>Cancel</button><button id="button" type="submit">Sign In</button></form>`); |
|
|
|
|
|
|
|
|
const document = jsdom.jsdom(`<form><input id="usernameField" type="text" name="username"/><input type="password" name="password"/><button>Cancel</button><button id="button" type="submit">Sign In</button></form>`); |
|
|
t.is(getFormInfo(document.forms[0]).loginField, document.getElementById('usernameField')); |
|
|
t.is(getFormInfo(document.forms[0]).loginField, document.getElementById('usernameField')); |
|
|
t.is(getFormInfo(document.forms[0]).button, document.getElementById('button')); |
|
|
t.is(getFormInfo(document.forms[0]).button, document.getElementById('button')); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
test('test real form 1', t => { |
|
|
test('test real form 1', t => { |
|
|
const document = require('jsdom').jsdom(`<!doctype html><html><body> <form> |
|
|
|
|
|
|
|
|
const document = jsdom.jsdom(`<!doctype html><html><body> <form> |
|
|
<fieldset class="form-group"><p class="text-muted"> Happy to see you here again </p> |
|
|
<fieldset class="form-group"><p class="text-muted"> Happy to see you here again </p> |
|
|
<label for="email" class="sr-only">login.email</label> |
|
|
<label for="email" class="sr-only">login.email</label> |
|
|
<input type="text" class="form-control" id="email" autofocus="" placeholder="Enter your email"> |
|
|
<input type="text" class="form-control" id="email" autofocus="" placeholder="Enter your email"> |
|
|