Rotate through photos from enabled feeds with a persisted shuffle-bag queue. Weekly changes at local Monday midnight and daily at local midnight; Off keeps the selected photo. Legacy configs migrate to the weekly default, and Rotation now sits above Feeds in the Photos settings.
59 lines
1.8 KiB
JavaScript
59 lines
1.8 KiB
JavaScript
import { module, test } from 'qunit';
|
|
import {
|
|
nextRotationStart,
|
|
rotationIndex,
|
|
shuffle,
|
|
} from 'dashtab/utils/rotation';
|
|
|
|
module('Unit | Utility | rotation', function () {
|
|
test('weekly periods change at local Monday midnight', function (assert) {
|
|
const sunday = new Date(2026, 10, 8, 23, 59, 59).getTime();
|
|
const monday = new Date(2026, 10, 9, 0, 0, 0).getTime();
|
|
|
|
assert.strictEqual(
|
|
rotationIndex(monday, 'weekly'),
|
|
rotationIndex(sunday, 'weekly') + 1
|
|
);
|
|
|
|
const next = new Date(nextRotationStart(sunday, 'weekly'));
|
|
|
|
assert.strictEqual(next.getFullYear(), 2026);
|
|
assert.strictEqual(next.getMonth(), 10);
|
|
assert.strictEqual(next.getDate(), 9);
|
|
assert.strictEqual(next.getHours(), 0);
|
|
assert.strictEqual(next.getMinutes(), 0);
|
|
assert.strictEqual(next.getSeconds(), 0);
|
|
});
|
|
|
|
test('daily periods change at local midnight', function (assert) {
|
|
const before = new Date(2026, 10, 8, 23, 59, 59).getTime();
|
|
const after = new Date(2026, 10, 9, 0, 0, 0).getTime();
|
|
|
|
assert.strictEqual(
|
|
rotationIndex(after, 'daily'),
|
|
rotationIndex(before, 'daily') + 1
|
|
);
|
|
|
|
const next = new Date(nextRotationStart(before, 'daily'));
|
|
|
|
assert.strictEqual(next.getFullYear(), 2026);
|
|
assert.strictEqual(next.getMonth(), 10);
|
|
assert.strictEqual(next.getDate(), 9);
|
|
assert.strictEqual(next.getHours(), 0);
|
|
assert.strictEqual(next.getMinutes(), 0);
|
|
assert.strictEqual(next.getSeconds(), 0);
|
|
});
|
|
|
|
test('off has no rotation period', function (assert) {
|
|
assert.strictEqual(rotationIndex(Date.now(), 'off'), null);
|
|
assert.strictEqual(nextRotationStart(Date.now(), 'off'), null);
|
|
});
|
|
|
|
test('shuffle is deterministic with an injected random source', function (assert) {
|
|
assert.deepEqual(
|
|
shuffle([1, 2, 3], () => 0),
|
|
[2, 3, 1]
|
|
);
|
|
});
|
|
});
|