dbxapp 4.1.3
CMS, Shop, Workflows und modulare Geschäftsanwendungen
Loading...
Searching...
No Matches
cms_zero_field_value_test.js
Go to the documentation of this file.
1"use strict";
2
3const fs = require("fs");
4const path = require("path");
5
6const cmsFile = path.resolve(__dirname, "../../../js/lib/cms.js");
7const source = fs.readFileSync(cmsFile, "utf8");
8const match = source.match(/function cmsFieldValue\‍([^)]*\‍) \{[\s\S]*?\n \}/);
9
10if (!match) {
11 throw new Error("cmsFieldValue wurde in cms.js nicht gefunden.");
12}
13
14const cmsFieldValue = Function(`"use strict"; return (${match[0]});`)();
15const cases = [
16 [0, 0, "Numerische Null muss erhalten bleiben"],
17 ["0", "0", "Statuswert 0 muss erhalten bleiben"],
18 [1, 1, "Numerische Eins muss erhalten bleiben"],
19 ["1", "1", "Statuswert 1 muss erhalten bleiben"],
20 [null, "", "null wird als leeres Feld dargestellt"],
21 [undefined, "", "undefined wird als leeres Feld dargestellt"],
22];
23
24for (const [input, expected, label] of cases) {
25 const actual = cmsFieldValue(input);
26 if (actual !== expected) {
27 throw new Error(`${label}: erwartet ${String(expected)}, erhalten ${String(actual)}`);
28 }
29}
30
31console.log("OK cms_zero_field_value_test");