mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-10-27 16:02:26 +00:00
This change ensures the 'Explore' link is visible in the sidebar when the user is logged in, and hidden when logged out, consistent with other authenticated routes like 'For You' and 'Subscriptions'. - Updated `js/app.js` to handle `exploreLink` visibility in `applyAuthenticatedUiState` and `applyLoggedOutUiState`. - Initialized `exploreLink` property in `js/ui/applicationBootstrap.js`. - Updated `tests/app/hydrate-sidebar-navigation.test.mjs` to verify the behavior.
184 lines
6.7 KiB
JavaScript
184 lines
6.7 KiB
JavaScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { JSDOM } from "jsdom";
|
|
|
|
import { Application } from "../../js/app.js";
|
|
|
|
const VIEW_HTML = `<!DOCTYPE html>
|
|
<html>
|
|
<body>
|
|
<div id="chrome">
|
|
<button id="loginButton" class="btn"></button>
|
|
<button id="logoutButton" class="hidden"></button>
|
|
<button id="uploadButton" class="hidden" hidden></button>
|
|
<button id="profileButton" class="hidden" hidden></button>
|
|
<span id="userStatus" class="hidden"></span>
|
|
<span id="userPubKey"></span>
|
|
<button id="closeLoginModal"></button>
|
|
</div>
|
|
<a id="subscriptionsLink" class="hidden"></a>
|
|
<a id="forYouLink" class="hidden"></a>
|
|
<a id="exploreLink" class="hidden"></a>
|
|
</body>
|
|
</html>`;
|
|
|
|
test("hydrateSidebarNavigation reveals chrome controls for authenticated viewers", () => {
|
|
const dom = new JSDOM(VIEW_HTML, { url: "https://example.com" });
|
|
const { window } = dom;
|
|
|
|
const previousWindow = global.window;
|
|
const previousDocument = global.document;
|
|
|
|
global.window = window;
|
|
global.document = window.document;
|
|
const previousHTMLElement = global.HTMLElement;
|
|
global.HTMLElement = window.HTMLElement;
|
|
|
|
try {
|
|
const app = Object.create(Application.prototype);
|
|
|
|
app.appChromeController = {
|
|
receivedElements: null,
|
|
setElements(elements) {
|
|
this.receivedElements = elements;
|
|
},
|
|
};
|
|
|
|
app.userStatus = window.document.getElementById("userStatus");
|
|
app.userPubKey = window.document.getElementById("userPubKey");
|
|
app.subscriptionsLink = null;
|
|
app.exploreLink = null;
|
|
app.isUserLoggedIn = () => true;
|
|
app.log = () => {};
|
|
app.showError = () => {};
|
|
app.showSuccess = () => {};
|
|
app.showStatus = () => {};
|
|
|
|
app.hydrateSidebarNavigation();
|
|
|
|
const uploadButton = window.document.getElementById("uploadButton");
|
|
const profileButton = window.document.getElementById("profileButton");
|
|
const loginButton = window.document.getElementById("loginButton");
|
|
const logoutButton = window.document.getElementById("logoutButton");
|
|
const subscriptionsLink = window.document.getElementById("subscriptionsLink");
|
|
const forYouLink = window.document.getElementById("forYouLink");
|
|
const exploreLink = window.document.getElementById("exploreLink");
|
|
const closeLoginButton = window.document.getElementById("closeLoginModal");
|
|
|
|
assert.equal(app.uploadButton, uploadButton);
|
|
assert.equal(app.profileButton, profileButton);
|
|
assert.equal(app.loginButton, loginButton);
|
|
assert.equal(app.logoutButton, logoutButton);
|
|
assert.equal(app.closeLoginModalBtn, closeLoginButton);
|
|
|
|
assert.equal(uploadButton.classList.contains("hidden"), false);
|
|
assert.equal(uploadButton.hasAttribute("hidden"), false);
|
|
assert.equal(profileButton.classList.contains("hidden"), false);
|
|
assert.equal(profileButton.hasAttribute("hidden"), false);
|
|
assert.equal(loginButton.classList.contains("hidden"), true);
|
|
assert.equal(loginButton.hasAttribute("hidden"), true);
|
|
assert.equal(logoutButton.classList.contains("hidden"), false);
|
|
assert.equal(subscriptionsLink.classList.contains("hidden"), false);
|
|
assert.equal(forYouLink.classList.contains("hidden"), false);
|
|
assert.equal(exploreLink.classList.contains("hidden"), false);
|
|
|
|
assert.ok(app.appChromeController.receivedElements);
|
|
assert.equal(
|
|
app.appChromeController.receivedElements.uploadButton,
|
|
uploadButton,
|
|
);
|
|
assert.equal(
|
|
app.appChromeController.receivedElements.profileButton,
|
|
profileButton,
|
|
);
|
|
} finally {
|
|
global.window = previousWindow;
|
|
global.document = previousDocument;
|
|
if (previousHTMLElement === undefined) {
|
|
delete global.HTMLElement;
|
|
} else {
|
|
global.HTMLElement = previousHTMLElement;
|
|
}
|
|
}
|
|
});
|
|
|
|
test("hydrateSidebarNavigation hides chrome controls for logged-out viewers", () => {
|
|
const dom = new JSDOM(VIEW_HTML, { url: "https://example.com" });
|
|
const { window } = dom;
|
|
|
|
const previousWindow = global.window;
|
|
const previousDocument = global.document;
|
|
|
|
global.window = window;
|
|
global.document = window.document;
|
|
const previousHTMLElement = global.HTMLElement;
|
|
global.HTMLElement = window.HTMLElement;
|
|
|
|
try {
|
|
const app = Object.create(Application.prototype);
|
|
|
|
app.appChromeController = {
|
|
receivedElements: null,
|
|
setElements(elements) {
|
|
this.receivedElements = elements;
|
|
},
|
|
};
|
|
|
|
app.userStatus = window.document.getElementById("userStatus");
|
|
app.userPubKey = window.document.getElementById("userPubKey");
|
|
app.subscriptionsLink = null;
|
|
app.exploreLink = null;
|
|
app.isUserLoggedIn = () => false;
|
|
app.log = () => {};
|
|
app.showError = () => {};
|
|
app.showSuccess = () => {};
|
|
app.showStatus = () => {};
|
|
|
|
app.hydrateSidebarNavigation();
|
|
|
|
const uploadButton = window.document.getElementById("uploadButton");
|
|
const profileButton = window.document.getElementById("profileButton");
|
|
const loginButton = window.document.getElementById("loginButton");
|
|
const logoutButton = window.document.getElementById("logoutButton");
|
|
const subscriptionsLink = window.document.getElementById("subscriptionsLink");
|
|
const forYouLink = window.document.getElementById("forYouLink");
|
|
const exploreLink = window.document.getElementById("exploreLink");
|
|
const closeLoginButton = window.document.getElementById("closeLoginModal");
|
|
|
|
assert.equal(app.uploadButton, uploadButton);
|
|
assert.equal(app.profileButton, profileButton);
|
|
assert.equal(app.loginButton, loginButton);
|
|
assert.equal(app.logoutButton, logoutButton);
|
|
assert.equal(app.closeLoginModalBtn, closeLoginButton);
|
|
|
|
assert.equal(uploadButton.classList.contains("hidden"), true);
|
|
assert.equal(uploadButton.hasAttribute("hidden"), true);
|
|
assert.equal(profileButton.classList.contains("hidden"), true);
|
|
assert.equal(profileButton.hasAttribute("hidden"), true);
|
|
assert.equal(loginButton.classList.contains("hidden"), false);
|
|
assert.equal(loginButton.hasAttribute("hidden"), false);
|
|
assert.equal(logoutButton.classList.contains("hidden"), true);
|
|
assert.equal(subscriptionsLink.classList.contains("hidden"), true);
|
|
assert.equal(forYouLink.classList.contains("hidden"), true);
|
|
assert.equal(exploreLink.classList.contains("hidden"), true);
|
|
|
|
assert.ok(app.appChromeController.receivedElements);
|
|
assert.equal(
|
|
app.appChromeController.receivedElements.uploadButton,
|
|
uploadButton,
|
|
);
|
|
assert.equal(
|
|
app.appChromeController.receivedElements.profileButton,
|
|
profileButton,
|
|
);
|
|
} finally {
|
|
global.window = previousWindow;
|
|
global.document = previousDocument;
|
|
if (previousHTMLElement === undefined) {
|
|
delete global.HTMLElement;
|
|
} else {
|
|
global.HTMLElement = previousHTMLElement;
|
|
}
|
|
}
|
|
});
|