Files
wekan/tests/rulesBlocks.test.cjs
T
Lauri Ojansivu d273b86ed5 Add editable Blockly rules with local translated message catalogs
Lazy-load Blockly for board administrators, preserve existing rule documents and execution, and provide direct List, Workflow, Blocks and History choices. Route workflow writes through server methods. Include local media, complete message-key coverage, translation merging and placeholder checks.

Translation coverage remains incomplete in additional locales. Low-confidence specialist terminology needs native review in Aragonese, Asturian, Corsican, Neapolitan, Occitan, Sardinian, Sicilian, Kashubian, Upper Sorbian, Silesian, Cornish, Manx, Gaelic and Breton; Faroese and Frisian also merit review.

Verified five Blockly/catalog Node tests, existing rules suites and four Blockly Chromium scenarios, including admin permissions, localization, drag editing and persisted execution.

Thanks to xet7 !
2026-09-27 17:07:02 +03:00

45 lines
2.5 KiB
JavaScript

const { test } = require('node:test');
const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
test('real Blockly round trip preserves rule fields and edits only supported parameters', async () => {
const Blockly = require('blockly/core');
const { registerRulesBlocks } = await import('../models/lib/rulesBlocksDefinition.js');
const { ruleWorkspace, workspaceRule } = await import('../models/lib/rulesBlocks.js');
registerRulesBlocks(Blockly);
const workspace = new Blockly.Workspace();
const trigger = { activityType: 'moveCard', listName: 'Done', userId: '*', advanced: { nested: ['preserve'] } };
const action = { actionType: 'archive', boardId: 'destination', unknownOption: true };
try {
Blockly.serialization.workspaces.load(ruleWorkspace(trigger, action), workspace);
assert.deepEqual(workspaceRule(workspace), { trigger, action });
workspace.getTopBlocks()[0].setFieldValue('In progress', 'listName');
const changed = workspaceRule(workspace);
assert.equal(changed.trigger.listName, 'In progress');
assert.deepEqual(changed.trigger.advanced, trigger.advanced);
assert.deepEqual(changed.action, action);
assert.equal(trigger.listName, 'Done');
const saved = Blockly.serialization.workspaces.save(workspace);
workspace.clear(); Blockly.serialization.workspaces.load(saved, workspace);
assert.deepEqual(workspaceRule(workspace), changed);
workspace.newBlock('wekan_action');
assert.throws(() => workspaceRule(workspace), /exactly one/);
workspace.clear();
assert.throws(() => workspaceRule(workspace), /exactly one/);
assert.throws(() => ruleWorkspace(null, action), /unavailable/);
} finally { workspace.dispose(); }
});
test('Blockly loads only from the dynamic editor and never generates executable code', () => {
const root = path.join(__dirname, '..');
const client = fs.readFileSync(path.join(root, 'client/components/rules/rulesBlocks.js'), 'utf8');
const editor = fs.readFileSync(path.join(root, 'client/components/rules/blocks/editor.js'), 'utf8');
assert.match(client, /await import\('\.\/blocks\/editor'\)/);
assert.doesNotMatch(client, /from ['"]blockly/);
assert.match(client, /rules\.createRule/); assert.match(client, /rules\.updateRule/);
assert.doesNotMatch(editor, /javascriptGenerator|eval\(|new Function/);
assert.match(editor, /observer\.disconnect\(\); workspace\.dispose\(\)/);
assert.match(editor, /\/blockly-media\//);
});