mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-11-06 12:52:26 +00:00
Refactor docs navigation and clean up legacy views
Co-authored-by: PR0M3TH3AN <[email protected]>
This commit is contained in:
1 parent
7e09a7e353
commit
cfd7c49a9d
9 files changed
+94
-523
No files matched your search
@@ -0,0 +1,64 @@
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { createHashChangeHandler } from '../../js/hashChangeHandler.js';
|
||||
|
||||
test('createHashChangeHandler', async (t) => {
|
||||
// Mock window
|
||||
const mockLocation = { hash: '' };
|
||||
global.window = {
|
||||
location: mockLocation,
|
||||
history: {
|
||||
replaceState: () => {}
|
||||
}
|
||||
};
|
||||
|
||||
// Mock dependencies
|
||||
let loadedView = null;
|
||||
const mockLoadView = async (url) => {
|
||||
loadedView = url;
|
||||
};
|
||||
|
||||
const mockViewInitRegistry = {
|
||||
docs: async () => {},
|
||||
"for-you": async () => {}
|
||||
};
|
||||
|
||||
const handler = createHashChangeHandler({
|
||||
getApplication: () => ({ isUserLoggedIn: () => false }),
|
||||
getApplicationReady: () => Promise.resolve(),
|
||||
loadView: mockLoadView,
|
||||
viewInitRegistry: mockViewInitRegistry,
|
||||
userLogger: { error: () => {}, warn: () => {} },
|
||||
devLogger: { log: () => {} }
|
||||
});
|
||||
|
||||
await t.test('loads default view if hash is empty', async () => {
|
||||
loadedView = null;
|
||||
mockLocation.hash = '';
|
||||
await handler();
|
||||
// Default is most-recent-videos if not logged in
|
||||
assert.equal(loadedView, 'views/most-recent-videos.html');
|
||||
});
|
||||
|
||||
await t.test('redirects legacy view', async () => {
|
||||
loadedView = null;
|
||||
mockLocation.hash = '#view=about';
|
||||
await handler();
|
||||
// It should update hash and return
|
||||
assert.equal(mockLocation.hash, '#view=docs&doc=about');
|
||||
assert.equal(loadedView, null);
|
||||
});
|
||||
|
||||
await t.test('skips redundant reload', async () => {
|
||||
// First load docs
|
||||
loadedView = null;
|
||||
mockLocation.hash = '#view=docs';
|
||||
await handler();
|
||||
assert.equal(loadedView, 'views/docs.html');
|
||||
|
||||
// Call again with same hash
|
||||
loadedView = null;
|
||||
await handler();
|
||||
assert.equal(loadedView, null, 'Should not reload view if same');
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user