adxutil
Version:
Utilities tools for Askia Design eXtension
792 lines (749 loc) • 371 kB
JavaScript
describe('ADXConfigurator', function () {
var fs = require('fs'),
path = require("path"),
et = require('elementtree'),
ElementTree = et.ElementTree,
common,
ADXConfigurator,
spies = {},
errMsg,
successMsg;
beforeEach(function () {
// Clean the cache, obtain a fresh instance of the object each time
var adxConfigKey = require.resolve('../../app/configurator/ADXConfigurator.js'),
commonKey = require.resolve('../../app/common/common.js');
delete require.cache[commonKey];
common = require('../../app/common/common.js');
delete require.cache[adxConfigKey];
ADXConfigurator = require('../../app/configurator/ADXConfigurator.js').Configurator;
// Messages
errMsg = common.messages.error;
successMsg = common.messages.success;
// Court-circuit the validation outputs
// spies.writeError = spyOn(common, 'writeError');
// spies.writeSuccess = spyOn(common, 'writeSuccess');
// spies.writeMessage = spyOn(common, 'writeMessage');
spies.dirExists = spyOn(common, 'dirExists');
// Court-circuit the access of the filesystem
spies.fs = {
readFile : spyOn(fs, 'readFile'),
writeFile : spyOn(fs, 'writeFile')
};
});
function runSync(fn) {
var wasCalled = false;
runs(function () {
fn(function () {
wasCalled = true;
});
});
waitsFor(function () {
return wasCalled;
});
}
describe("#constructor", function () {
it("should throw an exception when the `path` argument of the constructor is a falsy", function () {
expect(function () {
var configurator = new ADXConfigurator();
}).toThrow(errMsg.invalidPathArg);
});
it("should set the property #path to the object instance", function () {
var configurator = new ADXConfigurator("my/path");
expect(configurator.path).toEqual("my/path");
});
});
describe("#load", function () {
it("should return an error when the `path` specified via the constructor doesn't exist", function () {
spies.dirExists.andCallFake(function (p, cb) {
cb(new Error(errMsg.noSuchFileOrDirectory));
});
runSync(function (done) {
var configurator = new ADXConfigurator("an/invalid/path");
configurator.load(function (err) {
expect(err.message).toEqual(errMsg.noSuchFileOrDirectory);
done();
});
});
});
it("should try to read the config.xml file", function () {
spies.dirExists.andCallFake(function (p, cb) {
cb(null, true);
});
runSync(function (done) {
var configurator = new ADXConfigurator("a/valid/path");
spies.fs.readFile.andCallFake(function (filepath) {
expect(filepath).toEqual(path.join("a/valid/path", "config.xml"));
done();
});
configurator.load();
});
});
it("should return an error when it could not read the config.xml file", function () {
var theError = new Error("A fake error");
spies.dirExists.andCallFake(function (p, cb) {
cb(null, true);
});
spies.fs.readFile.andCallFake(function (p, cb) {
cb(theError, null);
});
runSync(function (done) {
var configurator = new ADXConfigurator("an/invalid/path");
configurator.load(function (err) {
expect(err).toBe(theError);
done();
});
});
});
it("should call the #fromXml() method with the content of the config.xml file", function () {
spies.dirExists.andCallFake(function (p, cb) {
cb(null, true);
});
spies.fs.readFile.andCallFake(function (p, cb) {
cb(null, '<xml></xml>');
});
runSync(function (done) {
var configurator = new ADXConfigurator("an/invalid/path");
var spyFromXml = spyOn(configurator, 'fromXml');
configurator.load(function (err) {
expect(spyFromXml).toHaveBeenCalledWith('<xml></xml>');
done();
});
});
});
});
describe("#fromXml", function () {
beforeEach(function () {
spies.dirExists.andCallFake(function (p, cb) {
cb(null, true);
});
spies.fs.readFile.andCallFake(function (p, cb) {
cb(null, '<control>\n <info>\n <name>the-name</name>\n <guid>the-guid</guid>\n ' +
'<version>the-version</version>\n <date>the-date</date>\n <description><![CDATA[the-description]]></description>\n ' +
'<company>the-company</company>\n <author>the-author</author>\n <site>the-site</site>\n ' +
'<helpURL>the-helpURL</helpURL>\n ' +
'<categories>\n <category>cat-1</category>\n <category>cat-2</category>\n </categories>' +
'\n <style width="200" height="400" />' +
'\n <constraints>\n <constraint on="questions" single="true" multiple="true" open="false" />' +
'\n <constraint on="controls" label="true" responseblock="true" />' +
'\n <constraint on="responses" min="2" max="*" />' +
'\n </constraints>' +
'\n </info></control>');
});
});
it("should set the #xmldoc property with the XML parse result", function () {
var configurator = new ADXConfigurator("an/valid/path");
configurator.fromXml('<control></control>');
expect(configurator.xmldoc instanceof ElementTree).toBe(true);
});
it("should set the #projectType to 'adc' when the root node of the xml is `control`", function () {
var configurator = new ADXConfigurator("an/valid/path");
configurator.fromXml('<control><info><guid>the-guid</guid><name>the-name</name></info></control>');
expect(configurator.projectType).toEqual('adc');
});
it("should set the #projectType to 'adp' when the root node of the xml is `page`", function () {
var configurator = new ADXConfigurator("an/valid/path");
configurator.fromXml('<page><info><guid>the-guid</guid><name>the-name</name></info></page>');
expect(configurator.projectType).toEqual('adp');
});
it("should set the #projectVersion to '2.0.0' by default for the ADC", function () {
var configurator = new ADXConfigurator("an/valid/path");
configurator.fromXml('<control><info><guid>the-guid</guid><name>the-name</name></info></control>');
expect(configurator.projectVersion).toEqual('2.0.0');
});
it("should set the #projectVersion with the value defined in the root node of the ADC", function () {
var configurator = new ADXConfigurator("an/valid/path");
configurator.fromXml('<control version="2.1.0"><info><guid>the-guid</guid><name>the-name</name></info></control>');
expect(configurator.projectVersion).toEqual('2.1.0');
});
it("should set the #projectVersion to '2.1.0' by default for the ADP", function () {
var configurator = new ADXConfigurator("an/valid/path");
configurator.fromXml('<page><info><guid>the-guid</guid><name>the-name</name></info></page>');
expect(configurator.projectVersion).toEqual('2.1.0');
});
it("should set the #projectVersion with the value defined in the root node of the ADP", function () {
var configurator = new ADXConfigurator("an/valid/path");
configurator.fromXml('<page version="2.1.1"><info><guid>the-guid</guid><name>the-name</name></info></page>');
expect(configurator.projectVersion).toEqual('2.1.1');
});
it("should throw an error when the xml root node is not 'control' nor 'page'", function () {
expect(function () {
var configurator = new ADXConfigurator("an/valid/path");
configurator.fromXml('<something><info><guid>the-guid</guid><name>the-name</name></info></something>');
}).toThrow(new Error(common.messages.error.invalidConfigFile))
});
it("should reset the configuration with XML", function () {
runSync(function (done) {
var configurator = new ADXConfigurator("an/valid/path");
configurator.load(function () {
configurator.fromXml('<control>\n <info>\n <name>new-name</name>\n <guid>new-guid</guid>\n ' +
'<version>new-version</version>\n <date>new-date</date>\n <description><![CDATA[new-description]]></description>\n ' +
'<company>new-company</company>\n <author>new-author</author>\n <site>new-site</site>\n ' +
'<helpURL>new-helpURL</helpURL>\n ' +
'<categories>\n <category>new-cat-1</category>\n <category>new-cat-2</category>\n <category>new-cat-3</category>\n </categories>' +
'\n <style width="300" height="500" />' +
'\n <constraints>\n <constraint on="questions" single="false" multiple="true" open="false" numeric="true" />' +
'\n <constraint on="controls" label="false" responseblock="true" checkbox="true" />' +
'\n <constraint on="responses" min="10" max="*" />' +
'\n </constraints>' +
'\n </info></control>');
var result = configurator.toXml();
expect(result ).toEqual('<?xml version="1.0" encoding="utf-8"?>'+
'\n<control xmlns="http://www.askia.com/2.0.0/ADCSchema"' +
'\n xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' +
'\n xsi:schemaLocation="http://www.askia.com/2.0.0/ADCSchema https://raw.githubusercontent.com/AskiaADX/ADXSchema/2.0.0/ADCSchema.xsd"' +
'\n version="2.0.0"' +
'\n askiaCompat="5.3.3">' +
'\n <info>' +
'\n <name>new-name</name>' +
'\n <guid>new-guid</guid>' +
'\n <version>new-version</version>' +
'\n <date>new-date</date>' +
'\n <description><![CDATA[new-description]]></description>' +
'\n <company>new-company</company>' +
'\n <author><![CDATA[new-author]]></author>' +
'\n <site>new-site</site>' +
'\n <helpURL>new-helpURL</helpURL>' +
'\n <categories>' +
'\n <category>new-cat-1</category>' +
'\n <category>new-cat-2</category>' +
'\n <category>new-cat-3</category>' +
'\n </categories>' +
'\n <style width="300" height="500" />' +
'\n <constraints>' +
'\n <constraint on="questions" single="false" multiple="true" open="false" numeric="true" />' +
'\n <constraint on="controls" label="false" responseblock="true" checkbox="true" />' +
'\n <constraint on="responses" min="10" max="*" />' +
'\n </constraints>' +
'\n </info>' +
'\n</control>');
done();
});
});
});
});
describe("#toXml", function () {
beforeEach(function () {
spies.dirExists.andCallFake(function (p, cb) {
cb(null, true);
});
});
it("should return the configuration of ADC 2.0 as XML", function () {
spies.fs.readFile.andCallFake(function (p, cb) {
cb(null, '<control><info><name>the-name</name><guid>the-guid</guid>' +
'<version>the-version</version><date>the-date</date><description><![CDATA[the-description]]></description>' +
'<company>the-company</company><author>the-author</author><site>the-site</site>' +
'<helpURL>the-helpURL</helpURL>' +
'<categories><category>cat-1</category><category>cat-2</category></categories>' +
'<style width="200" height="400" />' +
'<constraints><constraint on="questions" single="true" multiple="true" open="false" />' +
'<constraint on="controls" label="true" responseblock="true" />' +
'<constraint on="responses" min="2" max="*" />' +
'</constraints>' +
'</info>' +
'<outputs defaultOutput="main">' +
'<output id="main">' +
'<description><![CDATA[Main output]]></description>' +
'<content fileName="main.css" type="css" mode="static" position="head" />' +
'<content fileName="main.html" type="html" mode="dynamic" position="placeholder" />' +
'<content fileName="main.js" type="javascript" mode="static" position="foot" />' +
'</output>' +
'<output id="second">' +
'<description><![CDATA[Second output]]></description>' +
'<condition><![CDATA[Browser.Support("javascript")]]></condition>' +
'<content fileName="second.css" type="css" mode="static" position="head" />' +
'<content fileName="second.html" type="html" mode="dynamic" position="placeholder" />' +
'<content fileName="second.js" type="javascript" mode="static" position="foot" />' +
'</output>' +
'<output id="third" defaultGeneration="false" maxIterations="12">' +
'<description><![CDATA[Third output]]></description>' +
'<content fileName="third.css" type="css" mode="static" position="head" >' +
' <attribute name="rel">' +
'<value>alternate</value>' +
'</attribute>' +
'<attribute name="media">' +
'<value>print</value>' +
'</attribute>' +
'</content>' +
'<content fileName="HTML5Shim.js" type="javascript" mode="static" position="head">' +
'<yield>' +
'<![CDATA[' +
'<!--[if lte IE 9]>' +
'<script type="text/javascript" src="{%= CurrentADC.URLTo("static/HTML5Shim.js") %}" ></script>' +
'<![endif]-->' +
']]>' +
'</yield>' +
'</content>'+
'</output>' +
'</outputs>' +
'<properties>' +
'<category id="general" name="General">' +
'<property xsi:type="askiaProperty" id="askia-theme">' +
'<options>' +
'<option value="red-theme" text="Red" />' +
'<option value="blue-theme" text="Blue" />' +
'</options>' +
'</property>' +
'<property xsi:type="standardProperty" id="renderingType" name="Rendering type" type="string">' +
'<description>Type of rendering</description>' +
'<value>classic</value>' +
'<options>' +
'<option value="classic" text="Classic"/>' +
'<option value="image" text="Image"/>' +
'</options>' +
'</property>' +
'<property xsi:type="standardProperty" id="other" name="Open-ended question for semi-open" type="question" open="true" numeric="true">' +
'<description>Additional open-ended question that could be use to emulate semi-open</description>' +
'</property>' +
'</category>' +
'<category id="images" name="Rendering type images">' +
'<property xsi:type="standardProperty" id="singleImage" name="Image for single question" type="file" fileExtension=".png, .gif, .jpg">' +
'<description>Image of single question when the rendering type is image</description>' +
'<value>Single.png</value>' +
'<value theme="red-theme">SingleRed.png</value>' +
'<value theme="blue-theme">SingleBlue.png</value>' +
'</property>' +
'<property xsi:type="standardProperty" id="multipleImage" name="Image for multiple question" type="file" fileExtension=".png, .gif, .jpg">' +
'<description>Image of multiple question when the rendering type is image</description>' +
'<value>Multiple.png</value>' +
'<value theme="red-theme">MultipleRed.png</value>' +
'<value theme="blue-theme">MultipleBlue.png</value>' +
'</property>' +
'</category>' +
'<category id="fake" name="Fake for test">' +
'<property xsi:type="standardProperty" id="testNumber" name="TEST" type="number" min="12" max="100.5" decimal="3" mode="dynamic" visible="false" require="true">' +
'<description>Test number properties</description>' +
'<value>13</value>' +
'</property>' +
'<property xsi:type="standardProperty" id="testColor" name="TEST" type="color" colorFormat="rgb">' +
'<description>Test color properties</description>' +
'<value>255,255,255</value>' +
'</property>' +
'<property xsi:type="standardProperty" id="testQuestion" name="TEST" type="question" chapter="false" single="true" multiple="true" numeric="false" open="false" date="false">' +
'<description>Test question properties</description>' +
'<value></value>' +
'</property>' +
'<property xsi:type="standardProperty" id="testFile" name="TEST" type="file" fileExtension=".test, .test2">' +
'<description>Test file properties</description>' +
'<value>file.test</value>' +
'</property>' +
'<property xsi:type="standardProperty" id="testString" name="TEST" type="string" pattern=".+@.+">' +
'<description>Test string properties</description>' +
'<value>test@test.com</value>' +
'</property>' +
'</category>' +
'</properties>' +
'</control>');
});
runSync(function (done) {
var configurator = new ADXConfigurator("an/valid/path");
configurator.load(function () {
var result = configurator.toXml();
expect(result ).toEqual('<?xml version="1.0" encoding="utf-8"?>'+
'\n<control xmlns="http://www.askia.com/2.0.0/ADCSchema"' +
'\n xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' +
'\n xsi:schemaLocation="http://www.askia.com/2.0.0/ADCSchema https://raw.githubusercontent.com/AskiaADX/ADXSchema/2.0.0/ADCSchema.xsd"' +
'\n version="2.0.0"' +
'\n askiaCompat="5.3.3">' +
'\n <info>' +
'\n <name>the-name</name>' +
'\n <guid>the-guid</guid>' +
'\n <version>the-version</version>' +
'\n <date>the-date</date>' +
'\n <description><![CDATA[the-description]]></description>' +
'\n <company>the-company</company>' +
'\n <author><![CDATA[the-author]]></author>' +
'\n <site>the-site</site>' +
'\n <helpURL>the-helpURL</helpURL>' +
'\n <categories>' +
'\n <category>cat-1</category>' +
'\n <category>cat-2</category>' +
'\n </categories>' +
'\n <style width="200" height="400" />' +
'\n <constraints>' +
'\n <constraint on="questions" single="true" multiple="true" open="false" />' +
'\n <constraint on="controls" label="true" responseblock="true" />' +
'\n <constraint on="responses" min="2" max="*" />' +
'\n </constraints>' +
'\n </info>' +
'\n <outputs defaultOutput="main">' +
'\n <output id="main">' +
'\n <description><![CDATA[Main output]]></description>' +
'\n <content fileName="main.css" type="css" mode="static" position="head" />' +
'\n <content fileName="main.html" type="html" mode="dynamic" position="placeholder" />' +
'\n <content fileName="main.js" type="javascript" mode="static" position="foot" />' +
'\n </output>' +
'\n <output id="second">' +
'\n <description><![CDATA[Second output]]></description>' +
'\n <condition><![CDATA[Browser.Support("javascript")]]></condition>' +
'\n <content fileName="second.css" type="css" mode="static" position="head" />' +
'\n <content fileName="second.html" type="html" mode="dynamic" position="placeholder" />' +
'\n <content fileName="second.js" type="javascript" mode="static" position="foot" />' +
'\n </output>' +
'\n <output id="third" defaultGeneration="false" maxIterations="12">' +
'\n <description><![CDATA[Third output]]></description>' +
'\n <content fileName="third.css" type="css" mode="static" position="head">' +
'\n <attribute name="rel">' +
'\n <value><![CDATA[alternate]]></value>' +
'\n </attribute>' +
'\n <attribute name="media">' +
'\n <value><![CDATA[print]]></value>' +
'\n </attribute>' +
'\n </content>' +
'\n <content fileName="HTML5Shim.js" type="javascript" mode="static" position="head">' +
'\n <yield>' +
'<![CDATA[<!--[if lte IE 9]><script type="text/javascript" src="{%= CurrentADC.URLTo("static/HTML5Shim.js") %}" ></script><![endif]-->]]>' +
'</yield>' +
'\n </content>' +
'\n </output>' +
'\n </outputs>' +
'\n <properties>' +
'\n <category id="general" name="General">' +
'\n <property xsi:type="standardProperty" id="renderingType" name="Rendering type" type="string">' +
'\n <description><![CDATA[Type of rendering]]></description>' +
'\n <value><![CDATA[classic]]></value>' +
'\n <options>' +
'\n <option value="classic" text="Classic" />' +
'\n <option value="image" text="Image" />' +
'\n </options>' +
'\n </property>' +
'\n <property xsi:type="standardProperty" id="other" name="Open-ended question for semi-open" type="question" numeric="true" open="true">' +
'\n <description><![CDATA[Additional open-ended question that could be use to emulate semi-open]]></description>' +
'\n </property>' +
'\n </category>' +
'\n <category id="images" name="Rendering type images">' +
'\n <property xsi:type="standardProperty" id="singleImage" name="Image for single question" type="file" fileExtension=".png, .gif, .jpg">' +
'\n <description><![CDATA[Image of single question when the rendering type is image]]></description>' +
'\n <value><![CDATA[Single.png]]></value>' +
'\n </property>' +
'\n <property xsi:type="standardProperty" id="multipleImage" name="Image for multiple question" type="file" fileExtension=".png, .gif, .jpg">' +
'\n <description><![CDATA[Image of multiple question when the rendering type is image]]></description>' +
'\n <value><![CDATA[Multiple.png]]></value>' +
'\n </property>' +
'\n </category>' +
'\n <category id="fake" name="Fake for test">' +
'\n <property xsi:type="standardProperty" id="testNumber" name="TEST" type="number" mode="dynamic" require="true" visible="false" min="12" max="100.5" decimal="3">' +
'\n <description><![CDATA[Test number properties]]></description>' +
'\n <value><![CDATA[13]]></value>' +
'\n </property>' +
'\n <property xsi:type="standardProperty" id="testColor" name="TEST" type="color" colorFormat="rgb">' +
'\n <description><![CDATA[Test color properties]]></description>' +
'\n <value><![CDATA[255,255,255]]></value>' +
'\n </property>' +
'\n <property xsi:type="standardProperty" id="testQuestion" name="TEST" type="question" chapter="false" single="true" multiple="true" numeric="false" open="false" date="false">' +
'\n <description><![CDATA[Test question properties]]></description>' +
'\n <value></value>' +
'\n </property>' +
'\n <property xsi:type="standardProperty" id="testFile" name="TEST" type="file" fileExtension=".test, .test2">' +
'\n <description><![CDATA[Test file properties]]></description>' +
'\n <value><![CDATA[file.test]]></value>' +
'\n </property>' +
'\n <property xsi:type="standardProperty" id="testString" name="TEST" type="string" pattern=".+@.+">' +
'\n <description><![CDATA[Test string properties]]></description>' +
'\n <value><![CDATA[test@test.com]]></value>' +
'\n </property>' +
'\n </category>' +
'\n </properties>' +
'\n</control>');
done();
});
});
});
it("should return the configuration of ADC 2.1 as XML", function () {
spies.fs.readFile.andCallFake(function (p, cb) {
cb(null, '<control version="2.1.0"><info><name>the-name</name><guid>the-guid</guid>' +
'<version>the-version</version><date>the-date</date><description><![CDATA[the-description]]></description>' +
'<company>the-company</company><author>the-author</author><site>the-site</site>' +
'<helpURL>the-helpURL</helpURL>' +
'<categories><category>cat-1</category><category>cat-2</category></categories>' +
'<style width="200" height="400" />' +
'<constraints><constraint on="questions" single="true" multiple="true" open="false" />' +
'<constraint on="controls" label="true" responseblock="true" />' +
'<constraint on="responses" min="2" max="*" />' +
'</constraints>' +
'</info>' +
'<outputs defaultOutput="main">' +
'<output id="main">' +
'<description><![CDATA[Main output]]></description>' +
'<content fileName="main.css" type="css" mode="static" position="head" />' +
'<content fileName="main.html" type="html" mode="dynamic" position="placeholder" />' +
'<content fileName="main.js" type="javascript" mode="static" position="foot" />' +
'</output>' +
'<output id="second">' +
'<description><![CDATA[Second output]]></description>' +
'<condition><![CDATA[Browser.Support("javascript")]]></condition>' +
'<content fileName="second.css" type="css" mode="static" position="head" />' +
'<content fileName="second.html" type="html" mode="dynamic" position="placeholder" />' +
'<content fileName="second.js" type="javascript" mode="static" position="foot" />' +
'</output>' +
'<output id="third" defaultGeneration="false" maxIterations="12">' +
'<description><![CDATA[Third output]]></description>' +
'<content fileName="third.css" type="css" mode="static" position="head" >' +
' <attribute name="rel">' +
'<value>alternate</value>' +
'</attribute>' +
'<attribute name="media">' +
'<value>print</value>' +
'</attribute>' +
'</content>' +
'<content fileName="HTML5Shim.js" type="javascript" mode="static" position="head">' +
'<yield>' +
'<![CDATA[' +
'<!--[if lte IE 9]>' +
'<script type="text/javascript" src="{%= CurrentADC.URLTo("static/HTML5Shim.js") %}" ></script>' +
'<![endif]-->' +
']]>' +
'</yield>' +
'</content>'+
'</output>' +
'</outputs>' +
'<properties>' +
'<category id="general" name="General">' +
'<property xsi:type="askiaProperty" id="askia-theme">' +
'<options>' +
'<option value="red-theme" text="Red" />' +
'<option value="blue-theme" text="Blue" />' +
'</options>' +
'</property>' +
'<property xsi:type="standardProperty" id="renderingType" name="Rendering type" type="string">' +
'<description>Type of rendering</description>' +
'<value>classic</value>' +
'<options>' +
'<option value="classic" text="Classic"/>' +
'<option value="image" text="Image"/>' +
'</options>' +
'</property>' +
'<property xsi:type="standardProperty" id="other" name="Open-ended question for semi-open" type="question" open="true" numeric="true">' +
'<description>Additional open-ended question that could be use to emulate semi-open</description>' +
'</property>' +
'</category>' +
'<category id="images" name="Rendering type images">' +
'<property xsi:type="standardProperty" id="singleImage" name="Image for single question" type="file" fileExtension=".png, .gif, .jpg">' +
'<description>Image of single question when the rendering type is image</description>' +
'<value>Single.png</value>' +
'<value theme="red-theme">SingleRed.png</value>' +
'<value theme="blue-theme">SingleBlue.png</value>' +
'</property>' +
'<property xsi:type="standardProperty" id="multipleImage" name="Image for multiple question" type="file" fileExtension=".png, .gif, .jpg">' +
'<description>Image of multiple question when the rendering type is image</description>' +
'<value>Multiple.png</value>' +
'<value theme="red-theme">MultipleRed.png</value>' +
'<value theme="blue-theme">MultipleBlue.png</value>' +
'</property>' +
'</category>' +
'<category id="fake" name="Fake for test">' +
'<property xsi:type="standardProperty" id="testNumber" name="TEST" type="number" min="12" max="100.5" decimal="3" mode="dynamic" visible="false" require="true">' +
'<description>Test number properties</description>' +
'<value>13</value>' +
'</property>' +
'<property xsi:type="standardProperty" id="testColor" name="TEST" type="color" colorFormat="rgb">' +
'<description>Test color properties</description>' +
'<value>255,255,255</value>' +
'</property>' +
'<property xsi:type="standardProperty" id="testQuestion" name="TEST" type="question" chapter="false" single="true" multiple="true" numeric="false" open="false" date="false">' +
'<description>Test question properties</description>' +
'<value></value>' +
'</property>' +
'<property xsi:type="standardProperty" id="testFile" name="TEST" type="file" fileExtension=".test, .test2">' +
'<description>Test file properties</description>' +
'<value>file.test</value>' +
'</property>' +
'<property xsi:type="standardProperty" id="testString" name="TEST" type="string" pattern=".+@.+">' +
'<description>Test string properties</description>' +
'<value>test@test.com</value>' +
'</property>' +
'</category>' +
'</properties>' +
'</control>');
});
runSync(function (done) {
var configurator = new ADXConfigurator("an/valid/path");
configurator.load(function () {
var result = configurator.toXml();
expect(result ).toEqual('<?xml version="1.0" encoding="utf-8"?>'+
'\n<control xmlns="http://www.askia.com/2.1.0/ADCSchema"' +
'\n xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' +
'\n xsi:schemaLocation="http://www.askia.com/2.1.0/ADCSchema https://raw.githubusercontent.com/AskiaADX/ADXSchema/2.1.0/ADCSchema.xsd"' +
'\n version="2.1.0"' +
'\n askiaCompat="5.4.2">' +
'\n <info>' +
'\n <name>the-name</name>' +
'\n <guid>the-guid</guid>' +
'\n <version>the-version</version>' +
'\n <date>the-date</date>' +
'\n <description><![CDATA[the-description]]></description>' +
'\n <company>the-company</company>' +
'\n <author><![CDATA[the-author]]></author>' +
'\n <site>the-site</site>' +
'\n <helpURL>the-helpURL</helpURL>' +
'\n <categories>' +
'\n <category>cat-1</category>' +
'\n <category>cat-2</category>' +
'\n </categories>' +
'\n <constraints>' +
'\n <constraint on="questions" single="true" multiple="true" open="false" />' +
'\n <constraint on="controls" label="true" responseblock="true" />' +
'\n <constraint on="responses" min="2" max="*" />' +
'\n </constraints>' +
'\n </info>' +
'\n <outputs defaultOutput="main">' +
'\n <output id="main">' +
'\n <description><![CDATA[Main output]]></description>' +
'\n <content fileName="main.css" type="css" mode="static" position="head" />' +
'\n <content fileName="main.html" type="html" mode="dynamic" position="placeholder" />' +
'\n <content fileName="main.js" type="javascript" mode="static" position="foot" />' +
'\n </output>' +
'\n <output id="second">' +
'\n <description><![CDATA[Second output]]></description>' +
'\n <condition><![CDATA[Browser.Support("javascript")]]></condition>' +
'\n <content fileName="second.css" type="css" mode="static" position="head" />' +
'\n <content fileName="second.html" type="html" mode="dynamic" position="placeholder" />' +
'\n <content fileName="second.js" type="javascript" mode="static" position="foot" />' +
'\n </output>' +
'\n <output id="third" defaultGeneration="false" maxIterations="12">' +
'\n <description><![CDATA[Third output]]></description>' +
'\n <content fileName="third.css" type="css" mode="static" position="head">' +
'\n <attribute name="rel">' +
'\n <value><![CDATA[alternate]]></value>' +
'\n </attribute>' +
'\n <attribute name="media">' +
'\n <value><![CDATA[print]]></value>' +
'\n </attribute>' +
'\n </content>' +
'\n <content fileName="HTML5Shim.js" type="javascript" mode="static" position="head">' +
'\n <yield>' +
'<![CDATA[<!--[if lte IE 9]><script type="text/javascript" src="{%= CurrentADC.URLTo("static/HTML5Shim.js") %}" ></script><![endif]-->]]>' +
'</yield>' +
'\n </content>' +
'\n </output>' +
'\n </outputs>' +
'\n <properties>' +
'\n <category id="general" name="General">' +
'\n <property xsi:type="standardProperty" id="renderingType" name="Rendering type" type="string">' +
'\n <description><![CDATA[Type of rendering]]></description>' +
'\n <value><![CDATA[classic]]></value>' +
'\n <options>' +
'\n <option value="classic" text="Classic" />' +
'\n <option value="image" text="Image" />' +
'\n </options>' +
'\n </property>' +
'\n <property xsi:type="standardProperty" id="other" name="Open-ended question for semi-open" type="question" numeric="true" open="true">' +
'\n <description><![CDATA[Additional open-ended question that could be use to emulate semi-open]]></description>' +
'\n </property>' +
'\n </category>' +
'\n <category id="images" name="Rendering type images">' +
'\n <property xsi:type="standardProperty" id="singleImage" name="Image for single question" type="file" fileExtension=".png, .gif, .jpg">' +
'\n <description><![CDATA[Image of single question when the rendering type is image]]></description>' +
'\n <value><![CDATA[Single.png]]></value>' +
'\n </property>' +
'\n <property xsi:type="standardProperty" id="multipleImage" name="Image for multiple question" type="file" fileExtension=".png, .gif, .jpg">' +
'\n <description><![CDATA[Image of multiple question when the rendering type is image]]></description>' +
'\n <value><![CDATA[Multiple.png]]></value>' +
'\n </property>' +
'\n </category>' +
'\n <category id="fake" name="Fake for test">' +
'\n <property xsi:type="standardProperty" id="testNumber" name="TEST" type="number" mode="dynamic" require="true" visible="false" min="12" max="100.5" decimal="3">' +
'\n <description><![CDATA[Test number properties]]></description>' +
'\n <value><![CDATA[13]]></value>' +
'\n </property>' +
'\n <property xsi:type="standardProperty" id="testColor" name="TEST" type="color" colorFormat="rgb">' +
'\n <description><![CDATA[Test color properties]]></description>' +
'\n <value><![CDATA[255,255,255]]></value>' +
'\n </property>' +
'\n <property xsi:type="standardProperty" id="testQuestion" name="TEST" type="question" chapter="false" single="true" multiple="true" numeric="false" open="false" date="false">' +
'\n <description><![CDATA[Test question properties]]></description>' +
'\n <value></value>' +
'\n </property>' +
'\n <property xsi:type="standardProperty" id="testFile" name="TEST" type="file" fileExtension=".test, .test2">' +
'\n <description><![CDATA[Test file properties]]></description>' +
'\n <value><![CDATA[file.test]]></value>' +
'\n </property>' +
'\n <property xsi:type="standardProperty" id="testString" name="TEST" type="string" pattern=".+@.+">' +
'\n <description><![CDATA[Test string properties]]></description>' +
'\n <value><![CDATA[test@test.com]]></value>' +
'\n </property>' +
'\n </category>' +
'\n </properties>' +
'\n</control>');
done();
});
});
});
it("should return the configuration of ADP 2.1 as XML", function () {
spies.fs.readFile.andCallFake(function (p, cb) {
cb(null, '<page><info><name>the-name</name><guid>the-guid</guid>' +
'<version>the-version</version><date>the-date</date><description><![CDATA[the-description]]></description>' +
'<company>the-company</company><author>the-author</author><site>the-site</site>' +
'<helpURL>the-helpURL</helpURL>' +
'</info>' +
'<outputs defaultOutput="main">' +
'<output id="main" masterPage="main.html">' +
'<description><![CDATA[Main output]]></description>' +
'<content fileName="main.css" type="css" mode="static" position="head" />' +
'<content fileName="main.js" type="javascript" mode="static" position="foot" />' +
'</output>' +
'<output id="second" masterPage="second.html">' +
'<description><![CDATA[Second output]]></description>' +
'<condition><![CDATA[Browser.Support("javascript")]]></condition>' +
'<content fileName="second.css" type="css" mode="static" position="head" />' +
'<content fileName="second.js" type="javascript" mode="static" position="foot" />' +
'</output>' +
'<output id="third" masterPage="third.html">' +
'<description><![CDATA[Third output]]></description>' +
'<content fileName="third.css" type="css" mode="static" position="head" >' +
' <attribute name="rel">' +
'<value>alternate</value>' +
'</attribute>' +
'<attribute name="media">' +
'<value>print</value>' +
'</attribute>' +
'</content>' +
'<content fileName="HTML5Shim.js" type="javascript" mode="static" position="head">' +
'<yield>' +
'<![CDATA[' +
'<!--[if lte IE 9]>' +
'<script type="text/javascript" src="{%= CurrentADC.URLTo("static/HTML5Shim.js") %}" ></script>' +
'<![endif]-->' +
']]>' +
'</yield>' +
'</content>'+
'</output>' +
'</outputs>' +
'<properties>' +
'<category id="general" name="General">' +
'<property xsi:type="standardProperty" id="renderingType" name="Rendering type" type="string">' +
'<description>Type of rendering</description>' +
'<value>classic</value>' +
'<options>' +
'<option value="classic" text="Classic"/>' +
'<option value="image" text="Image"/>' +
'</options>' +
'</property>' +
'</category>' +
'<category id="images" name="Rendering type images">' +
'<property xsi:type="standardProperty" id="singleImage" name="Image for single question" type="file" fileExtension=".png, .gif, .jpg">' +
'<description>Image of single question when the rendering type is image</description>' +
'<value>Single.png</value>' +
'</property>' +
'<property xsi:type="standardProperty" id="multipleImage" name="Image for multiple question" type="file" fileExtension=".png, .gif, .jpg">' +
'<description>Image of multiple question when the rendering type is image</description>' +
'<value>Multiple.png</value>' +
'</property>' +
'</category>' +
'<category id="fake" name="Fake for test">' +
'<property xsi:type="standardProperty" id="testNumber" name="TEST" type="number" min="12" max="100.5" decimal="3" mode="dynamic" visible="false" require="true">' +
'<description>Test number properties</description>' +
'<value>13</value>' +
'</property>' +
'<property xsi:type="standardProperty" id="testColor" name="TEST" type="color" colorFormat="rgb">' +
'<description>Test color properties</description>' +
'<value>255,255,255</value>' +
'</property>' +
'<property xsi:type="standardProperty" id="testFile" name="TEST" type="file" fileExtension=".test, .test2">' +
'<description>Test file properties</description>' +
'<value>file.test</value>' +
'</property>' +
'<property xsi:type="standardProperty" id="testString" name="TEST" type="string" pattern=".+@.+">' +
'<description>Test string properties</description>' +
'<value>test@test.com</value>' +
'</property>' +
'</cat