Mirrors the existing unread-drawer pattern: a new dropdown next to the notification bell, gated on templateData.support.visible (injected by the support plugin's filter:middleware.renderHeader hook, on every page render, for viewers with any support access at all). Opening it fetches GET /plugins/support/notifications via the api module, renders up to 10 entries by textContent (never innerHTML), and marks everything read via POST .../notifications/read, clearing the badge client-side. Also present in the mobile burger drawer, same gating. ponytail: no live socket push for this badge (core's own unread/notification counts get one); it only catches up on the next full page load after the box is opened. Noted in client.js as the upgrade path if that gap matters. Verified live against sow-nodebb-plugin-support's dev NodeBB stack (theme + plugin both mounted): icon hidden for a user with no support access, badge count and dropdown contents correct for a reviewer, badge clears on open. Full plain-node test suite passes. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
219 lines
6.6 KiB
JavaScript
219 lines
6.6 KiB
JavaScript
'use strict';
|
|
|
|
const assert = require('assert');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
function read(relativePath) {
|
|
const filePath = path.join(__dirname, '..', relativePath);
|
|
assert(fs.existsSync(filePath), `${relativePath} should exist`);
|
|
return fs.readFileSync(filePath, 'utf8');
|
|
}
|
|
|
|
function assertMissing(relativePath, message) {
|
|
const filePath = path.join(__dirname, '..', relativePath);
|
|
assert(!fs.existsSync(filePath), message || `${relativePath} should not exist`);
|
|
}
|
|
|
|
function assertIncludes(haystack, needle, message) {
|
|
assert(
|
|
haystack.includes(needle),
|
|
message || `Expected file to include ${needle}`
|
|
);
|
|
}
|
|
|
|
function assertExcludes(haystack, needle, message) {
|
|
assert(
|
|
!haystack.includes(needle),
|
|
message || `Expected file not to include ${needle}`
|
|
);
|
|
}
|
|
|
|
function assertMatches(haystack, pattern, message) {
|
|
assert(
|
|
pattern.test(haystack),
|
|
message || `Expected file to match ${pattern}`
|
|
);
|
|
}
|
|
|
|
const header = read('templates/header.tpl');
|
|
const footer = read('templates/footer.tpl');
|
|
const topbar = read('templates/partials/header/topbar.tpl');
|
|
const theme = read('theme.scss');
|
|
const stylesheet = read('scss/westgate/_topbar.scss');
|
|
const client = read('public/client.js');
|
|
const themeHooks = read('lib/theme.js');
|
|
|
|
assertIncludes(
|
|
header,
|
|
'<!-- IMPORT partials/header/topbar.tpl -->',
|
|
'Header should mount the Westgate topbar partial'
|
|
);
|
|
assertExcludes(
|
|
header,
|
|
'<!-- IMPORT partials/sidebar-left.tpl -->',
|
|
"Header should no longer render Harmony's left global sidebar"
|
|
);
|
|
assertExcludes(
|
|
footer,
|
|
'<!-- IMPORT partials/sidebar-right.tpl -->',
|
|
"Footer should no longer render Harmony's right global sidebar"
|
|
);
|
|
assertIncludes(
|
|
theme,
|
|
'@import "./scss/westgate/topbar";',
|
|
'theme.scss should import the focused topbar partial'
|
|
);
|
|
assertExcludes(
|
|
theme,
|
|
'@import "./scss/westgate/header";',
|
|
'theme.scss should not import the removed brand banner stylesheet'
|
|
);
|
|
assertIncludes(
|
|
stylesheet,
|
|
'.wg-topbar',
|
|
'Topbar styles should be scoped to .wg-topbar'
|
|
);
|
|
assertIncludes(
|
|
stylesheet,
|
|
'.wg-topbar__utility-list .visible-closed:not(.hidden)',
|
|
'Topbar collapsed utility labels should not override hidden count badges'
|
|
);
|
|
assertIncludes(
|
|
client,
|
|
'initWestgateTopbar',
|
|
'Client bundle should initialize Westgate topbar behavior'
|
|
);
|
|
|
|
[
|
|
'component="sidebar/search"',
|
|
'component="notifications"',
|
|
'component="sidebar/drafts"',
|
|
].forEach((component) => {
|
|
assertIncludes(topbar, component, `Topbar should preserve live NodeBB hook ${component}`);
|
|
});
|
|
|
|
[
|
|
'<!-- IMPORT partials/sidebar/search.tpl -->',
|
|
'<!-- IMPORT partials/sidebar/notifications.tpl -->',
|
|
'<!-- IMPORT partials/sidebar/chats.tpl -->',
|
|
'<!-- IMPORT partials/sidebar/drafts.tpl -->',
|
|
'<!-- IMPORT partials/sidebar/user-menu.tpl -->',
|
|
].forEach((templateImport) => {
|
|
assertIncludes(topbar, templateImport, `Topbar should reuse Harmony live partial ${templateImport}`);
|
|
});
|
|
|
|
[
|
|
'Velessa Thorne',
|
|
'Guildmaster Orin',
|
|
'A letter left at the Undergate',
|
|
'wg-topbar-demo',
|
|
"localStorage.setItem('wg-topbar-presence'",
|
|
].forEach((fixture) => {
|
|
assertExcludes(topbar, fixture, `Topbar should not ship preview fixture ${fixture}`);
|
|
});
|
|
|
|
assertIncludes(topbar, '{{{ if config.loggedIn }}}', 'Topbar should branch on the real logged-in state');
|
|
assertIncludes(topbar, '{{{ if canChat }}}', 'Chat controls should remain permission-gated');
|
|
assertIncludes(topbar, '{{{ if allowRegistration }}}', 'Registration should remain server-gated');
|
|
assertIncludes(topbar, '{{{ each navigation }}}', 'Topbar should render ACP Navigation items');
|
|
assertIncludes(topbar, '{./textClass}', 'Topbar should honor ACP Navigation text visibility classes');
|
|
assertExcludes(topbar, 'href="{relative_path}/admin"', 'Topbar should not hard-code the administrator link');
|
|
assertMatches(
|
|
topbar,
|
|
/<a\b(?=[^>]*class="[^"]*\bwg-topbar__brand\b[^"]*")(?=[^>]*aria-label="{config\.siteTitle}")/,
|
|
'Topbar brand link should use the configured site title as its accessible name'
|
|
);
|
|
assertMatches(
|
|
topbar,
|
|
/<span\b(?=[^>]*class="[^"]*\bwg-topbar__brand-name\b[^"]*")[^>]*>{config\.siteTitle}<\/span>/,
|
|
'Topbar brand text should render the configured site title'
|
|
);
|
|
assertExcludes(topbar, 'data-wg-menu', 'Topbar should rely on Bootstrap and NodeBB navigation instead of custom menu triggers');
|
|
|
|
assertMissing(
|
|
'templates/partials/header/brand.tpl',
|
|
'Theme should inherit Harmony brand markup instead of shipping the removed Westgate brand banner override'
|
|
);
|
|
assertMissing(
|
|
'scss/westgate/_header.scss',
|
|
'Removed brand banner styles should not remain in the theme'
|
|
);
|
|
assertMissing(
|
|
'public/images/plum-header-bg.png',
|
|
'Removed brand banner background should not remain in static assets'
|
|
);
|
|
assertExcludes(
|
|
themeHooks,
|
|
'brand-header',
|
|
'Removed brand banner widget area should not remain registered'
|
|
);
|
|
|
|
const unreadDrawer = read('templates/partials/header/unread-drawer.tpl');
|
|
assertIncludes(
|
|
topbar,
|
|
'<!-- IMPORT partials/header/unread-drawer.tpl -->',
|
|
'Topbar should mount the unread drawer before notifications'
|
|
);
|
|
assert(
|
|
topbar.indexOf('partials/header/unread-drawer.tpl') < topbar.indexOf('partials/sidebar/notifications.tpl'),
|
|
'Unread drawer should sit before the notifications item'
|
|
);
|
|
assertIncludes(
|
|
unreadDrawer,
|
|
'component="unread/count"',
|
|
'Unread toggle should carry the live core count badge'
|
|
);
|
|
assertIncludes(
|
|
unreadDrawer,
|
|
'data-wg-unread-menu',
|
|
'Unread dropdown menu should expose the JS mount hook'
|
|
);
|
|
assertMatches(
|
|
topbar,
|
|
/href="\{relative_path\}\/unread"[^>]*>[\s\S]*?component="unread\/count"/,
|
|
'Mobile drawer actions should include an Unread link with count badge'
|
|
);
|
|
|
|
assertIncludes(
|
|
stylesheet,
|
|
'.unread-dropdown',
|
|
'Topbar styles should cover the unread dropdown'
|
|
);
|
|
|
|
const supportDrawer = read('templates/partials/header/support-drawer.tpl');
|
|
assertIncludes(
|
|
topbar,
|
|
'<!-- IMPORT partials/header/support-drawer.tpl -->',
|
|
'Topbar should mount the support inbox drawer'
|
|
);
|
|
assertIncludes(
|
|
topbar,
|
|
'{{{ if support.visible }}}',
|
|
'Support inbox drawer should be gated on the viewer having any support access'
|
|
);
|
|
assert(
|
|
topbar.indexOf('partials/sidebar/notifications.tpl') < topbar.indexOf('partials/header/support-drawer.tpl'),
|
|
'Support inbox should sit next to (after) the notifications bell'
|
|
);
|
|
assertIncludes(
|
|
supportDrawer,
|
|
'component="support/count"',
|
|
'Support toggle should carry its own unread count badge'
|
|
);
|
|
assertIncludes(
|
|
supportDrawer,
|
|
'data-wg-support-menu',
|
|
'Support dropdown menu should expose the JS mount hook'
|
|
);
|
|
assertMatches(
|
|
topbar,
|
|
/href="\{relative_path\}\/support"[^>]*>[\s\S]*?component="support\/count"/,
|
|
'Mobile drawer actions should include a Support inbox link with count badge'
|
|
);
|
|
assertIncludes(
|
|
stylesheet,
|
|
'.support-dropdown',
|
|
'Topbar styles should cover the support inbox dropdown'
|
|
);
|