Repository navigation
Expand file tree
/
Copy paththemeAdapters.test.js
More file actions
28 lines (28 loc) · 1.6 KB
/
Copy paththemeAdapters.test.js
File metadata and controls
28 lines (28 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
const { test } = require('node:test');
const assert = require('node:assert/strict');
const { JSDOM } = require('jsdom');
const { readFileSync } = require('node:fs');
function detect(file, path = '/hot-deals-f9/', host = 'forums.redflagdeals.com') {
const dom = new JSDOM(readFileSync(`test/fixtures/rfd/${file}.html`, 'utf8'), { url: `https://${host}${path}`, runScripts: 'outside-only' });
dom.window.eval(readFileSync('js/theme/adapters.js', 'utf8'));
return dom.window.RFDModern.adapters.detect(dom.window.document, new URL(dom.window.location));
}
test('recognizes verified card list and native empty list shell', () => {
assert.equal(detect('list-card')?.kind, 'list');
assert.equal(detect('list-card')?.root.id, 'forum-topics');
assert.equal(detect('list-empty'), null); // Synthetic empty state is not verified against live RFD.
});
test('recognizes thread root, not a sidebar title', () => {
assert.equal(detect('thread', '/example-1/')?.root.id, 'thread');
assert.equal(detect('unsupported', '/login/') , null);
});
test('rejects unsupported host and routes', () => {
assert.equal(detect('list-card', '/hot-deals-f9/', 'example.com'), null);
assert.equal(detect('list-card', '/search.php'), null);
assert.equal(detect('thread', '/posting.php'), null);
assert.equal(detect('thread', '/example-1/?view=print'), null);
});
test('recognizes the search result shell without treating it as a deal list', () => {
assert.equal(detect('search', '/search.php?keywords=anker&sr=threads')?.kind, 'search');
assert.equal(detect('search', '/search.php?keywords=anker&sr=posts')?.root.id, 'search_results');
});