Commit a5a10bb8 authored by Boris Kocherov's avatar Boris Kocherov

tests: test viewer display validation and changed status

parent 0d4890f6
......@@ -38,6 +38,38 @@
});
}
function updateTextContent(g) {
return g.getDeclaredGadget("form_view")
.push(function (form_view) {
return form_view.getContent();
})
.push(function (ret) {
var valid = g.state.valid,
changed = g.state.changed;
if (ret === undefined) {
ret = {};
}
if (typeof valid === "boolean") {
if (valid) {
valid = "form filed valid";
} else {
valid = "form filed invalid";
}
} else {
valid = "valid status unknown";
}
if (changed) {
changed = 'changed\n';
} else {
changed = '';
}
document.getElementById("json_document_content").textContent =
valid + '\n' +
changed +
JSON.stringify(ret, null, 2);
});
}
rJS(window)
.ready(function (g) {
var url_list = [];
......@@ -97,11 +129,19 @@
]);
});
})
.allowPublicAcquisition("notifyValid", function () {
return;
.allowPublicAcquisition("notifyValid", function (arr, scope) {
if (scope === "form_view") {
this.changeState({
valid: true
});
}
})
.allowPublicAcquisition("notifyInvalid", function () {
return;
.allowPublicAcquisition("notifyInvalid", function (arr, scope) {
if (scope === "form_view") {
this.changeState({
valid: false
});
}
})
.allowPublicAcquisition("notifyChange", function (arr, scope) {
var gadget = this;
......@@ -125,12 +165,14 @@
return g.getContent();
})
.push(function (ret) {
gadget.props.valid = null;
if (ret !== gadget.props.documents[0]) {
var test = gadget.props.schema + ': ' + ret;
test = gadget.props.test_data[test];
console.log(test.schema);
console.log(test.data);
return gadget.changeState({
changed: false,
schema: test.schema,
json_document: test.data
});
......@@ -138,40 +180,45 @@
});
}
if (scope === "form_view") {
return this.getDeclaredGadget("form_view")
.push(function (g) {
return g.getContent();
})
.push(function (ret) {
if (ret === undefined) {
ret = {};
}
document.getElementById("json_document_content").textContent =
JSON.stringify(ret, null, " ");
return gadget.changeState({
changed: true
})
.push(function () {
return updateTextContent(gadget);
});
}
})
.onStateChange(function () {
var g = this;
return g.getDeclaredGadget("form_view")
.push(function (form_view) {
return form_view.render({
value: g.state.json_document,
schema: g.state.schema,
schema_url: g.state.schema_url
.onStateChange(function (modification) {
var g = this,
queue = RSVP.Queue();
if (modification.hasOwnProperty('json_document') ||
modification.hasOwnProperty('schema') ||
modification.hasOwnProperty('schema_url')) {
queue
.push(function () {
return g.getDeclaredGadget("form_view");
})
.push(function () {
return form_view.getContent();
})
.push(function (ret) {
if (ret === undefined) {
ret = {};
}
g.state.json_document = ret;
document.getElementById("json_document_content").textContent =
JSON.stringify(ret, null, 2);
.push(function (form_view) {
return form_view.render({
value: g.state.json_document,
schema: g.state.schema,
schema_url: g.state.schema_url
});
});
})
.push(undefined, function (error) {
console.log(error);
})
.push(function () {
return updateTextContent(g);
});
}
if (modification.hasOwnProperty('valid')) {
queue
.push(function () {
return updateTextContent(g);
});
}
return queue;
});
}(window, rJS, jIO));
\ 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