Commit e61f1354 authored by Boris Kocherov's avatar Boris Kocherov

tests: add getContent test fix render() test

parent d1f6bc3a
/*jslint nomen: true*/
/*global console, RSVP, renderJS, QUnit, window, document*/
/*global console, RSVP, renderJS, QUnit, window, document,
__RenderJSGadget, URL*/
(function (document, renderJS, QUnit) {
"use strict";
var test = QUnit.test,
module = QUnit.module,
root_gadget_defer = RSVP.defer(),
RenderJSGadget = __RenderJSGadget,
// root_gadget_defer = RSVP.defer(),
jsonform_url = '../jsonform.gadget.html';
// Keep track of the root gadget
renderJS(window)
.ready(function () {
root_gadget_defer.resolve(this);
function create_gadget(__aq_parent) {
var gadget = new RenderJSGadget();
gadget.__sub_gadget_dict = {};
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", {
beforeEach: function () {
renderJS.clearGadgetKlassList();
module("jsonform.general");
test('JSON Form render', function (assert) {
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);
root_gadget_defer.promise
.then(function (root_gadget) {
return root_gadget.declareGadget(
jsonform_url,
{
scope: "iframe",
element: document.querySelector('#qunit-fixture')
});
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();
})
.then(function (gadget) {
assert.ok(true, gadget);
.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");
})
.fail(function (error) {
assert.ok(false, error);
console.warn(error);
throw error;
.push(undefined, function (error) {
assert.notOk(error, "issue in gadget");
})
.always(function () {
.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