56 lines
2.5 KiB
JavaScript
56 lines
2.5 KiB
JavaScript
const fs = require("fs");
|
|
const os = require("os");
|
|
const path = require("path");
|
|
const test = require("node:test");
|
|
const assert = require("node:assert/strict");
|
|
|
|
const { loadSpecs, generateProjectFiles, generatePreview, renderXfdl } = require("../index");
|
|
|
|
test("spec loader discovers app and form specs", () => {
|
|
const { appSpec, forms } = loadSpecs();
|
|
assert.equal(appSpec.projectName, "HanwhaNexacroDemo");
|
|
assert.equal(forms.length, 5);
|
|
assert.ok(forms.some((form) => form.formId === "frmUploadValidation"));
|
|
});
|
|
|
|
test("project generator writes required Nexacro files", () => {
|
|
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "nexacro-src-"));
|
|
const { appSpec, forms } = loadSpecs();
|
|
generateProjectFiles(appSpec, forms, tempDir);
|
|
|
|
assert.ok(fs.existsSync(path.join(tempDir, "HanwhaNexacroDemo.xprj")));
|
|
assert.ok(fs.existsSync(path.join(tempDir, "Application_Desktop.xadl")));
|
|
assert.ok(fs.existsSync(path.join(tempDir, "environment.xml")));
|
|
assert.ok(fs.existsSync(path.join(tempDir, "typedefinition.xml")));
|
|
assert.ok(fs.existsSync(path.join(tempDir, "appvariables.xml")));
|
|
assert.ok(fs.existsSync(path.join(tempDir, "Base", "frmLogin.xfdl")));
|
|
assert.ok(fs.existsSync(path.join(tempDir, "FrameBase", "Form_Work.xfdl")));
|
|
assert.ok(fs.readFileSync(path.join(tempDir, "HanwhaNexacroDemo.xprj"), "utf8").includes("Application_Desktop.xadl"));
|
|
|
|
const projectBuffer = fs.readFileSync(path.join(tempDir, "HanwhaNexacroDemo.xprj"));
|
|
assert.equal(projectBuffer[0], 0xef);
|
|
assert.equal(projectBuffer[1], 0xbb);
|
|
assert.equal(projectBuffer[2], 0xbf);
|
|
});
|
|
|
|
test("preview generator emits static assets", () => {
|
|
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "nexacro-preview-"));
|
|
const { appSpec, forms } = loadSpecs();
|
|
generatePreview(appSpec, forms, tempDir);
|
|
|
|
assert.ok(fs.existsSync(path.join(tempDir, "index.html")));
|
|
assert.ok(fs.existsSync(path.join(tempDir, "assets", "app.js")));
|
|
assert.ok(fs.readFileSync(path.join(tempDir, "assets", "app.js"), "utf8").includes("frmReportsOps"));
|
|
});
|
|
|
|
test("xfdl renderer includes datasets and components", () => {
|
|
const { appSpec, forms } = loadSpecs();
|
|
const xfdl = renderXfdl(forms.find((item) => item.formId === "frmLogin"), appSpec);
|
|
|
|
assert.ok(xfdl.includes("<Dataset id=\"dsLogin\">"));
|
|
assert.ok(xfdl.includes("<Edit id=\"edtUsername\""));
|
|
assert.ok(xfdl.includes('onload="Form_onload"'));
|
|
assert.ok(xfdl.includes("<FDL version=\"2.1\">"));
|
|
assert.ok(xfdl.includes("this.Form_onload"));
|
|
});
|