summaryrefslogtreecommitdiff
path: root/web/js/tests
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-05-09 19:58:44 +0300
committerPaul Buetow <paul@buetow.org>2026-05-09 19:58:44 +0300
commit868b7fb10c912ea3b7200d1ffa1f287dce335f23 (patch)
treea524d91e484bf4c814a269815594b3ebae66bed4 /web/js/tests
parent8c32cd117abe79f4ee6cff3a950ffc35c95faeff (diff)
Fix shuffle hotkey reshuffle behavior (q1)
Diffstat (limited to 'web/js/tests')
-rw-r--r--web/js/tests/shuffle.test.js54
1 files changed, 54 insertions, 0 deletions
diff --git a/web/js/tests/shuffle.test.js b/web/js/tests/shuffle.test.js
new file mode 100644
index 0000000..bfbc79a
--- /dev/null
+++ b/web/js/tests/shuffle.test.js
@@ -0,0 +1,54 @@
+import { enable, isOn, revision, toggle } from '../shuffle.js';
+
+const failures = [];
+const button = {
+ active: false,
+ classList: {
+ toggle(name, enabled) {
+ if (name === 'active') button.active = enabled;
+ },
+ },
+};
+
+globalThis.document = {
+ getElementById(id) {
+ return id === 'shuffle-toggle' ? button : null;
+ },
+};
+
+function assert(cond, msg) {
+ if (!cond) failures.push(msg || 'assertion failed');
+}
+
+function testEnableTurnsShuffleOn() {
+ enable();
+ assert(isOn(), 'enable should turn shuffle on');
+ assert(button.active, 'enable should update the shuffle button active state');
+}
+
+function testRepeatedEnableKeepsShuffleOnAndAdvancesRevision() {
+ const before = revision();
+ enable();
+ assert(isOn(), 'repeated enable should keep shuffle on');
+ assert(revision() > before, 'repeated enable should advance revision for a fresh random load');
+}
+
+function testToggleCanStillTurnShuffleOff() {
+ toggle();
+ assert(!isOn(), 'toggle should still turn shuffle off for the toolbar button');
+ assert(!button.active, 'toggle should update the shuffle button inactive state');
+}
+
+console.log('Running shuffle tests...');
+testEnableTurnsShuffleOn();
+testRepeatedEnableKeepsShuffleOnAndAdvancesRevision();
+testToggleCanStillTurnShuffleOff();
+
+if (failures.length) {
+ console.error('FAILURES:');
+ failures.forEach((m) => console.error(' - ' + m));
+ process.exit(1);
+} else {
+ console.log('All shuffle tests passed.');
+ process.exit(0);
+}