Commit e61f1354 authored by Boris Kocherov's avatar Boris Kocherov

tests: add getContent test fix render() test

parent d1f6bc3a
/*jslint nomen: true*/ /*jslint nomen: true*/
/*global console, RSVP, renderJS, QUnit, window, document*/ /*global console, RSVP, renderJS, QUnit, window, document,
__RenderJSGadget, URL*/
(function (document, renderJS, QUnit) { (function (document, renderJS, QUnit) {
"use strict"; "use strict";
var test = QUnit.test, var test = QUnit.test,
module = QUnit.module, module = QUnit.module,
root_gadget_defer = RSVP.defer(), RenderJSGadget = __RenderJSGadget,
// root_gadget_defer = RSVP.defer(),
jsonform_url = '../jsonform.gadget.html'; jsonform_url = '../jsonform.gadget.html';
// Keep track of the root gadget function create_gadget(__aq_parent) {
renderJS(window) var gadget = new RenderJSGadget();
.ready(function () { gadget.__sub_gadget_dict = {};
root_gadget_defer.resolve(this); gadget.__aq_parent = __aq_parent;
// return gadget.declareGadget(jsonform_url, {
return gadget.declareGadget((new URL(jsonform_url, window.location)), {
// sandbox: "iframe",
element: document.querySelector('#qunit-fixture'),
scope: 'foobar'
}); });
}
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// declareGadget // render
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
module("jsonform.declareGadget", { module("jsonform.general");
beforeEach: function () { test('JSON Form render', function (assert) {
renderJS.clearGadgetKlassList(); var done = assert.async(),
} gadget;
}); create_gadget(function (method_name, argument_list) {
test('JSON Form gadget can be loaded', function (assert) { if (method_name === "notifyValid") {
var done = assert.async(); assert.ok(argument_list, "form correctly filled");
assert.expect(1); return "result correctly fetched from parent";
root_gadget_defer.promise }
.then(function (root_gadget) { throw new renderJS.AcquisitionError("Can not handle " + method_name);
return root_gadget.declareGadget( })
jsonform_url, .push(function (g) {
{ gadget = g;
scope: "iframe", return gadget.render({
element: document.querySelector('#qunit-fixture') key: "foo"
} });
);
}) })
.then(function (gadget) { .push(function (element) {
assert.ok(true, gadget); assert.ok(element, "gadget rendered");
}) })
.fail(function (error) { .push(undefined, function (error) {
assert.ok(false, error); assert.notOk(error, "issue in gadget");
console.warn(error);
throw error;
}) })
.always(function () { .push(function () {
done(); done();
}); });
}); });
}(document, renderJS, QUnit)); test('JSON Form getContent', function (assert) {
var done = assert.async(),
gadget,
key = "foo_key",
schema = {
"properties": {
"foo": {"type": "integer"},
"bar": {"type": "string"}
},
required: ["foo"]
},
value = {foo: 1, bar: "fsdfs"},
schema_orig = JSON.parse(JSON.stringify(schema));
create_gadget(function (method_name, argument_list) {
if (method_name === "notifyValid") {
assert.ok(argument_list, "form correctly filled");
return "result correctly fetched from parent";
}
throw new renderJS.AcquisitionError("Can not handle " + method_name);
})
.push(function (g) {
gadget = g;
return gadget.render({
key: key,
schema: schema,
value: value
});
})
.push(function (element) {
assert.ok(element, "gadget rendered");
return gadget.getContent();
})
.push(function (json_document) {
assert.deepEqual(schema, schema_orig, "schema not change (side effect absent)");
assert.deepEqual(JSON.parse(json_document[key]), value, "returned value equal");
})
.push(undefined, function (error) {
assert.notOk(error, "issue in gadget");
})
.push(function () {
done();
});
});
}(document, renderJS, QUnit));
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment