diff options
author | Andreas Gohr <andi@splitbrain.org> | 2024-10-15 13:42:32 +0200 |
---|---|---|
committer | Andreas Gohr <andi@splitbrain.org> | 2024-10-15 13:42:32 +0200 |
commit | d3d20a669a9dfc59495db347cb88a168a1362617 (patch) | |
tree | 253cdb527e9fd810618047402156e79e15c9bdd5 /lib/scripts/linkwiz.test.js | |
parent | d2fda519a7918544348b6e375522558e6ee2928c (diff) | |
download | dokuwiki-d3d20a669a9dfc59495db347cb88a168a1362617.tar.gz dokuwiki-d3d20a669a9dfc59495db347cb88a168a1362617.zip |
LinkWizard: add method to create a relative link
This is not used, yet. Usage will be added in a future commit.
Since we don't have a proper testing framework in place, yet. Tests have
been added as a standalone script that can be run manually.
Diffstat (limited to 'lib/scripts/linkwiz.test.js')
-rw-r--r-- | lib/scripts/linkwiz.test.js | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/scripts/linkwiz.test.js b/lib/scripts/linkwiz.test.js new file mode 100644 index 000000000..2f4b7aed9 --- /dev/null +++ b/lib/scripts/linkwiz.test.js @@ -0,0 +1,34 @@ +/** + * Tests for the LinkWizard class + * + * This is a simple self-contained test suite until we introduce a proper way to run JavaScript tests + * in DokuWiki. + * + * Needs to be run manually as: + * + * cat linkwiz.js linkwiz.test.js | node + */ + +function runLinkWizardTests() { + const testCases = [ + { ref: 'a:b:c', id: 'a:b:d', expected: 'd' }, + { ref: 'a:b:c', id: 'a:b:c:d:e', expected: '.:c:d:e' }, + { ref: 'a:b:c', id: 'a:b:c:d:e', expected: '.:c:d:e' }, + { ref: 'a', id: 'a:b:c', expected: 'a:b:c' }, + { ref: 'a:b', id: 'c:d', expected: 'c:d' }, + { ref: 'a:b:c', id: 'a:d:e', expected: '..:d:e' }, + { ref: 'a:b', id: 'c', expected: ':c' }, + ]; + + testCases.forEach(({ ref, id, expected }, index) => { + const result = LinkWizard.createRelativeID(ref, id); + if (result === expected) { + console.log(`Test ${index + 1} passed`); + } else { + console.log(`Test ${index + 1} failed: expected ${expected}, got ${result}`); + } + }); +} + +// Run the tests +runLinkWizardTests(); |