mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-17 06:53:15 +00:00
Add home login views tests
This commit is contained in:
@@ -13,11 +13,11 @@ define([
|
|||||||
"backbone",
|
"backbone",
|
||||||
"bootstrap",
|
"bootstrap",
|
||||||
"common/validator",
|
"common/validator",
|
||||||
"apps/login/home/views/inputView"
|
"apps/login/home/views/input"
|
||||||
], function($, _, Backbone, bootstrap, Validator, InputView) {
|
], function($, _, Backbone, bootstrap, Validator, InputView) {
|
||||||
var RegisterForm = Backbone.View.extend({
|
var RegisterForm = Backbone.View.extend({
|
||||||
events: {
|
events: {
|
||||||
"submit": "onSubmit"
|
"submit": "_onSubmit"
|
||||||
},
|
},
|
||||||
initialize: function(options) {
|
initialize: function(options) {
|
||||||
var self = this;
|
var self = this;
|
||||||
@@ -36,7 +36,7 @@ define([
|
|||||||
self._addInputView(input);
|
self._addInputView(input);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
onSubmit: function (event) {
|
_onSubmit: function (event) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
// reset previous errors in the view
|
// reset previous errors in the view
|
||||||
|
@@ -11,7 +11,7 @@ define([
|
|||||||
"jquery",
|
"jquery",
|
||||||
"underscore",
|
"underscore",
|
||||||
"backbone",
|
"backbone",
|
||||||
"apps/login/home/views/errorView",
|
"apps/login/home/views/error",
|
||||||
"common/multiviews"
|
"common/multiviews"
|
||||||
], function($, _, Backbone, ErrorView, MultiViews) {
|
], function($, _, Backbone, ErrorView, MultiViews) {
|
||||||
var InputView = Backbone.View.extend(_.extend({}, MultiViews, {
|
var InputView = Backbone.View.extend(_.extend({}, MultiViews, {
|
@@ -58,6 +58,10 @@ define([
|
|||||||
return this.errors.length > 0;
|
return this.errors.length > 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
FormValidator.prototype.getRules = function() {
|
||||||
|
return this.rules;
|
||||||
|
};
|
||||||
|
|
||||||
FormValidator.prototype._addField = function(field) {
|
FormValidator.prototype._addField = function(field) {
|
||||||
this.fields.push({
|
this.fields.push({
|
||||||
name: field.name,
|
name: field.name,
|
||||||
|
55
www/scripts/tests/fixtures/home/login/form
vendored
Normal file
55
www/scripts/tests/fixtures/home/login/form
vendored
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
<form novalidate="" name="loginForm" method="POST" action="/login/authenticate/">
|
||||||
|
<div class="row-fluid">
|
||||||
|
<div class="span12">
|
||||||
|
<label for="login" class="required">Login</label>
|
||||||
|
<table class="input-table">
|
||||||
|
<tbody><tr>
|
||||||
|
<td class="icon">
|
||||||
|
<i class="icon-envelope icon-white"></i>
|
||||||
|
</td>
|
||||||
|
<td class="input">
|
||||||
|
<input type="text" id="login" name="login" required="required" class="input-block-level">
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody></table>
|
||||||
|
<div class="error-view"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row-fluid">
|
||||||
|
<div class="span12">
|
||||||
|
<label for="password" class="required">Password</label>
|
||||||
|
<table class="input-table">
|
||||||
|
<tbody><tr>
|
||||||
|
<td class="icon">
|
||||||
|
<i class="icon-lock icon-white"></i>
|
||||||
|
</td>
|
||||||
|
<td class="input">
|
||||||
|
<input type="password" id="password" name="password" required="required" class="input-block-level">
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody></table>
|
||||||
|
<div class="error-view"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="text-right">
|
||||||
|
<a class="forget-password-link" href="/login/forgot-password/">Forgot password?</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row-fluid">
|
||||||
|
<div class="span12">
|
||||||
|
<button type="submit" class="btn btn-success btn-trigger">
|
||||||
|
Connection
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row-fluid">
|
||||||
|
<div class="span12">
|
||||||
|
<label for="remember-me" class="checkbox">
|
||||||
|
<input type="checkbox" id="remember-me" name="remember-me" checked="checked" value="1">
|
||||||
|
Remember me
|
||||||
|
</label>
|
||||||
|
<div class="error-view"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<input type="hidden" id="redirect" name="redirect"><input type="hidden" id="_token" name="_token" value="76b1bdee87734050bb1ab237c162f1211eda0622">
|
||||||
|
</form>
|
23
www/scripts/tests/fixtures/home/login/templates
vendored
Normal file
23
www/scripts/tests/fixtures/home/login/templates
vendored
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<script type="text/template" id="field_errors">
|
||||||
|
<div class="hidden-phone popover bottom field-error">
|
||||||
|
<div class="arrow"></div>
|
||||||
|
<div class="popover-content">
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<td style="width:35px;"><i class="icon-warning-sign icon-white"></i></td>
|
||||||
|
<td>
|
||||||
|
<% _.each(errors, function(error) { %>
|
||||||
|
<div><%= error.message %></div>
|
||||||
|
<% }); %>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<span class="visible-phone text-error help-block help-block-error">
|
||||||
|
<% _.each(errors, function(error) { %>
|
||||||
|
<td> <%= error.message %></td>
|
||||||
|
<% }); %>
|
||||||
|
</span>
|
||||||
|
</script>
|
@@ -14,8 +14,10 @@
|
|||||||
require([
|
require([
|
||||||
'tests/baseTest',
|
'tests/baseTest',
|
||||||
'specs/admin/fields',
|
'specs/admin/fields',
|
||||||
|
'specs/login/home',
|
||||||
'specs/models',
|
'specs/models',
|
||||||
'specs/validator'], runMocha);
|
'specs/validator'
|
||||||
|
], runMocha);
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@@ -44,7 +44,7 @@ define([
|
|||||||
|
|
||||||
App.initialize();
|
App.initialize();
|
||||||
|
|
||||||
describe("Application", function() {
|
describe("Admin field", function() {
|
||||||
describe("Initialization", function() {
|
describe("Initialization", function() {
|
||||||
it("should create a global variable", function() {
|
it("should create a global variable", function() {
|
||||||
should.exist(AdminFieldApp);
|
should.exist(AdminFieldApp);
|
||||||
|
93
www/scripts/tests/specs/login/home.js
Normal file
93
www/scripts/tests/specs/login/home.js
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
define([
|
||||||
|
'chai',
|
||||||
|
'fixtures',
|
||||||
|
'jquery',
|
||||||
|
'apps/login/home/views/form',
|
||||||
|
'apps/login/home/views/input',
|
||||||
|
'apps/login/home/views/error'
|
||||||
|
], function(
|
||||||
|
chai,
|
||||||
|
fixtures,
|
||||||
|
$,
|
||||||
|
FormView,
|
||||||
|
InputView,
|
||||||
|
ErrorView
|
||||||
|
) {
|
||||||
|
var expect = chai.expect;
|
||||||
|
var assert = chai.assert;
|
||||||
|
var should = chai.should();
|
||||||
|
|
||||||
|
fixtures.path = 'fixtures';
|
||||||
|
$("body").append(fixtures.read('home/login/form', 'home/login/templates'));
|
||||||
|
|
||||||
|
describe("Login Home", function() {
|
||||||
|
describe("Form View", function() {
|
||||||
|
it("should be initialize validator with proper rules", function() {
|
||||||
|
var rules = [{name: "hello",rules: "simple_rules"}];
|
||||||
|
var form = new FormView({
|
||||||
|
el: $('form[name=loginForm]'),
|
||||||
|
rules: rules
|
||||||
|
});
|
||||||
|
form.validator.getRules().should.equal(rules);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should be initialize input views", function() {
|
||||||
|
var form = new FormView({
|
||||||
|
el: $('form[name=loginForm]')
|
||||||
|
});
|
||||||
|
|
||||||
|
Object.keys(form.inputViews).length.should.equal(5);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should be initialize errors", function() {
|
||||||
|
var form = new FormView({
|
||||||
|
el: $('form[name=loginForm]')
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.isTrue(_.isEmpty(form.validator.getErrors()));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("Input View", function() {
|
||||||
|
it("should initialize error view", function() {
|
||||||
|
var input = new InputView({
|
||||||
|
"name": "test"
|
||||||
|
});
|
||||||
|
expect(input.errorView).to.be.an.instanceof(ErrorView);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("Error View", function() {
|
||||||
|
it("should render errors", function() {
|
||||||
|
var error ={
|
||||||
|
name: "test",
|
||||||
|
message: "Something is wrong"
|
||||||
|
};
|
||||||
|
|
||||||
|
var errorView = new ErrorView({
|
||||||
|
"errors": [error],
|
||||||
|
"el" : $(".error-view").first()
|
||||||
|
});
|
||||||
|
|
||||||
|
errorView.render();
|
||||||
|
|
||||||
|
assert.isTrue(errorView.$el.html().indexOf(error.message) !== -1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should empty errors content if there are no errors", function() {
|
||||||
|
var $el = $(".error-view").first();
|
||||||
|
|
||||||
|
$el.html('previous error here');
|
||||||
|
|
||||||
|
var errorView = new ErrorView({
|
||||||
|
"errors": [],
|
||||||
|
"el" : $el
|
||||||
|
});
|
||||||
|
|
||||||
|
errorView.render();
|
||||||
|
|
||||||
|
assert.isTrue(errorView.$el.html() === "");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
Reference in New Issue
Block a user