| 1 | import assert from 'node:assert/strict'; |
| 2 | import {matchingSlashCommands, shouldShowSlashCommands, slashCommandQuery} from './slashCommands.js'; |
| 3 | |
| 4 | assert.equal(shouldShowSlashCommands('/', false), true); |
| 5 | assert.equal(shouldShowSlashCommands('/co', false), true); |
| 6 | assert.equal(shouldShowSlashCommands('/co', true), false); |
| 7 | assert.equal(shouldShowSlashCommands('hello', false), false); |
| 8 | |
| 9 | assert.equal(slashCommandQuery('/compact now'), '/compact'); |
| 10 | assert.equal(slashCommandQuery('/co'), '/co'); |
| 11 | |
| 12 | assert.deepEqual(matchingSlashCommands('/').map((command) => command.name), ['/compact']); |
| 13 | assert.deepEqual(matchingSlashCommands('/com').map((command) => command.name), ['/compact']); |
| 14 | assert.deepEqual(matchingSlashCommands('/compact').map((command) => command.name), ['/compact']); |
| 15 | assert.deepEqual(matchingSlashCommands('/x').map((command) => command.name), []); |
| 16 | |
| 17 | const slashOnly = matchingSlashCommands('/')[0]; |
| 18 | assert.equal(slashOnly?.matchedPrefix, '/'); |
| 19 | assert.equal(slashOnly?.unmatchedSuffix, 'compact'); |
| 20 | |
| 21 | const partial = matchingSlashCommands('/co')[0]; |
| 22 | assert.equal(partial?.matchedPrefix, '/co'); |
| 23 | assert.equal(partial?.unmatchedSuffix, 'mpact'); |
| 24 | |
| 25 | const full = matchingSlashCommands('/compact')[0]; |
| 26 | assert.equal(full?.matchedPrefix, '/compact'); |
| 27 | assert.equal(full?.unmatchedSuffix, ''); |
| 28 | |
| 29 | console.log('slashCommands tests passed'); |
| 30 |