|
| 1 | +import assert from "node:assert/strict"; |
| 2 | +import fs from "node:fs"; |
| 3 | +import path from "node:path"; |
| 4 | +import * as methodEngine from "../src/lib/method-engine.js"; |
| 5 | + |
| 6 | +const expectedPalette = { |
| 7 | + benefit: "#C0EB6A", |
| 8 | + neutral: "#DFDDC5", |
| 9 | + negative: "#FFAFAF", |
| 10 | + task: "#7DC9E7", |
| 11 | + default: "#FFF399" |
| 12 | +}; |
| 13 | + |
| 14 | +assert.deepEqual(methodEngine.getNoteColorPalette(), expectedPalette); |
| 15 | +assert.equal(methodEngine.DEFAULT_NOTE_COLOR, expectedPalette.default); |
| 16 | + |
| 17 | +assert.equal( |
| 18 | + methodEngine.getDefaultNoteColorForSection("customerJourneyCanvas", "journeySteps"), |
| 19 | + expectedPalette.task |
| 20 | +); |
| 21 | +assert.equal( |
| 22 | + methodEngine.getDefaultNoteColorForSection("customerJourneyCanvas", "gains"), |
| 23 | + expectedPalette.benefit |
| 24 | +); |
| 25 | +assert.equal( |
| 26 | + methodEngine.getDefaultNoteColorForSection("businessImpactCanvas", "availabilityRisks"), |
| 27 | + expectedPalette.negative |
| 28 | +); |
| 29 | + |
| 30 | +assert.deepEqual( |
| 31 | + methodEngine.parseStickyNoteInput("Map the approval workflow", { |
| 32 | + canvasId: "customerJourneyCanvas", |
| 33 | + sectionId: "journeySteps" |
| 34 | + }), |
| 35 | + { |
| 36 | + content: "Map the approval workflow", |
| 37 | + size: methodEngine.DEFAULT_NOTE_SIZE, |
| 38 | + color: expectedPalette.task |
| 39 | + } |
| 40 | +); |
| 41 | + |
| 42 | +assert.deepEqual( |
| 43 | + methodEngine.parseStickyNoteInput("[benefit] Faster onboarding", { |
| 44 | + canvasId: "customerJourneyCanvas", |
| 45 | + sectionId: "pains" |
| 46 | + }), |
| 47 | + { |
| 48 | + content: "Faster onboarding", |
| 49 | + size: methodEngine.DEFAULT_NOTE_SIZE, |
| 50 | + color: expectedPalette.benefit |
| 51 | + } |
| 52 | +); |
| 53 | + |
| 54 | +assert.deepEqual( |
| 55 | + methodEngine.parseStickyNoteInput("[color=#7dc9e7] Capture order event", { |
| 56 | + canvasId: "eventCanvas", |
| 57 | + sectionId: "processingLogic" |
| 58 | + }), |
| 59 | + { |
| 60 | + content: "Capture order event", |
| 61 | + size: methodEngine.DEFAULT_NOTE_SIZE, |
| 62 | + color: expectedPalette.task |
| 63 | + } |
| 64 | +); |
| 65 | + |
| 66 | +assert.throws( |
| 67 | + () => methodEngine.parseStickyNoteInput("[mystery] Unknown tag", { |
| 68 | + canvasId: "domainCanvas", |
| 69 | + sectionId: "coreEntitiesAndBusinessMeaning" |
| 70 | + }), |
| 71 | + /Unknown sticky note tag/ |
| 72 | +); |
| 73 | + |
| 74 | +const templateDir = path.join(process.cwd(), "src", "data", "canvas", "import-export-templates"); |
| 75 | +const allowedColors = new Set(Object.values(expectedPalette)); |
| 76 | + |
| 77 | +for (const entry of fs.readdirSync(templateDir)) { |
| 78 | + if (!entry.endsWith(".json")) { |
| 79 | + continue; |
| 80 | + } |
| 81 | + |
| 82 | + const filePath = path.join(templateDir, entry); |
| 83 | + const json = JSON.parse(fs.readFileSync(filePath, "utf8")); |
| 84 | + |
| 85 | + for (const section of json.sections || []) { |
| 86 | + for (const note of section.stickyNotes || []) { |
| 87 | + assert.ok( |
| 88 | + allowedColors.has(note.color), |
| 89 | + `${entry} contains a sticky note color outside the supported palette: ${note.color}` |
| 90 | + ); |
| 91 | + } |
| 92 | + } |
| 93 | +} |
| 94 | + |
| 95 | +console.log("Sticky note color palette checks passed."); |
0 commit comments