UNPKG

2.47 kBJavaScriptView Raw
1// Generated by CoffeeScript 1.7.1
2var Editor, Form, assert, async, path;
3
4async = require("async");
5
6assert = require("assert");
7
8path = require('path');
9
10Form = (require('../index.js')).form;
11
12Editor = (require('../index.js')).editor;
13
14describe('Form', function() {
15 describe('field', function() {
16 return it('get / set', function(done) {
17 var form;
18 form = Form({});
19 form.field("username", function(options, next) {
20 return next(null, {
21 tag: 'label',
22 text: 'open it'
23 });
24 });
25 assert.equal(true, (form.field('username')) != null);
26 return done();
27 });
28 });
29 describe('init()', function() {
30 return it('test', function(done) {
31 var form, locals;
32 form = Form({
33 url: "www.baidu.com"
34 });
35 form.field("username", {
36 make: function(options, next) {
37 return next(null, {
38 tag: 'label',
39 text: 'open it'
40 });
41 }
42 });
43 assert.equal(true, (form.field('username')) != null, "field can not be get");
44 locals = {};
45 return form.init({}, {
46 locals: locals
47 }, function(error) {
48 assert.equal(true, (locals.$form.field('username')) != null);
49 assert.equal("www.baidu.com", locals.$form.url);
50 return done();
51 });
52 });
53 });
54 describe('val()', function() {
55 return it('get value', function(done) {
56 var form, locals;
57 form = Form({});
58 form.field("username", {
59 val: function(options, next) {
60 return next(null, 'tom');
61 }
62 });
63 locals = {};
64 return form.val({
65 body: {
66 'username': '1212'
67 }
68 }, {
69 locals: locals
70 }, function(error, data) {
71 assert.equal('tom', data.username);
72 return done();
73 });
74 });
75 });
76 return describe('val()', function() {
77 return it('valid', function(done) {
78 var form, locals;
79 form = Form({});
80 form.field("username", {
81 val: function(options, next) {
82 return next('username error');
83 }
84 });
85 locals = {};
86 return form.val({
87 body: {
88 'username': '1212'
89 }
90 }, {
91 locals: locals
92 }, function(error, data) {
93 assert.equal(true, error != null);
94 assert.equal('username error', locals.$form.errors['username']);
95 return done();
96 });
97 });
98 });
99});
100
101//# sourceMappingURL=form_test.map