1// Tests of the pure core of the merge request page (static/js/mr.js). Run with
2// node --test 'internal/adapters/web/jstest/*.test.mjs'
3import assert from 'node:assert/strict';
4import { test } from 'node:test';
5
6globalThis.window = globalThis;
7globalThis.document = { readyState: 'complete', querySelector: () => null, querySelectorAll: () => [] };
8await import('../static/js/mr.js');
9const C = window.ermiteMR.core;
10
11test('windowOf: the start of the window of a file', () => {
12 assert.equal(C.windowOf('f1', 25), 0);
13 assert.equal(C.windowOf('f25', 25), 0);
14 assert.equal(C.windowOf('f26', 25), 25);
15 assert.equal(C.windowOf('f84', 25), 75);
16 assert.equal(C.windowOf('c3', 25), -1, 'not a file');
17 assert.equal(C.windowOf('f0', 25), -1);
18});
19
20test('menuKey: modes by number, D toggles the deletion, nothing else', () => {
21 assert.deepEqual(C.menuKey('1', 2), { mode: 0 });
22 assert.deepEqual(C.menuKey('2', 2), { mode: 1 });
23 assert.equal(C.menuKey('3', 2), null, 'no third mode');
24 assert.equal(C.menuKey('0', 2), null);
25 assert.deepEqual(C.menuKey('D', 2), { toggle: true });
26 assert.equal(C.menuKey('d', 2), null, 'd is the split layout');
27 assert.equal(C.menuKey('Enter', 2), null, 'the browser submits: the focus is on the button');
28 assert.equal(C.menuKey('M', 2), null);
29});
30
31test('step: stays in the list', () => {
32 assert.equal(C.step(0, 1, 3), 1);
33 assert.equal(C.step(2, 1, 3), 2);
34 assert.equal(C.step(0, -1, 3), 0);
35 assert.equal(C.step(-1, 1, 3), 0);
36 assert.equal(C.step(-1, -1, 3), 2);
37 assert.equal(C.step(0, 1, 0), -1);
38});