UNPKG

6.52 kBJavaScriptView Raw
1// Generated by CoffeeScript 1.7.1
2var Editor, assert, async, path;
3
4async = require("async");
5
6assert = require("assert");
7
8path = require('path');
9
10Editor = (require('../index.js')).editor;
11
12describe('Editor', function() {
13 describe('Textbox', function() {
14 return it('Editor', function(done) {
15 var textbox;
16 textbox = Editor.textbox({
17 maxlength: Editor.attrs.maxlength(12)
18 });
19 return textbox.make({
20 req: {}
21 }, function(error, element) {
22 assert.equal('text', element['type']);
23 assert.equal('input', element['tag']);
24 assert.equal(12, element['maxlength']);
25 return done();
26 });
27 });
28 });
29 describe('Attrs', function() {
30 return it('PlaceHolder', function(done) {
31 var options, placeholder;
32 placeholder = Editor.attrs.placeholder('hello world');
33 options = {
34 element: {},
35 res: {
36 locals: {}
37 }
38 };
39 return placeholder.makeAttr(options, function(err) {
40 assert.equal('hello world', options.element['placeholder']);
41 return done();
42 });
43 });
44 });
45 describe('textbox', function() {
46 it('make', function(done) {
47 var options, textbox;
48 textbox = Editor.textbox({});
49 options = {
50 element: {},
51 req: {
52 body: {
53 'email': 'tom'
54 }
55 },
56 res: {},
57 fieldName: 'email'
58 };
59 return textbox.make(options, function(err, element) {
60 assert.equal('input', element['tag']);
61 assert.equal('text', element['type']);
62 assert.equal('email', element['name']);
63 assert.equal('tom', element['value'], 'get value failed');
64 return done();
65 });
66 });
67 it('make without value', function(done) {
68 var options, textbox;
69 textbox = Editor.textbox({});
70 options = {
71 element: {},
72 req: {},
73 res: {},
74 fieldName: 'email'
75 };
76 return textbox.make(options, function(err, element) {
77 assert.equal('input', element['tag']);
78 assert.equal('text', element['type']);
79 assert.equal('email', element['name']);
80 assert.equal('', element['value']);
81 return done();
82 });
83 });
84 it('val', function(done) {
85 var options, textbox;
86 textbox = Editor.textbox({});
87 options = {
88 element: {},
89 req: {
90 body: {
91 'email': 'tom'
92 }
93 },
94 res: {
95 locals: {
96 $i18n: {
97 t: function(x) {
98 return x;
99 }
100 }
101 }
102 },
103 fieldName: 'email'
104 };
105 return textbox.val(options, function(err, data) {
106 assert.equal('tom', data);
107 return done();
108 });
109 });
110 return it('val with verify', function(done) {
111 var locals, options, textbox;
112 textbox = Editor.textbox([Editor.attrs.required("xxx is required")]);
113 locals = {
114 $i18n: {
115 t: function(x) {
116 return x;
117 }
118 }
119 };
120 options = {
121 element: {},
122 req: {
123 body: {
124 'email': null
125 }
126 },
127 res: {
128 locals: locals
129 },
130 fieldName: 'email'
131 };
132 return textbox.val(options, function(err, data) {
133 assert.equal(null, data);
134 assert.equal(true, err != null);
135 return done();
136 });
137 });
138 });
139 describe('password', function() {
140 it('make', function(done) {
141 var options, textbox;
142 textbox = Editor.password({});
143 options = {
144 element: {},
145 req: {
146 body: {
147 'password': 'tom'
148 }
149 },
150 res: {},
151 fieldName: 'password'
152 };
153 return textbox.make(options, function(err, element) {
154 assert.equal('input', element['tag']);
155 assert.equal('password', element['type']);
156 assert.equal('password', element['name']);
157 assert.equal('tom', element['value']);
158 return done();
159 });
160 });
161 it('make without value', function(done) {
162 var options, textbox;
163 textbox = Editor.password({});
164 options = {
165 element: {},
166 req: {
167 body: {}
168 },
169 res: {},
170 fieldName: 'password'
171 };
172 return textbox.make(options, function(err, element) {
173 assert.equal('input', element['tag']);
174 assert.equal('password', element['type']);
175 assert.equal('password', element['name']);
176 assert.equal('', element['value']);
177 return done();
178 });
179 });
180 it('val', function(done) {
181 var options, textbox;
182 textbox = Editor.password({});
183 options = {
184 element: {},
185 req: {
186 body: {
187 'email': 'tom'
188 }
189 },
190 res: {
191 locals: {
192 $i18n: {
193 t: function(x) {
194 return x;
195 }
196 }
197 }
198 },
199 fieldName: 'email'
200 };
201 return textbox.val(options, function(err, data) {
202 assert.equal('tom', data);
203 return done();
204 });
205 });
206 return it('val with verify', function(done) {
207 var locals, options, textbox;
208 textbox = Editor.password({
209 required: Editor.attrs.required("xxx is required")
210 });
211 locals = {
212 $i18n: {
213 t: function(x) {
214 return x;
215 }
216 }
217 };
218 options = {
219 element: {},
220 req: {
221 body: {
222 'email': null
223 }
224 },
225 res: {
226 locals: locals
227 },
228 fieldName: 'email'
229 };
230 return textbox.val(options, function(err, data) {
231 assert.equal(null, data);
232 assert.equal(true, err != null);
233 return done();
234 });
235 });
236 });
237 return describe('verify', function() {
238 return it('tap', function(done) {
239 var locals, verify;
240 locals = {
241 $i18n: {
242 t: function(x) {
243 return x;
244 }
245 }
246 };
247 verify = Editor.attrs.verify((function(options, next) {
248 next('error1');
249 return assert.equal(12, options.value);
250 }));
251 return verify.verify({
252 value: 12,
253 req: {},
254 res: {
255 locals: locals
256 },
257 fieldName: 'email'
258 }, function(err, result) {
259 assert.equal('error1', err);
260 return done();
261 });
262 });
263 });
264});
265
266//# sourceMappingURL=editor_test.map