fire-ide
Version:
Web-based Integrated Development Environment for fire.js
176 lines (161 loc) • 12.1 kB
text/jade
html
head
script(src="http://code.jquery.com/jquery-latest.js")
link(rel='stylesheet', href='http://code.jquery.com/qunit/git/qunit.css', type='text/css', media='screen')
script(type="text/javascript", src="http://code.jquery.com/qunit/git/qunit.js")
script(type='text/javascript', src='/javascripts/jquery.jeditable.js')
script(type='text/javascript', src='/javascripts/jquery-ui-1.8.16.custom.min.js')
script(type="text/javascript", src="/javascripts/fire-ide.js")
script
$(document).ready(function(){
$('#editor').hide()
QUnit.testStart = function() {
$('#editor').empty()
}
module("literal root value serialization");
test("string", function() {
var editor = new FireEditor($('#editor:first'))
editor.loadDocument("My Document")
equal(editor.rootEditorNode.getFirstChild().getType(), EditorNodeType.string(), "The Root editor type must be the literal type")
var serialized = editor.serialize()
equal(serialized, "My Document", "Expected serialized document to be the root literal value")
editor.rootEditorNode.getFirstChild().replaceValueFromString("My Another Value")
var serialized = editor.serialize()
strictEqual(serialized, "My Another Value", "Expected serialized document to be the equivalent replaced value from string")
});
test("boolean", function() {
var editor = new FireEditor($('#editor:first'))
editor.loadDocument(true)
equal(editor.rootEditorNode.getFirstChild().getType(), EditorNodeType.true(), "The Root editor type must be the literal type")
var serialized = editor.serialize()
strictEqual(serialized, true, "Expected serialized document to be the root literal value")
});
test("number", function() {
var editor = new FireEditor($('#editor:first'))
editor.loadDocument(2445)
equal(editor.rootEditorNode.getFirstChild().getType(), EditorNodeType.number(), "The Root editor type must be the literal type")
var serialized = editor.serialize()
strictEqual(serialized, 2445, "Expected serialized document to be the root literal value")
editor.rootEditorNode.getFirstChild().replaceValueFromString("654")
var serialized = editor.serialize()
strictEqual(serialized, 654, "Expected serialized document to be the equivalent replaced value from string")
});
test("null", function() {
var editor = new FireEditor($('#editor:first'))
editor.loadDocument(null)
equal(editor.rootEditorNode.getFirstChild().getType(), EditorNodeType.null(), "The Root editor type must be the literal type")
var serialized = editor.serialize()
strictEqual(serialized, null, "Expected serialized document to be the root literal value")
});
module("object root value serialization");
test("empty object", function() {
var editor = new FireEditor($('#editor:first'))
editor.loadDocument({})
equal(editor.rootEditorNode.getFirstChild().getType(), EditorNodeType.hash(), "The Root editor type must be the literal type")
var serialized = editor.serialize()
deepEqual(serialized, {}, "Expected serialized document to be the root object value")
});
module("array root value serialization");
test("empty array", function() {
var editor = new FireEditor($('#editor:first'))
editor.loadDocument([])
equal(editor.rootEditorNode.getFirstChild().getType(), EditorNodeType.array(), "The Root editor type must be the literal type")
var serialized = editor.serialize()
deepEqual(serialized, [], "Expected serialized document to be the root object value")
});
test("composed array", function() {
var editor = new FireEditor($('#editor:first'))
editor.loadDocument([2,null,"Three"])
equal(editor.rootEditorNode.getFirstChild().getType(), EditorNodeType.array(), "The Root node should be an array")
equal(editor.rootEditorNode.getFirstChild().children.length, 3, "The array should contain three subnodes")
// Item 0
equal(editor.rootEditorNode.getFirstChild().children[0].getType(), EditorNodeType.index(), "The subnode of the array should be index")
equal(editor.rootEditorNode.getFirstChild().children[0].getFirstChild().getType(), EditorNodeType.number(), "The type subnode of subnode 0 of the array should be number")
equal(editor.rootEditorNode.getFirstChild().children[0].getFirstChild().getValue(), 2, "The value of the subnode of subnode 0 of the array should be number")
// Item 1
equal(editor.rootEditorNode.getFirstChild().children[1].getType(), EditorNodeType.index(), "The subnode of the array should be index")
equal(editor.rootEditorNode.getFirstChild().children[1].getFirstChild().getType(), EditorNodeType.null(), "The type subnode of subnode 1 of the array should be null")
strictEqual(editor.rootEditorNode.getFirstChild().children[1].getFirstChild().getValue(), null, "The value of the subnode of subnode 1 of the array should be null")
// Item 2
equal(editor.rootEditorNode.getFirstChild().children[2].getType(), EditorNodeType.index(), "The subnode of the array should be index")
equal(editor.rootEditorNode.getFirstChild().children[2].getFirstChild().getType(), EditorNodeType.string(), "The type subnode of subnode 2 of the array should be null")
strictEqual(editor.rootEditorNode.getFirstChild().children[2].getFirstChild().getValue(), "Three", "The value of the subnode of subnode 2 of the array should be null")
var serialized = editor.serialize()
deepEqual(serialized, [2,null,"Three"], "Expected serialized document to be the array with the original values")
});
test("composed array with dynamically added values", function() {
var editor = new FireEditor($('#editor:first'))
editor.loadDocument([2,null,"Three"])
equal(editor.rootEditorNode.getFirstChild().getType(), EditorNodeType.array(), "The Root node should be an array")
editor.rootEditorNode.getFirstChild().createChild(0, EditorNodeType.index()).createChild("Another Value")
var serialized = editor.serialize()
deepEqual(serialized, [2,null,"Three", "Another Value"], "Expected serialized document to be the array with the original values")
});
module("hash root value serialization");
test("composed hash", function() {
var editor = new FireEditor($('#editor:first'))
editor.loadDocument({x:200, y:350, description: "Point One", shape: null})
equal(editor.rootEditorNode.getFirstChild().getType(), EditorNodeType.hash(), "The Root node should be an object")
equal(editor.rootEditorNode.getFirstChild().children.length, 4, "The object should contain four subnodes")
// key x
equal(editor.rootEditorNode.getFirstChild().children[0].getType(), EditorNodeType.key(), "The subnode of the object should be key")
equal(editor.rootEditorNode.getFirstChild().children[0].getValue(), "x", "The value of the subnode 0 of the hash should be the name of the key")
equal(editor.rootEditorNode.getFirstChild().children[0].getFirstChild().getType(), EditorNodeType.number(), "The type subnode of subnode 0 of the hash should be number")
equal(editor.rootEditorNode.getFirstChild().children[0].getFirstChild().getValue(), 200, "The value of the subnode of subnode 0 of the hash should be the number")
// key y
equal(editor.rootEditorNode.getFirstChild().children[1].getType(), EditorNodeType.key(), "The subnode of the hash should be key")
equal(editor.rootEditorNode.getFirstChild().children[1].getValue(), "y", "The value of the subnode 1 of the hash should be the name of the key")
equal(editor.rootEditorNode.getFirstChild().children[1].getFirstChild().getType(), EditorNodeType.number(), "The type subnode of subnode 1 of the hash should be number")
strictEqual(editor.rootEditorNode.getFirstChild().children[1].getFirstChild().getValue(), 350, "The value of the subnode of subnode 1 of the hash should be the number")
// key description
equal(editor.rootEditorNode.getFirstChild().children[2].getType(), EditorNodeType.key(), "The subnode of the hash should be key")
equal(editor.rootEditorNode.getFirstChild().children[2].getValue(), "description", "The value of the subnode 2 of the hash should be the name of the key")
equal(editor.rootEditorNode.getFirstChild().children[2].getFirstChild().getType(), EditorNodeType.string(), "The type subnode of subnode 2 of the hash should be string")
strictEqual(editor.rootEditorNode.getFirstChild().children[2].getFirstChild().getValue(), "Point One", "The value of the subnode of subnode 2 of the hash should be the string")
// key shape
equal(editor.rootEditorNode.getFirstChild().children[3].getType(), EditorNodeType.key(), "The subnode of the hash should be key")
equal(editor.rootEditorNode.getFirstChild().children[3].getValue(), "shape", "The value of the subnode 3 of the hash should be the name of the key")
equal(editor.rootEditorNode.getFirstChild().children[3].getFirstChild().getType(), EditorNodeType.null(), "The type subnode of subnode 3 of the hash should be null")
strictEqual(editor.rootEditorNode.getFirstChild().children[3].getFirstChild().getValue(), null, "The value of the subnode of subnode 3 of the hash should be null")
var serialized = editor.serialize()
deepEqual(serialized, {x:200, y:350, description: "Point One", shape: null}, "Expected serialized document to be the hash with the original values")
});
test("composed hash with dynamically added keys", function() {
var editor = new FireEditor($('#editor:first'))
editor.loadDocument({name: "Chuck"})
equal(editor.rootEditorNode.getFirstChild().getType(), EditorNodeType.hash(), "The Root node should be an hash")
editor.rootEditorNode.getFirstChild().createChild("email", EditorNodeType.key()).createChild("chuck@example.com")
var serialized = editor.serialize()
deepEqual(serialized, {name: "Chuck", email: "chuck@example.com"}, "Expected serialized document to be the hash with the original keys and additional keys")
});
module("expression root value serialization");
test("expression with no hint", function() {
var editor = new FireEditor($('#editor:first'))
editor.loadDocument({"@return": null})
equal(editor.rootEditorNode.getFirstChild().getType(), EditorNodeType.expressionBlock(), "The Root node should be an expression block")
equal(editor.rootEditorNode.getFirstChild().getFirstChild().getType(), EditorNodeType.expression(), "the subnode should be an expression")
equal(editor.rootEditorNode.getFirstChild().getFirstChild().getValue(), "@return", "the subnode value should be the special key")
var serialized = editor.serialize()
deepEqual(serialized, {"@return": null}, "Expected serialized document to be the expression block with the original keys")
});
test("expression with initial hint", function() {
var editor = new FireEditor($('#editor:first'))
editor.loadDocument({"@return(person.name)": null})
equal(editor.rootEditorNode.getFirstChild().getType(), EditorNodeType.expressionBlock(), "The Root node should be an expression block")
equal(editor.rootEditorNode.getFirstChild().getFirstChild().getType(), EditorNodeType.expression(), "the subnode should be an expression")
equal(editor.rootEditorNode.getFirstChild().getFirstChild().getValue(), "@return(person.name)", "the subnode value should be the special key")
editor.rootEditorNode.getFirstChild().getFirstChild().setHint('person.name.email')
equal(editor.rootEditorNode.getFirstChild().getFirstChild().getValue(), "@return(person.name.email)", "after set the hint the key should contain the expression and the new hint")
var serialized = editor.serialize()
deepEqual(serialized, {"@return(person.name.email)": null}, "Expected serialized document to be the expression block with the original expressions")
});
});
body
div#editor
h1#qunit-header QUnit example
h1
h2#qunit-banner
div#qunit-testrunner-toolbar
h2#qunit-userAgent
ol#qunit-tests
div#qunit-fixture test markup, will be hidden