UNPKG

tools

Version:

Install for the tools

261 lines (226 loc) 6.03 kB
var recline; var forms; var new_form; var body = { "field1" : "todd@toddm.me", "field2" : "this is text", "field3" : "this is field 3 for the forms validation", "field4" : "first chouce", "field5" : "on", "field6" : "firstchoice" } var _body = { "field1" : "todd@toddm.me", "field2" : "this is text", "field3" : "this is field 3 for the forms validation", "field4" : "first chouce", "field5" : "on", "field6" : "firstchoice" } function guidGenerator() { var S4 = function() { return (((1+Math.random())*0x10000)|0).toString(16).substring(1); }; return ("newformtest-"+S4()+S4()+""+S4()+""+S4()+""+S4()+""+S4()+S4()+S4()); } exports.forms = { 1 : function(test) { recline = require('recline').settings(__dirname + '/settings.json'); forms = recline.module("forms"); test.done(); }, _init: function(test){ var template = require('recline/core/tmpl'); var fs = require('fs'); fs.readFile(__dirname + '/fixtures/signup.js','utf8',function(er,data){ recline.forms.saveDoc('signup', data, function(er,res){ //test.ok(res); }); }); fs.readFile(__dirname + '/fixtures/daisychain.js','utf8',function(er,data){ recline.forms.saveDoc('daisychain', data, function(er,res){ //test.ok(res); }); }); fs.readFile(__dirname + '/fixtures/new_form.js','utf8',function(er,data){ new_form = data; }); template.get('template1', function(er,res){ if(er == 404){ this.save('template1.html'); test.done(); }else{ test.done(); } }); }, initialisemember : function(test){ var form = forms.get('signup'); test.ok(form.id); test.equals(typeof form.id, "string"); test.throws(function(){ var form = new members.Instance({}) }); test.throws(function(){ var form = new members.Instance(123) }); test.throws(function(){ var form = new members.Instance([123]) }); test.throws(function(){ var form = new members.Instance(true) }) test.done(); }, 404: function(test){ var form = forms.get('randomformadfasdfj', function(er,res){ test.equals(er, 404); test.done(); }); }, get: function(test){ var form = forms.get('signup', function(er,res){ test.ok(res); test.done(); }); }, save: function(test){ var form = forms.save('signup', body, function(er,res){ test.ok(res); test.done(); }); }, createError: function(test){ // A form must have at least a title // One field // And a response // Templates can be set by default var form = forms.create("signup", new_form, function(er,res){ if(er){ test.ok(er) test.done(); }else{ } }); }, create: function(test){ // A form must have at least a title // One field // And a response // Templates can be set by default var form = forms.create(guidGenerator(), new_form, function(er,res){ if(er){ console.log("Console log from cerate function in test",er); }else{ test.done(); } }); }, delete: function(test){ test.done(); }, update: function(test){ test.done(); } } exports.fields = { checkemailfieldNotIncluded: function(test){ delete _body["field1"]; var form = forms.save('signup', _body, function(er,res){ test.ok(res); test.equals(typeof res,"string"); test.done(); }); }, checkemailfieldResultNotValid: function(test){ _body["field1"] = "tdafd"; var form = forms.save('signup', _body, function(er,res){ _body["field1"] = "todd@toddm.me"; test.ok(res); test.equals(typeof res,"string"); test.done(); }); }, checktextInputNotIncluded: function(test){ delete _body["field2"]; var form = forms.save('signup', _body, function(er,res){ test.ok(res); test.equals(typeof res,"string"); test.done(); }); }, checktextInputResultNotValid: function(test){ _body["field2"] = ""; var form = forms.save('signup', _body, function(er,res){ _body["field2"] = "this is text"; test.ok(res); test.equals(typeof res,"string"); test.done(); }); }, checktextAreaNotIncluded: function(test){ delete _body["field3"]; var form = forms.save('signup', _body, function(er,res){ test.ok(res); test.equals(typeof res,"string"); test.done(); }); }, checktextAreaResultNotValid: function(test){ _body["field3"] = ""; var form = forms.save('signup', _body, function(er,res){ _body["field3"] = "this is field 3 for the forms validation"; test.ok(res); test.equals(typeof res,"string"); test.done(); }); }, checkradiosNotIncluded: function(test){ delete _body["field4"]; var form = forms.save('signup', _body, function(er,res){ test.ok(res); test.equals(typeof res,"string"); test.done(); }); }, checkradiosResultNotValid: function(test){ _body["field4"] = ""; var form = forms.save('signup', _body, function(er,res){ _body["field4"] = "first chouce"; test.ok(res); test.equals(typeof res,"string"); test.done(); }); }, checkcbNotIncluded: function(test){ delete _body["field5"]; var form = forms.save('signup', _body, function(er,res){ test.ok(res); test.equals(typeof res,"string"); test.done(); }); }, checkcbResultNotValid: function(test){ _body["field5"] = ""; var form = forms.save('signup', _body, function(er,res){ _body["field5"] = "on"; test.ok(res); test.equals(typeof res,"string"); test.done(); }); }, checkselectNotIncluded: function(test){ delete _body["field6"]; var form = forms.save('signup', _body, function(er,res){ test.ok(res); test.equals(typeof res,"string"); test.done(); }); }, checkselectResultNotValid: function(test){ _body["field6"] = ""; var form = forms.save('signup', _body, function(er,res){ _body["field6"] = "firstchoice"; test.ok(res); test.equals(typeof res,"string"); test.done(); }); }, checkfinalsave: function(test){ var form = forms.save('signup', _body, function(er,res){ test.equals(typeof res, "object"); test.ok(res); test.done(); }); } }