Commit 59df8ce2 authored by Boris Kocherov's avatar Boris Kocherov
parent e61f1354
......@@ -3,6 +3,7 @@ renderjs.js
rsvp.js
jio.js
handlebars.js
test_index.js
font-awesome/
node_modules/
npm-debug.log
......
......@@ -31,6 +31,27 @@ module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-open');
grunt.registerMultiTask('files_to_json', 'Simple plugin to create a list of files', function () {
// Iterate over all specified file groups.
this.files.forEach(function (f) {
var output = '[\n';
output += f.src.filter(function (filepath) {
// Warn on and remove invalid source files (if nonull was set).
if (!grunt.file.exists(filepath)) {
grunt.log.warn('Source file "' + filepath + '" not found.');
return false;
}
return true;
}).map(function (filepath) {
return ' \"' + filepath + '\"';
}).join(grunt.util.normalizelf(',\n'));
output += '\n]';
// Write the destination file.
grunt.file.write(f.dest, output);
});
});
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
......@@ -141,6 +162,12 @@ module.exports = function (grunt) {
all: ['test/index.html']
},
files_to_json: {
files: {
src: 'node_modules/json-schema-test-suite/tests/draft7/**/*.json',
dest: 'test_index.json'
}
},
connect: {
client: {
options: {
......@@ -164,6 +191,6 @@ module.exports = function (grunt) {
grunt.registerTask('all', ['less', 'lint']);
grunt.registerTask('lint', ['jslint']);
grunt.registerTask('test', ['copy', 'qunit']);
grunt.registerTask('server', ['connect:client', 'watch']);
grunt.registerTask('server', ['connect:client', 'files_to_json', 'watch']);
};
......@@ -19,6 +19,7 @@
"grunt-contrib-qunit": "~2.0.0",
"grunt-contrib-watch": "~0.5.3",
"grunt-contrib-less": "",
"json-schema-test-suite": "git+https://github.com/json-schema-org/JSON-Schema-Test-Suite.git",
"grunt-jslint": "1.1.14",
"grunt-open": "~0.2.2",
"qunitjs": "2.3.0",
......
......@@ -7,6 +7,7 @@
<link rel="stylesheet" href="../node_modules/qunitjs/qunit/qunit.css" type="text/css" media="screen"/>
<script src="../rsvp.js" type="text/javascript"></script>
<script src="../renderjs.js" type="text/javascript"></script>
<script src="../jio.js" type="text/javascript"></script>
<script src="../node_modules/qunitjs/qunit/qunit.js" type="text/javascript"></script>
<script src="../node_modules/sinon/pkg/sinon.js" type="text/javascript"></script>
<script src="jsonform_test.js" type="text/javascript"></script>
......
/*jslint nomen: true*/
/*global console, RSVP, renderJS, QUnit, window, document,
__RenderJSGadget, URL*/
(function (document, renderJS, QUnit) {
__RenderJSGadget, URL, jIO*/
(function (document, renderJS, QUnit, jIO) {
"use strict";
var test = QUnit.test,
module = QUnit.module,
RenderJSGadget = __RenderJSGadget,
// root_gadget_defer = RSVP.defer(),
jsonform_url = '../jsonform.gadget.html';
QUnit.config.autostart = false;
function downloadJSON(url) {
return RSVP.Queue()
.push(function () {
return jIO.util.ajax({
url: url,
dataType: "json"
});
})
.push(undefined, function (error) {
console.log(error);
throw error;
})
.push(function (evt) {
return evt.target.response;
});
}
function create_gadget(__aq_parent) {
var gadget = new RenderJSGadget();
gadget.__sub_gadget_dict = {};
......@@ -96,4 +114,75 @@
});
});
}(document, renderJS, QUnit));
\ No newline at end of file
function create_callback(schema, value) {
return function (assert) {
var done = assert.async(),
gadget,
key = "foo_key",
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();
});
};
}
RSVP.Queue()
.push(function () {
return downloadJSON("../test_index.json");
})
.push(function (list) {
var i,
tasks = [];
for (i = 0; i < list.length; i += 1) {
tasks.push(downloadJSON('../' + list[i]));
}
return RSVP.all(tasks);
})
.push(function (list) {
var i,
k,
z,
m,
t;
for (i = 0; i < list.length; i += 1) {
for (k = 0; k < list[i].length; k += 1) {
m = list[i][k];
module(m.description);
for (z = 0; z < m.tests.length; z += 1) {
t = m.tests[z];
test(t.description, create_callback(m.schema, t.data, t.valid));
}
}
}
})
.push(function () {
QUnit.start();
});
}(document, renderJS, QUnit, 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