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) {
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: "foo"
});
})
.push(function (element) {
assert.ok(element, "gadget rendered");
})
.push(undefined, function (error) {
assert.notOk(error, "issue in gadget");
})
.push(function () {
done();
}); });
test('JSON Form gadget can be loaded', function (assert) { });
var done = assert.async();
assert.expect(1); test('JSON Form getContent', function (assert) {
root_gadget_defer.promise var done = assert.async(),
.then(function (root_gadget) { gadget,
return root_gadget.declareGadget( key = "foo_key",
jsonform_url, schema = {
{ "properties": {
scope: "iframe", "foo": {"type": "integer"},
element: document.querySelector('#qunit-fixture') "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();
}) })
.then(function (gadget) { .push(function (json_document) {
assert.ok(true, gadget); assert.deepEqual(schema, schema_orig, "schema not change (side effect absent)");
assert.deepEqual(JSON.parse(json_document[key]), value, "returned value equal");
}) })
.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)); }(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