test('[html_factory._get_text] correct, default should be empty string', function (t) { t.plan(1); var hf = html_factory(); var result = hf._get_text(); t.equal(result.text, ''); });
test('[html_factory._bundle] correct', function (t) { t.plan(6); SETUP(); var hf = html_factory(); var html = document.createElement('input'); html.type = 'radio'; html.id = "1"; var de = new createjs.DOMElement(html); var text = new createjs.Text('some string'); var result = hf._bundle(de, text); t.ok(check.instanceStrict(result, createjs.Container), 'should get back a createjs.Container'); t.equal(result.children.length, 2); t.deepEqual(result.children[0], de); t.deepEqual(result.children[1], text); t.deepEqual(result._.htmlElement, html); t.equal(result._.text, 'some string'); TEARDOWN(); });
test('[UI_factory._pubsub_radio_buttons] correct, unique button events', function (t) { //get pub/sub so we can do subscriptions before setting up event handlers var pub_sub = require('pubsub-js'); pub_sub.clearAllSubscriptions(); t.plan(2); //setup var html_factory = require('lib/factory/html_factory'); var hf = html_factory(); var text_factory = require('lib/factory/text_factory'); var tf = text_factory(); var container = new createjs.Container(); for(var i = 0; i < 2; i++) { //create a container to hold the text and radio button var c = new createjs.Container(); //create the button hf.html({ type:'radio', }); var b = hf.get(); //create the text //get the current label for this button var l = String('test' + String(i)); tf.text({text:l}); //space the label so that it does not intersect the radio button var te = tf.get(); //add the Text and Button to the container c.addChild(te); c.addChild(b); //add the radio button container to the parent container // for return of all the radio buttons in the set container.addChild(c); pub_sub.subscribe("radio_button_check." + l, function(event, DOMElement) { t.ok(true, "just track number of events seen, as they're all for specific buttons"); }); } var uf = UI_factory(); uf._pubsub_radio_buttons(container, pub_sub); //test //dispatch the events to test for (var j = 0; j < container.children.length; j++) { container.children[j].children[1]._.htmlElement.dispatchEvent(new Event("change")); } });
test('[html_factory.html] correct, "type" passed, id passed', function (t) { t.plan(2); var hf = html_factory(); hf.html({type:"radio", id:1}); t.equal(hf._html_options.type, "radio", "should have the radio option set"); t.equal(hf._html_options.id, "1", "should have an id"); });
test('[html_factory._decorate] correct, name unset, but label set (non-string)', function (t) { t.plan(3); //setup SETUP(); var container = new createjs.Container(); container._ = {}; var html = document.createElement('input'); html.type = 'radio'; html.id = "1"; container._.htmlElement = html; var hf = html_factory(); hf._html_options.label = 123456; var result = hf._decorate(container); //test t.ok(check.object(result._)); t.ok(check.string(result._.name)); t.equal(result._.name, "123456"); TEARDOWN(); });
test('[html_factory._decorate] correct, name', function (t) { t.plan(3); //setup SETUP(); var container = new createjs.Container(); container._ = {}; var html = document.createElement('input'); html.type = 'radio'; html.id = "1"; container._.htmlElement = html; var hf = html_factory(); hf._name = "some test name"; var result = hf._decorate(container); //test t.ok(check.object(result._)); t.ok(check.string(result._.name)); t.equal(result._.name, "some test name"); TEARDOWN(); });
test('[html_factory._decorate.append_to] correct', function (t) { t.plan(3); SETUP(); var container = new createjs.Container(); container._ = {}; var html = document.createElement('input'); html.type = 'radio'; html.id = "1"; container._.htmlElement = html; var hf = html_factory(); var result = hf._decorate(container); var target = document.createElement('div'); result._.append_to(target); t.ok(target.hasChildNodes(), "the div we created should now have children"); t.equal(target.childNodes.length, 1, "...there should be only one child"); t.deepEqual(target.childNodes[0], html, "...and the child should be the HTML we made"); TEARDOWN(); });
test('[html_factory._decorate.append_to] incorrect, bad argument', function (t) { t.plan(2); var container = new createjs.Container(); container._ = {}; var html = document.createElement('input'); html.type = 'radio'; html.id = "1"; container._.htmlElement = html; var hf = html_factory(); var result = hf._decorate(container); var target = document.createElement('div'); try { result._.append_to("some bad argument"); } catch(error) { t.ok(check.instanceStrict(error, TypeError), 'we should get back a TypeError'); var message = error.toString(); t.ok(message.match(/HTML Element/), '...we should want an HTML element'); } });
test('[UI_factory._decorate_text_input] get_input(), incorrect, undefined', function (t) { t.plan(1); //SETUP var html_factory = require('lib/factory/html_factory'); var hf = html_factory(); var text_factory = require('lib/factory/text_factory'); var tf = text_factory(); var container = new createjs.Container(); //get the Text object tf.text({text:String('test')}); var te = tf.get(); //get the text input element hf.html({ type:'text', }); var h = hf.get(); //add to the container container.addChild(te); container.addChild(h); container.setBounds(0, 0, 0, 0); //TEST var uf = UI_factory(); var result = uf._decorate_text_input(container); result.children[1]._.htmlElement.value = undefined; t.ok(Number.isNaN(result._.get_text_input_value()), 'shold get back NaN on non-numeric input'); });
test('[html_factory.html] correct, "type" passed, id generated', function (t) { t.plan(3); var hf = html_factory(); hf.html({type:"radio"}); t.equal(hf._html_options.type, "radio", "should have the radio option set"); t.ok(hf._html_options.id.match(/^radio/), "id should begin with the type..."); t.ok(hf._html_options.id.match(/(\d+)$/)[1], "...and end with a number"); });
test('[html_factory._get_html] correct, label (not string)', function (t) { t.plan(1); var hf = html_factory(); hf._html_options.type = "button"; hf._html_options.label = 0; var result = hf._get_html(); t.equal(result.value, '0'); });
test('[UI_factory._decorate_radio_buttons] correct, checked property behavior', function (t) { //get pub/sub so we can do subscriptions before setting up event handlers var pub_sub = require('pubsub-js'); pub_sub.clearAllSubscriptions(); t.plan(2); //setup var html_factory = require('lib/factory/html_factory'); var hf = html_factory(); var text_factory = require('lib/factory/text_factory'); var tf = text_factory(); var container = new createjs.Container(); for(var i = 0; i < 2; i++) { //create a container to hold the text and radio button var c = new createjs.Container(); //create the button hf.html({ type:'radio', }); var b = hf.get(); //create the text //get the current label for this button var l = String('test' + String(i)); tf.text({text:l}); //space the label so that it does not intersect the radio button var te = tf.get(); //add the Text and Button to the container c.addChild(te); c.addChild(b); //add the radio button container to the parent container // for return of all the radio buttons in the set container.addChild(c); } var uf = UI_factory(); //setting bounds container.setBounds(0, 0, 0, 0); container = uf._decorate_radio_buttons(container); for (var i = 0; i < container.children.length; i++) { container.children[i].children[1]._.htmlElement.checked = true; var name = container.children[i].children[0].text; t.ok(container._.radio_button_checked[name](), 'the decorated property should update as the HTML element is changed'); } });
test('[html_factory.get] correct, user options', function (t) { t.plan(2); var hf = html_factory(); hf.html({type:'radio'}); var result = hf.get({x:1, y:1}); t.equal(result.y, 1); t.equal(result.x, 1); });
test('[html_factory._get_html] correct', function (t) { t.plan(2); var hf = html_factory(); hf._html_options.type = "radio"; hf._html_options.id = "1"; var result = hf._get_html(); t.equal(result.type, "radio", "should have the radio option set"); t.equal(result.id, "1", "should have an id"); });
test('[html_factory.html] incorrect, did not pass "type" option', function (t) { t.plan(2); var hf = html_factory(); try { hf.html({}); } catch(error) { t.ok(check.instanceStrict(error, TypeError), 'we should get back a TypeError'); var message = error.toString(); t.ok(message.match(/argument \'type\' is required/), 'argument should include "type"'); } });
test('[html_factory._set_props] correct, user options', function (t) { t.plan(2); var container = new createjs.Container(); var hf = html_factory(); var result = hf._set_props(container, {x:1, y:1}); t.equal(result.y, 1); t.equal(result.x, 1); });
test('[html_factory.html] incorrect, "type" passed, but unknown', function (t) { t.plan(2); var hf = html_factory(); try { hf.html({type:"some wrong type"}); } catch(error) { t.ok(check.instanceStrict(error, TypeError), 'we should get back a TypeError'); var message = error.toString(); t.ok(message.match(/argument \'type\' was unsupported/), 'argument should include "type"'); } });
test('[html_factory.html] incorrect, option "label" set but type is not button', function (t) { t.plan(3); var hf = html_factory(); try { hf.html({type:"radio", label:"some label"}); } catch(error) { t.ok(check.instanceStrict(error, TypeError), 'we should get back a TypeError'); var message = error.toString(); t.ok(message.match(/label/)); t.ok(message.match(/button/)); } });
test('[html_factory.get] incorrect, type unset', function (t) { t.plan(2); var hf = html_factory(); try { hf.get(); } catch(error) { t.ok(check.instanceStrict(error, TypeError), 'we should get back a TypeError'); var message = error.toString(); t.ok(message.match(/Unknown type of HTML to create/), 'argument should include "type"'); } });
test('[html_factory._get_dom_element] correct', function (t) { t.plan(3); var hf = html_factory(); var html = document.createElement('input'); html.type = 'radio'; html.id = "1"; var result = hf._get_dom_element(html); t.ok(check.instanceStrict(result, createjs.DOMElement), 'should get back a createjs.DOMElement'); t.equal(result.htmlElement.type, 'radio', 'radio type input element'); t.equal(result.htmlElement.id, '1', 'id should be set'); });
test('[html_factory.get] incorrect, bad options', function (t) { t.plan(2); var hf = html_factory(); hf.html({type:'radio'}); try { hf.get("some bad argument") } catch(error) { t.ok(check.instanceStrict(error, TypeError), 'we should get back a TypeError'); var message = error.toString(); t.ok(message.match(/requires Object/), 'object required'); } });
test('[html_factory._get_html] correct, label', function (t) { t.plan(1); SETUP(); var hf = html_factory(); hf._html_options.type = "button"; hf._html_options.label = 'some label'; var result = hf._get_html(); t.equal(result.value, 'some label'); TEARDOWN(); });
test('[html_factory._set_props] correct, no options', function (t) { t.plan(2); SETUP(); var container = new createjs.Container(); var hf = html_factory(); var result = hf._set_props(container); t.equal(result.x, 0); t.equal(result.y, 0); TEARDOWN(); });
test("[html_factory] incorrect, 'createjs' unset", function (t) { t.plan(3); //TEST try { html_factory(); } catch(error) { t.ok(check.instanceStrict(error, ReferenceError), 'we should get back a ReferenceError'); var message = error.toString(); console.log(message); t.ok(message.match(/createjs/), 'checking for an object in primitives'); t.ok(message.match(/undefined or not object in primitives object/), 'defined what was wrong'); } TEARDOWN(); });
test('[html_factory.get] correct', function (t) { t.plan(8); var hf = html_factory(); hf.html({type:'radio'}); var result = hf.get() t.ok(result.children, "we should have a container"); t.equal(result.children.length, 2, "...that has two children"); t.ok(result.children[0].htmlElement, "...the first child is an HTML element"); t.ok(check.string(result.children[1].text), "...the second is Text"); t.deepEqual(result.children[0].htmlElement, result._.htmlElement, "...we should see the HTML exposed in our namespace _"); t.equal(result.children[1].text, result._.text, "...and the text value exposed in _"); t.equal(result._.htmlElement.type, 'radio', '...and the type of the HTML input should be "radio"'); t.ok(check.function(result._.append_to), "...and we can see the apply_to method"); });
test('[html_factory.get] correct, user options, multiple object', function (t) { t.plan(6); var hf = html_factory(); hf.html({type:'radio'}); var result1 = hf.get({x:1, y:1}); t.equal(result1.y, 1); t.equal(result1.x, 1); t.equal(result1._.htmlElement.type, 'radio'); var result2 = hf.get(); t.equal(result2.x, 1); t.equal(result2.y, 1); t.equal(result2._.htmlElement.type, 'radio'); });
test('[html_factory._decorate] correct', function (t) { t.plan(2); var container = new createjs.Container(); container._ = {}; var html = document.createElement('input'); html.type = 'radio'; html.id = "1"; container._.htmlElement = html; var hf = html_factory(); var result = hf._decorate(container); t.ok(result._.append_to, "the decorated method was applied to the container"); t.ok(check.function(result._.append_to), "...and that it's a method"); });
test('[html_factory._decorate] correct, add_to_stage', function (t) { t.plan(2); var container = new createjs.Container(); container._ = {}; var html = document.createElement('input'); html.type = 'radio'; html.id = "1"; container._.htmlElement = html; var hf = html_factory(); var result = hf._decorate(container); t.ok(check.object(result._)); t.ok(check.function(result._.add_to_stage)); });
test('[html_factory.get] correct, user options, text set', function (t) { t.plan(8); var hf = html_factory(); hf.html({type:'radio'}); hf.text({text:"some string"}) var result1 = hf.get({x:1, y:1}); t.equal(result1.y, 1); t.equal(result1.x, 1); t.equal(result1._.htmlElement.type, 'radio'); t.equal(result1._.text, "some string"); var result2 = hf.get(); t.equal(result2.x, 1); t.equal(result2.y, 1); t.equal(result2._.htmlElement.type, 'radio'); t.equal(result2._.text, "some string"); });
test("[html_factory] incorrect, 'createjs' wrong type", function (t) { t.plan(3); //SETUP SETUP(); var primitives = require("lib/util/primitives"); primitives.set('createjs', ''); //TEST try { html_factory(); } catch(error) { t.ok(check.instanceStrict(error, ReferenceError), 'we should get back a ReferenceError'); var message = error.toString(); t.ok(message.match(/createjs/), 'checking for an object in primitives'); t.ok(message.match(/undefined or not object in primitives object/), 'defined what was wrong'); } TEARDOWN(); });