v0.28.1 cc7ba64

mr.test.mjs RawHistoryFolder

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});
39
40test('rangeURL requires the same file, side and MR and sorts endpoints', () => {
41 const base = 'https://forge.test/demo/merge-requests/1';
42 const a = base+'?on=new:24:dir%2Fa.go#f1';
43 const b = base+'?from=25&on=new:10:dir%2Fa.go#f1';
44 const u = new URL(C.rangeURL(a,b,base));
45 assert.equal(u.searchParams.get('on'),'new:10-24:dir/a.go');
46 assert.equal(u.searchParams.get('from'),'25');
47 assert.equal(u.hash,'#f1');
48 assert.equal(C.rangeURL(a,a,base),null);
49 assert.equal(C.rangeURL(a,b.replace('new:','old:'),base),null);
50 assert.equal(C.rangeURL(a,b.replace('a.go','b.go'),base),null);
51 assert.equal(C.rangeURL(a,b.replace('/1?','/2?'),base),null);
52});
53
54test('quote opens the thread reply and prefills and focuses its textarea', () => {
55 let focused=false;
56 const field={value:'',focus(){focused=true;}};
57 const details={open:false,querySelector(){return field;}};
58 const thread={querySelector(){return details;}};
59 const button={dataset:{quote:'> source\n\n^2 '},closest(){return {closest(){return thread;}};}};
60 assert.equal(C.quote(button),true);
61 assert.equal(details.open,true);
62 assert.equal(field.value,'> source\n\n^2 ');
63 assert.equal(focused,true);
64});
65
66for (const dataset of [{diff:'split'}, {view:'split'}]) test(`reveal selects the split note (${JSON.stringify(dataset)}), including after lazy loading`, async () => {
67 const saved = globalThis.document;
68 const savedRAF = globalThis.requestAnimationFrame;
69 let scrolled = '';
70 const details = {open:false};
71 const node = id => ({id, querySelector(){return null;}, closest(){return details;}, scrollIntoView(){scrolled=id;}});
72 const nodes = new Map([['c12',node('c12')],['c12-s',node('c12-s')]]);
73 const ph = {dataset:{notes:'c12'}};
74 globalThis.document = {
75   querySelector: sel => sel === '#diffs' ? {dataset} : null,
76   querySelectorAll: () => [ph],
77   getElementById: id => nodes.get(id),
78 };
79 globalThis.requestAnimationFrame = fn => fn();
80 try {
81   assert.equal(window.ermiteMR.reveal('c12'),false);
82   assert.equal(scrolled,'c12-s');
83   assert.equal(details.open,true);
84   nodes.clear(); scrolled=''; details.open=false;
85   assert.equal(window.ermiteMR.reveal('c12'),true);
86   nodes.set('c12',node('c12')); nodes.set('c12-s',node('c12-s'));
87   await Promise.resolve();
88   assert.equal(scrolled,'c12-s');
89   assert.equal(details.open,true);
90 } finally {
91   globalThis.document=saved;
92   globalThis.requestAnimationFrame=savedRAF;
93 }
94});

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 4

Tags 45

↑↓ moveenter openesc close