mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 18:10:06 -05:00
Implements option D of docs/Design/Multitenancy/Multitenancy.md, which that document now describes as shipped. An Organization may claim hostnames (Admin Panel / People / Organizations -> Edit), carry its own branding - product name, logos, help link, legal notice and theme colour - and have its own Organization admins, appointed from the row's "..." menu. The request's host picks the Organization; its branding replaces the instance branding for that request, and the client bundle that host serves points its DDP connection back at that host instead of at the one ROOT_URL. An Organization admin administers their own Organization and nothing else: its people, its Organizations row, its theme colour and its backups. They can never grant the site-wide Admin flag, never manage a site admin, and never see another Organization's people or archives. Per-tenant backup and restore is one new control in Admin Panel / Attachments / Backup - Scope. An Organization's archive holds its boards and everything on them plus the attachments those boards use, and no accounts, no instance settings and no org/team documents, because those are shared. A restore may only write to boards that Organization owns: the board ids are the intersection of what the archive claims with what the Organization really owns, every document is checked against that, and "replace all" replaces that Organization's documents rather than everyone's. Admin Panel / Settings / Visibility gains a Change color section above Logo: the site theme, rendered by the SAME shared picker as Board Settings and Member Settings - one template for all three, the way one shared table page serves every table. Its design is the new docs/Design/Page/Theme.md. The order of themes is WeKan's default theme, then the site theme (an Organization's own value on its own hosts), then a user's own override; a board's own colour still owns the board page. All of it is OFF unless the server is started with MULTITENANCY=true (plus MULTITENANCY_TRUST_PROXY_HOST=true when a trusted proxy sets X-Forwarded-Host), so an instance that has never heard of tenants answers exactly as before. One WeKan server per customer remains the supported topology for customers who must not share a process, and the design says plainly what this does NOT isolate. The decisions are three pure modules - models/lib/tenants.js, tenantAdmin.js and tenantBackup.js - so the same rules run on the client, on the server and in the tests. Four new suites pin the separation rather than the plumbing: forged Host headers, cross-tenant queries, privilege escalation and cross-tenant restores. Thanks to xet7 !
657 lines
36 KiB
JavaScript
657 lines
36 KiB
JavaScript
'use strict';
|
|
|
|
// The shared left menu — docs/Design/Page/Left-Menu.md.
|
|
//
|
|
// This is the COMBINED suite for that design: the pure helpers, the template, the
|
|
// side it appears on (and its mirroring under a right-to-left language), the
|
|
// theming, and the layout it shares with the table page. Files under test are the
|
|
// ones listed in the Related files table of the design doc.
|
|
//
|
|
// Every Admin Panel page has the same menu beside its content, and the markup was
|
|
// retyped 44 times across seven templates — with, in two of those pages, one
|
|
// click handler per entry instead of one per menu.
|
|
//
|
|
// Run: node tests/leftMenu.test.cjs
|
|
|
|
const assert = require('assert');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
let passed = 0;
|
|
function test(name, fn) {
|
|
fn();
|
|
passed += 1;
|
|
console.log(' ok -', name);
|
|
}
|
|
|
|
const root = path.join(__dirname, '..');
|
|
const read = p => fs.readFileSync(path.join(root, p), 'utf8');
|
|
|
|
const libSrc = read('models/lib/leftMenu.js');
|
|
const jade = read('client/components/settings/leftMenu.jade');
|
|
const css = read('client/components/settings/settingBody.css');
|
|
const tableCss = read('client/components/settings/tablePage.css');
|
|
const doc = read('docs/Design/Page/Left-Menu.md');
|
|
|
|
const lib = {};
|
|
new Function('exports', libSrc.replace(/export function/g, 'function') +
|
|
'\nexports.buildMenuItems = buildMenuItems;\nexports.activeCount = activeCount;' +
|
|
'\nexports.leftMenuData = leftMenuData;\nexports.paneTitle = paneTitle;')(lib);
|
|
|
|
console.log('leftMenu:');
|
|
|
|
// ── pure helpers ────────────────────────────────────────────────────────────
|
|
|
|
test('buildMenuItems marks exactly one entry active', () => {
|
|
const items = lib.buildMenuItems([
|
|
{ id: 'a', icon: 'fa-key', labelKey: 'registration' },
|
|
{ id: 'b', icon: 'fa-envelope', labelKey: 'email' },
|
|
{ id: 'c', icon: 'fa-users', labelKey: 'accounts' },
|
|
], 'b');
|
|
assert.strictEqual(items.length, 3);
|
|
assert.strictEqual(lib.activeCount(items), 1,
|
|
'a menu must never highlight two rows - that is what per-entry isXActive ' +
|
|
'helpers drift into');
|
|
assert.strictEqual(items[1].active, true);
|
|
assert.strictEqual(items[0].active, false);
|
|
});
|
|
|
|
test('an unknown or missing active id highlights nothing (negative)', () => {
|
|
const items = [{ id: 'a', labelKey: 'x' }, { id: 'b', labelKey: 'y' }];
|
|
assert.strictEqual(lib.activeCount(lib.buildMenuItems(items, 'nope')), 0);
|
|
assert.strictEqual(lib.activeCount(lib.buildMenuItems(items, undefined)), 0);
|
|
assert.strictEqual(lib.activeCount(lib.buildMenuItems(items, '')), 0);
|
|
});
|
|
|
|
test('a numeric id still matches the active id', () => {
|
|
const items = lib.buildMenuItems([{ id: 1, labelKey: 'x' }], '1');
|
|
assert.strictEqual(items[0].active, true, 'compared as strings');
|
|
});
|
|
|
|
test('conditional entries and separators are handled', () => {
|
|
// A page builds its list with holes (the E-mail entry is absent on Sandstorm).
|
|
const items = lib.buildMenuItems([
|
|
{ id: 'a', labelKey: 'x' },
|
|
null,
|
|
{ separator: true },
|
|
{ id: 'b', labelKey: 'y' },
|
|
], 'b');
|
|
assert.strictEqual(items.length, 3, 'the null hole is dropped, not rendered');
|
|
assert.deepStrictEqual(items[1], { separator: true });
|
|
assert.strictEqual(items[2].active, true);
|
|
});
|
|
|
|
test('buildMenuItems survives junk input (negative)', () => {
|
|
assert.deepStrictEqual(lib.buildMenuItems(null, 'a'), []);
|
|
assert.deepStrictEqual(lib.buildMenuItems(undefined, undefined), []);
|
|
assert.strictEqual(lib.activeCount(null), 0);
|
|
// An entry with no id/icon/label renders as empty strings, not "undefined".
|
|
const [item] = lib.buildMenuItems([{}], '');
|
|
assert.deepStrictEqual(
|
|
{ id: item.id, icon: item.icon, labelKey: item.labelKey }, { id: '', icon: '', labelKey: '' });
|
|
});
|
|
|
|
test('the page keeps its own handler class alongside the shared one', () => {
|
|
const [item] = lib.buildMenuItems([{ id: 'a', labelKey: 'x' }], 'a', 'js-setting-menu');
|
|
assert.strictEqual(item.jsClass, 'js-setting-menu');
|
|
// Per-entry override wins, so a page can keep one odd entry on its own handler.
|
|
const [own] = lib.buildMenuItems([{ id: 'a', labelKey: 'x', jsClass: 'js-other' }], 'a', 'js-setting-menu');
|
|
assert.strictEqual(own.jsClass, 'js-other');
|
|
});
|
|
|
|
// ── the template ────────────────────────────────────────────────────────────
|
|
|
|
test('the template renders the menu once, from the item list', () => {
|
|
assert.ok(/template\(name="leftMenu"\)/.test(jade));
|
|
assert.ok(/\.side-menu/.test(jade) && /each items/.test(jade),
|
|
'one .side-menu, driven by the items');
|
|
assert.ok(/js-left-menu-item/.test(jade),
|
|
'every entry carries the shared handler class');
|
|
assert.ok(/data-id="\{\{id\}\}"/.test(jade), 'the id is what a handler reads');
|
|
assert.ok(/\{\{_ labelKey\}\}/.test(jade), 'labels are i18n keys, not literals');
|
|
assert.ok(/if separator/.test(jade), 'group separators are supported');
|
|
});
|
|
|
|
test('the template pins no physical side', () => {
|
|
// The side comes from the document direction and logical CSS. A physical side
|
|
// in the markup is how you get a right-hand menu whose contents still read
|
|
// left. (The class name js-left-menu-item is a NAME, not a placement.)
|
|
const markup = jade.replace(/^\s*\/\/-.*$/gm, '');
|
|
assert.ok(!/style=/.test(markup), 'no inline styles to hide a side in');
|
|
assert.ok(!/(padding|margin|border)-(left|right)|text-align:\s*(left|right)|float:/.test(markup),
|
|
'no physical side properties in the markup');
|
|
});
|
|
|
|
// ── side and mirroring ──────────────────────────────────────────────────────
|
|
|
|
test('the menu mirrors under a right-to-left language', () => {
|
|
const menu = css.slice(css.indexOf('.side-menu {'), css.indexOf('.content-body .main-body {'));
|
|
// Physical properties do not flip; logical ones do.
|
|
assert.ok(!/padding-left|padding-right|margin-left|margin-right/.test(menu),
|
|
'use padding-inline-* / margin-inline-*, never the physical side');
|
|
assert.ok(/padding-inline-start/.test(menu),
|
|
'the entry indent must follow the reading direction');
|
|
assert.ok(/margin-inline-end/.test(menu),
|
|
'the gap after the icon must follow the reading direction');
|
|
// An inset shadow offset sideways is physical too - it shaded the wrong inner
|
|
// edge once the menu mirrored to the right.
|
|
assert.ok(!/box-shadow: inset -/.test(menu),
|
|
'an inset shadow must not be offset on the X axis');
|
|
});
|
|
|
|
test('a long menu scrolls inside the panel instead of spilling out of it', () => {
|
|
// Admin Panel / Problems is the longest menu: 15 entries. The panel is a flex item
|
|
// stretched to the row height, so its background, border and rounded corners stop at
|
|
// the bottom of the page - and with the default `overflow: visible` the entries kept
|
|
// rendering past that edge, on the page's grey with no panel behind them.
|
|
const panel = /\.side-menu \{([^}]*)\}/.exec(css);
|
|
assert.ok(panel, 'the panel must be styled');
|
|
assert.ok(/overflow-y:\s*auto/.test(panel[1]),
|
|
'a menu taller than the page must scroll inside its own panel');
|
|
assert.ok(/min-height:\s*0/.test(panel[1]),
|
|
'without min-height:0 a flex item will not shrink below its content, and the '
|
|
+ 'overflow never engages');
|
|
// The panel keeps its own background, so whatever is visible always sits on it.
|
|
assert.ok(/background-color:/.test(panel[1]), 'the panel still has its background');
|
|
});
|
|
|
|
test('the design doc states which side, both ways', () => {
|
|
assert.ok(/left-to-right/i.test(doc) && /right-to-left/i.test(doc),
|
|
'both directions must be described');
|
|
assert.ok(/mirror/i.test(doc), 'and that the panel mirrors');
|
|
assert.ok(/dir=rtl/.test(doc), 'naming the mechanism');
|
|
});
|
|
|
|
// ── theme ───────────────────────────────────────────────────────────────────
|
|
|
|
test('the selected entry looks like the selected tab in the bar above', () => {
|
|
// Filled with the theme colour, label and icon white - the same treatment
|
|
// settingHeader.css gives `.setting-header-btn.active`. Before this the entry kept
|
|
// the panel grey on white, which is easy to miss.
|
|
const fill = /\.side-menu ul li\.active,\s*[^{]*li\.active:hover \{([^}]*)\}/.exec(css);
|
|
assert.ok(fill, 'the selected entry must be filled');
|
|
assert.ok(/background: var\(--theme-accent, #[0-9a-f]{6}\)/.test(fill[1]),
|
|
'a per-user accent fills it, falling back to the WeKan header blue so the menu ' +
|
|
'matches the bar when no colour is chosen');
|
|
// :hover must be in that same selector list. `li:hover` sets white at the SAME
|
|
// specificity and comes later, so without it the fill vanishes under the pointer.
|
|
assert.ok(/li\.active:hover/.test(css),
|
|
'hovering the selected entry must not wash it back to white');
|
|
// Label AND icon go white together. Comments are stripped first: the rule explains
|
|
// in prose why it is not `inherit`, which a naive text search would trip over.
|
|
const code = css.replace(/\/\*[\s\S]*?\*\//g, '');
|
|
const text = /\.side-menu ul li\.active > a,\s*[^{]*li\.active > a i \{([^}]*)\}/.exec(code);
|
|
assert.ok(text, 'label and icon must be coloured together');
|
|
assert.ok(/color: #fff/.test(text[1]), 'white on the filled background');
|
|
assert.ok(!/inherit/.test(text[1]),
|
|
'inheriting the panel grey is what made the selected entry invisible');
|
|
});
|
|
|
|
test('the design doc explains the theming', () => {
|
|
assert.ok(/## Theme/.test(doc));
|
|
assert.ok(/--theme-accent/.test(doc) && /Change color/.test(doc),
|
|
'name the per-user override and where it is set');
|
|
assert.ok(/inherit/.test(doc), 'and the fallback that keeps the default look');
|
|
});
|
|
|
|
// ── layout shared with the table page ───────────────────────────────────────
|
|
|
|
test('narrow windows stack the menu above the content', () => {
|
|
const at = tableCss.indexOf('@media screen and (max-width: 800px)');
|
|
assert.ok(at > 0, 'the stacking rule lives with the table page and covers both');
|
|
const block = tableCss.slice(at);
|
|
assert.ok(/\.side-menu \{[^}]*width:\s*100%/.test(block));
|
|
assert.ok(/\.content-body \{\s*flex-wrap:\s*wrap/.test(block));
|
|
});
|
|
|
|
// ── the doc ─────────────────────────────────────────────────────────────────
|
|
|
|
test('the related-files table lists files that exist', () => {
|
|
assert.ok(doc.includes('| File Path | File Type | Description |'),
|
|
'the related-files table must have those three columns');
|
|
const paths = [...doc.matchAll(/\| `([a-z][\w./-]+\.(?:jade|css|js|cjs))` \|/g)].map(m => m[1]);
|
|
assert.ok(paths.length >= 10, `expected the full file list, found ${paths.length}`);
|
|
for (const rel of paths) {
|
|
assert.ok(fs.existsSync(path.join(root, rel)), `related file missing: ${rel}`);
|
|
}
|
|
assert.strictEqual(new Set(paths).size, paths.length, 'no file listed twice');
|
|
});
|
|
|
|
test('the two page designs cross-link', () => {
|
|
assert.ok(/\[Table\]\(Table\.md\)/.test(doc),
|
|
'Left-Menu.md must link to Table.md - the two compose on the same page');
|
|
assert.ok(fs.existsSync(path.join(root, 'docs/Design/Page/Table.md')));
|
|
});
|
|
|
|
// ── the template and the pages must agree on the data shape ─────────────────
|
|
|
|
test('what the pages pass is what the template iterates', () => {
|
|
// The whole Admin Panel lost its left menu to this. leftMenu.jade iterates
|
|
// `each items`, and every page handed it the bare ARRAY from buildMenuItems - so
|
|
// Spacebars looked `items` up ON the array, found nothing, and rendered an empty
|
|
// panel on Settings, People, Features, Attachments, Version and Problems alike.
|
|
// Nothing failed: the template was fine, the helper was fine, only the seam between
|
|
// them was wrong. Neither half can be checked alone, so check the seam.
|
|
const iterated = /^\s*each (\w+)\s*$/m.exec(jade);
|
|
assert.ok(iterated, 'the template must iterate a named variable');
|
|
const key = iterated[1];
|
|
const context = lib.leftMenuData([{ id: 'a', labelKey: 'x' }], 'a');
|
|
assert.ok(!Array.isArray(context),
|
|
'a bare array cannot carry a named property for the template to iterate');
|
|
assert.ok(Array.isArray(context[key]),
|
|
`the template iterates \`${key}\`, so the data context must have a \`${key}\` array`);
|
|
assert.strictEqual(context[key].length, 1, 'and it must hold the built entries');
|
|
});
|
|
|
|
test('every page builds its context through that one helper', () => {
|
|
// Six pages, one shape. Calling buildMenuItems directly returns the array again and
|
|
// silently empties that page's menu, so no page may do it.
|
|
const pages = ['settingBody', 'peopleBody', 'attachments', 'adminReports'];
|
|
for (const page of pages) {
|
|
const src = read(`client/components/settings/${page}.js`);
|
|
const helper = /menuItems\(\) \{[\s\S]*?\n \},/.exec(src);
|
|
assert.ok(helper, `${page}: must have a menuItems helper`);
|
|
assert.ok(/leftMenuData\(/.test(helper[0]),
|
|
`${page}: must build its context with leftMenuData`);
|
|
assert.ok(!/return buildMenuItems\(/.test(helper[0]),
|
|
`${page}: returning the bare array renders an empty menu`);
|
|
}
|
|
});
|
|
|
|
// ── pages converted to the shared menu ──────────────────────────────────────
|
|
|
|
test('Admin Panel / Problems renders the shared menu from data', () => {
|
|
const jade = read('client/components/settings/adminReports.jade');
|
|
// Strip line comments: the collapsed handlers are DESCRIBED in a comment there.
|
|
const js = read('client/components/settings/adminReports.js').replace(/^\s*\/\/.*$/gm, '');
|
|
assert.ok(/\+leftMenu\(menuItems\)/.test(jade), 'renders the shared menu');
|
|
assert.ok(!/\.side-menu/.test(jade), 'no hand-written .side-menu markup left');
|
|
assert.ok(/PROBLEMS_MENU = \[/.test(js), 'its entries are a data list');
|
|
assert.ok(/leftMenuData\(PROBLEMS_MENU/.test(js), 'built by the shared helper');
|
|
// Twelve identical per-entry handlers collapsed to one on the shared class.
|
|
assert.strictEqual((js.match(/'click a\.js-report-/g) || []).length, 0,
|
|
'the per-entry handlers must be gone');
|
|
assert.strictEqual((js.match(/'click \.js-left-menu-item'/g) || []).length, 1,
|
|
'exactly one menu handler');
|
|
// The active row is rendered from activeReport, so the hand DOM toggling that
|
|
// used to fight a re-render must be gone.
|
|
assert.ok(!/side-menu li\.active'\)\.removeClass/.test(js),
|
|
'no manual active-class toggling');
|
|
});
|
|
|
|
test('the shared menu reproduces each page icon shape', () => {
|
|
// Same styling after conversion: an empty span.emoji-icon (Settings,
|
|
// Features), a coloured wrapper (People / Locked users), or a bare icon.
|
|
assert.ok(/if iconWrapCls/.test(jade) && /if emoji/.test(jade),
|
|
'all three icon shapes must be supported');
|
|
const [plain] = lib.buildMenuItems([{ id: 'a', icon: 'fa-list', labelKey: 'x' }], 'a');
|
|
assert.strictEqual(plain.emoji, false);
|
|
assert.strictEqual(plain.iconWrapCls, '');
|
|
const [emoji] = lib.buildMenuItems([{ id: 'b', icon: 'fa-key', labelKey: 'y', emoji: true }], 'b');
|
|
assert.strictEqual(emoji.emoji, true);
|
|
const [red] = lib.buildMenuItems([{ id: 'c', icon: 'fa-lock', labelKey: 'z', iconWrapCls: 'text-red' }], 'c');
|
|
assert.strictEqual(red.iconWrapCls, 'text-red');
|
|
});
|
|
|
|
test('Settings renders the shared menu too', () => {
|
|
// The menu builders take the current user now: multitenancy option D gives an
|
|
// Organization's own admin a shorter menu (docs/Design/Multitenancy/Multitenancy.md).
|
|
const pages = [
|
|
['settingBody', 'settingsMenu(', 'js-setting-menu'],
|
|
];
|
|
for (const [file, list, jsClass] of pages) {
|
|
const pageJade = read(`client/components/settings/${file}.jade`);
|
|
const pageJs = read(`client/components/settings/${file}.js`);
|
|
assert.ok(/\+leftMenu\(menuItems\)/.test(pageJade), `${file}: renders the shared menu`);
|
|
assert.ok(!/\.side-menu/.test(pageJade), `${file}: no hand-written menu markup left`);
|
|
assert.ok(pageJs.includes(`leftMenuData(${list}`), `${file}: built by the shared helper`);
|
|
assert.ok(pageJs.includes(jsClass), `${file}: keeps its own handler class`);
|
|
}
|
|
});
|
|
|
|
test('the Sandstorm exception moved to People with the E-mail pane', () => {
|
|
// Login and E-mail are People panes now, so the entry that is dropped on a
|
|
// Sandstorm deployment lives with them.
|
|
const people = read('client/components/settings/peopleBody.js');
|
|
assert.ok(/isSandstorm \? null :/.test(people),
|
|
'the e-mail entry is still absent on Sandstorm - a dropped null, not empty markup');
|
|
assert.ok(/function peopleMenu\(\)/.test(people),
|
|
'so the menu is built by a function, which can read Meteor.settings at call time');
|
|
const settings = read('client/components/settings/settingBody.js');
|
|
assert.ok(!/isSandstorm/.test(settings),
|
|
'and Settings no longer needs the check - its conditional entry left');
|
|
});
|
|
|
|
test('Settings still maps every pane it can open to one active id', () => {
|
|
const js = read('client/components/settings/settingBody.js');
|
|
assert.ok(/function activeSettingId/.test(js),
|
|
'the per-pane vars are mapped to ONE active id');
|
|
// Every pane the menu can open must be mapped, or that entry never highlights.
|
|
// No registration-setting/email-setting: those two moved to Admin Panel / People.
|
|
for (const id of ['tableVisibilityMode-setting',
|
|
'announcement-setting', 'accessibility-setting',
|
|
'layout-setting', 'webhook-setting']) {
|
|
assert.ok(js.includes(`'${id}'`), `${id} must be in both the menu and the id map`);
|
|
}
|
|
for (const gone of ['registration-setting', 'email-setting']) {
|
|
assert.ok(!js.includes(`'${gone}'`), `${gone} moved to People and must not linger here`);
|
|
}
|
|
});
|
|
|
|
test('Admin Panel / People renders the shared menu from data', () => {
|
|
const pageJade = read('client/components/settings/peopleBody.jade');
|
|
const pageJs = read('client/components/settings/peopleBody.js').replace(/^\s*\/\/.*$/gm, '');
|
|
assert.ok(/\+leftMenu\(menuItems\)/.test(pageJade), 'renders the shared menu');
|
|
assert.ok(!/\.side-menu/.test(pageJade), 'no hand-written menu markup left');
|
|
// A function rather than a bare array since the E-mail entry it gained is dropped
|
|
// on Sandstorm, which has to be read at call time.
|
|
assert.ok(/function peopleMenu\(user\)/.test(pageJs) && /leftMenuData\(peopleMenu\(/.test(pageJs),
|
|
'its entries are data, built by the shared helper - and take the user, since an '
|
|
+ 'Organization\'s own admin gets a shorter menu (multitenancy option D)');
|
|
// Seven near-identical handlers collapsed to one.
|
|
for (const old of ['js-org-menu', 'js-team-menu', 'js-people-menu',
|
|
'js-locked-users-menu', 'js-roles-menu', 'js-templates-menu', 'js-domains-menu']) {
|
|
assert.ok(!pageJs.includes(old), `${old} must be gone`);
|
|
}
|
|
assert.strictEqual((pageJs.match(/'click \.js-left-menu-item'/g) || []).length, 1,
|
|
'exactly one menu handler');
|
|
// The per-pane extras must survive the collapse.
|
|
for (const extra of ['refreshOrgsCount', 'refreshTeamsCount', 'refreshUsersCount']) {
|
|
assert.ok(pageJs.includes(extra), `${extra} must still run on its pane`);
|
|
}
|
|
// Active row from state, not from a hand-toggled class. The page opens on the
|
|
// FIRST entry of the menu this user actually has: Login for the site admin, as
|
|
// before - and Organizations for an Organization's own admin, who has no Login
|
|
// pane (multitenancy option D). One helper decides both, so the open pane and the
|
|
// highlighted row can never disagree.
|
|
assert.ok(/function firstPeoplePaneId\(user\)/.test(pageJs),
|
|
'the first pane of the user\'s own menu');
|
|
assert.ok(/activeMenuId = new ReactiveVar\(openPaneId\)/.test(pageJs),
|
|
'the open pane is state, and starts on the first entry in the menu');
|
|
assert.ok(/registrationSetting = new ReactiveVar\(openPaneId === 'registration-setting'\)/.test(pageJs),
|
|
'and that pane is the one whose var starts true');
|
|
assert.ok(/orgSetting = new ReactiveVar\(openPaneId === 'org-setting'\)/.test(pageJs),
|
|
'the pane that used to open first must no longer also start true');
|
|
assert.ok(!/side-menu li\.active'\)\.removeClass/.test(pageJs),
|
|
'no manual active-class toggling');
|
|
assert.ok(/iconWrapCls: 'text-red'/.test(pageJs),
|
|
'Locked users keeps its red lock');
|
|
});
|
|
|
|
test('EVERY Admin Panel page renders the shared menu', () => {
|
|
// The design is only worth having if nothing is left outside it.
|
|
// Translation and Version moved INTO Settings as panes, so neither has a menu of
|
|
// its own any more - they are entries in the Settings menu.
|
|
const pages = ['settingBody', 'peopleBody', 'attachments', 'adminReports'];
|
|
for (const page of pages) {
|
|
const pageJade = read(`client/components/settings/${page}.jade`);
|
|
assert.ok(/\+leftMenu\(menuItems\)/.test(pageJade), `${page}: renders the shared menu`);
|
|
assert.ok(!/\.side-menu/.test(pageJade), `${page}: no hand-written menu markup left`);
|
|
}
|
|
});
|
|
|
|
test('the Attachments Sandstorm pane is commented out, code and all', () => {
|
|
// It only had content inside a grain - the MongoDB 3 -> FerretDB migration
|
|
// report and a button that DELETED the raw MongoDB 3 files. Compacting the
|
|
// database frees that space too, so the pane is commented out rather than
|
|
// deleted: no menu entry, no template, no helpers, no state, no handler, and
|
|
// nothing of it runs. The grain migration itself is untouched.
|
|
const js = read('client/components/settings/attachments.js');
|
|
const pageJade = read('client/components/settings/attachments.jade');
|
|
const liveJs = js.replace(/^\s*\/\/.*$/gm, '');
|
|
const liveJade = pageJade.replace(/^\s*\/\/-.*$/gm, '');
|
|
assert.ok(/\/\/ \{ id: 'sandstorm', icon: 'fa-hdd-o', label: 'Sandstorm'/.test(js),
|
|
'the menu entry is kept as a comment');
|
|
assert.ok(!/sandstorm/i.test(liveJs),
|
|
'no live line of the page mentions Sandstorm any more');
|
|
assert.ok(!/sandstorm/i.test(liveJade),
|
|
'and its pane is commented out of the template');
|
|
// Everything else on the page keeps working: the storages, their stats, the
|
|
// database migration and Backup.
|
|
for (const kept of ['isBackupActive', 'isDatabaseMigrationActive', 'isGridFsActive',
|
|
'isFilesystemActive', 'isS3Active', 'isMoveActive']) {
|
|
assert.ok(liveJs.includes(kept) && liveJade.includes(kept),
|
|
`${kept} must still be live`);
|
|
}
|
|
// The literal-label path the entry used is still supported by the design, for
|
|
// the next proper noun that needs it.
|
|
assert.ok(/if labelKey[\s\S]*\{\{_ labelKey\}\}[\s\S]*else[\s\S]*\{\{label\}\}/.test(jade),
|
|
'the template falls back to a literal label');
|
|
const [lit] = lib.buildMenuItems([{ id: 's', label: 'Sandstorm' }], 's');
|
|
assert.strictEqual(lit.label, 'Sandstorm');
|
|
assert.strictEqual(lit.labelKey, '');
|
|
});
|
|
|
|
test('no pane repeats the title the section already rendered', () => {
|
|
// The heading comes from the menu entry now, so a pane that also prints its own
|
|
// name shows the same word twice - every Attachments pane did (`h3 Backup` under
|
|
// a title reading "Backup"). A heading that says something the label does not -
|
|
// Limits' "Attachment And API File Size Limits", Locked users' "Brute Force
|
|
// Protection Settings" - is not a repeat, and stays.
|
|
const en = JSON.parse(read('imports/i18n/data/en.i18n.json'));
|
|
const pages = ['settingBody', 'peopleBody', 'attachments', 'adminReports',
|
|
'informationBody', 'translationBody'];
|
|
// Every menu label rendered anywhere in the Admin Panel.
|
|
const labels = new Set();
|
|
for (const page of ['settingBody', 'peopleBody', 'attachments', 'adminReports']) {
|
|
const src = read(`client/components/settings/${page}.js`);
|
|
for (const m of src.matchAll(/labelKey: '([\w-]+)'/g)) labels.add(m[1]);
|
|
for (const m of src.matchAll(/label: '([^']+)'/g)) labels.add(m[1]);
|
|
}
|
|
for (const page of pages) {
|
|
const pageJade = read(`client/components/settings/${page}.jade`);
|
|
for (const m of pageJade.matchAll(/^\s*h[1-3] (?:\{\{_ '([\w-]+)'\}\}|(\S.*))$/gm)) {
|
|
const [, key, literal] = m;
|
|
if (key) {
|
|
assert.ok(!labels.has(key),
|
|
`${page}: a heading of {{_ '${key}'}} repeats the menu label above it`);
|
|
} else if (literal) {
|
|
const text = literal.trim();
|
|
assert.ok(!labels.has(text) && !Object.entries(en).some(
|
|
([k, v]) => labels.has(k) && v === text),
|
|
`${page}: a heading of "${text}" repeats the menu label above it`);
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
test('a heading names a group and cannot be clicked or selected', () => {
|
|
const [heading] = lib.buildMenuItems([{ heading: true, labelKey: 'reports' }], 'reports');
|
|
assert.strictEqual(heading.heading, true);
|
|
assert.strictEqual(heading.labelKey, 'reports');
|
|
// No id, no icon, no handler class - so there is nothing to click, and the page's
|
|
// click handler has no data-id to read even if something reached it.
|
|
assert.strictEqual(heading.id, undefined);
|
|
assert.strictEqual(heading.jsClass, undefined);
|
|
// And it can never be the active row, or a group name could become a pane title.
|
|
assert.strictEqual(heading.active, undefined);
|
|
assert.deepStrictEqual(lib.paneTitle([{ heading: true, labelKey: 'reports' }], 'reports'), {});
|
|
assert.strictEqual(lib.activeCount(lib.buildMenuItems(
|
|
[{ heading: true, labelKey: 'reports' }, { id: 'a', labelKey: 'x' }], 'a')), 1);
|
|
// The template renders it as text in an <li>, with no anchor.
|
|
const block = /else if heading\n([\s\S]*?)\n else\n/.exec(jade);
|
|
assert.ok(block, 'the template must have a heading branch');
|
|
assert.ok(/li\.left-menu-heading/.test(block[1]), 'as its own row class');
|
|
assert.ok(!/a\./.test(block[1]) && !/data-id/.test(block[1]),
|
|
'a heading must not render an anchor or a data-id');
|
|
// ...and it does not light up under the pointer like a row you can open.
|
|
assert.ok(/li\.left-menu-heading:hover \{[^}]*background:\s*transparent/.test(css)
|
|
|| /li\.left-menu-separator:hover,\s*\n[^{]*li\.left-menu-heading:hover \{[^}]*background:\s*transparent/.test(css),
|
|
'the heading must opt out of the entry hover highlight');
|
|
});
|
|
|
|
test('the first entry of a menu is the pane that opens', () => {
|
|
// Settings opens on Version, Attachments on Backup: the row at the top of the
|
|
// menu and the pane on the right must be the same one, or the page opens with a
|
|
// pane nobody chose while the menu highlights a different row.
|
|
const firstId = (src, fn) => {
|
|
const menu = new RegExp(`function ${fn}\\(\\) \\{[\\s\\S]*?\\n\\}`).exec(src)[0];
|
|
return /id: '([\w-]+)'/.exec(menu)[1];
|
|
};
|
|
const attachments = read('client/components/settings/attachments.js');
|
|
assert.strictEqual(firstId(attachments, 'attachmentsMenu'), 'backup',
|
|
'Backup must be the first Attachments entry');
|
|
assert.ok(/this\.activeSection = new ReactiveVar\('backup'\)/.test(attachments),
|
|
'and the section the page opens on');
|
|
const settings = read('client/components/settings/settingBody.js');
|
|
assert.strictEqual(firstId(settings, 'settingsMenu'), 'version-setting',
|
|
'Version must be the first Settings entry');
|
|
});
|
|
|
|
test('Translation is a Settings pane, not a page of its own', () => {
|
|
const js = read('client/components/settings/settingBody.js');
|
|
const jadeSrc = read('client/components/settings/settingBody.jade');
|
|
assert.ok(/id: 'translation-setting'/.test(js), 'it is an entry in the Settings menu');
|
|
assert.ok(/\+translationSettings/.test(jadeSrc), 'and Settings renders the pane');
|
|
// The old top-level tab and its helper are gone.
|
|
const header = read('client/components/settings/settingHeader.jade');
|
|
assert.ok(!/pathFor 'translation'/.test(header), 'the Admin Panel tab must be gone');
|
|
assert.ok(!/isTranslationActive/.test(read('client/components/settings/settingHeader.js')));
|
|
// The pane carries the state that feeds its table - a child template cannot
|
|
// see a parent page that no longer renders it.
|
|
const body = read('client/components/settings/translationBody.js');
|
|
assert.ok(/Template\.translationSettings\.onCreated/.test(body));
|
|
assert.ok(!/Template\.translation\./.test(body), 'the old page template must be gone');
|
|
// The URL still resolves, redirecting rather than rendering a dead template.
|
|
const router = read('config/router.js');
|
|
assert.ok(!/content: 'translation'/.test(router), 'it must not render the old template');
|
|
assert.ok(/FlowRouter\.go\('setting'\)/.test(router), 'a bookmark must land in Settings');
|
|
});
|
|
|
|
// ── the pane title: every Admin Panel pane has one, and they are identical ──
|
|
|
|
test('paneTitle returns the ACTIVE entry label, in either of its two forms', () => {
|
|
const menu = [
|
|
{ id: 'a', labelKey: 'people' },
|
|
{ id: 'b', labelKey: 'teams' },
|
|
{ id: 'c', label: 'Sandstorm' },
|
|
];
|
|
assert.deepStrictEqual(lib.paneTitle(menu, 'b'), { titleKey: 'teams', label: '' });
|
|
// A literal label (a proper noun) comes back as a label, not as an i18n key.
|
|
assert.deepStrictEqual(lib.paneTitle(menu, 'c'), { titleKey: '', label: 'Sandstorm' });
|
|
});
|
|
|
|
test('paneTitle gives nothing rather than an empty heading (negative)', () => {
|
|
// No selection, an id that is not in the menu, junk: a page renders NO title
|
|
// rather than an empty <h1> with a stray margin under it.
|
|
assert.deepStrictEqual(lib.paneTitle([{ id: 'a', labelKey: 'x' }], 'nope'), {});
|
|
assert.deepStrictEqual(lib.paneTitle([], 'a'), {});
|
|
assert.deepStrictEqual(lib.paneTitle(null, undefined), {});
|
|
// A separator can never become a title.
|
|
assert.deepStrictEqual(lib.paneTitle([{ separator: true }], ''), {});
|
|
});
|
|
|
|
test('the title template renders the active label, and only when there is one', () => {
|
|
const at = jade.indexOf('template(name="paneTitle")');
|
|
assert.ok(at > 0, 'the shared title template must exist beside the menu');
|
|
const tpl = jade.slice(at);
|
|
assert.ok(/if titleKey/.test(tpl) && /else if label/.test(tpl),
|
|
'both forms of an entry label must render');
|
|
assert.ok(/h1\.admin-pane-title/.test(tpl), 'one class, so every pane title matches');
|
|
assert.strictEqual((tpl.match(/h1\./g) || []).length, 2,
|
|
'the heading exists once per branch and nowhere else');
|
|
});
|
|
|
|
test('EVERY Admin Panel page renders the shared pane title', () => {
|
|
// The point of deriving it from the menu: no pane can end up without a heading,
|
|
// or with one of its own size. Before this only the table pages had a title.
|
|
const pages = ['settingBody', 'peopleBody', 'attachments', 'adminReports'];
|
|
for (const page of pages) {
|
|
const pageJade = read(`client/components/settings/${page}.jade`);
|
|
const pageJs = read(`client/components/settings/${page}.js`);
|
|
assert.ok(/\+paneTitle\(paneTitleData\)/.test(pageJade),
|
|
`${page}: must render +paneTitle(paneTitleData) inside .main-body`);
|
|
// ...as the FIRST thing in the pane, above whatever is showing.
|
|
const body = pageJade.indexOf('.main-body');
|
|
assert.ok(pageJade.indexOf('+paneTitle(paneTitleData)') > body,
|
|
`${page}: the title belongs inside .main-body`);
|
|
// Blaze resolves a name against the CURRENT template, so the helper has to be
|
|
// registered on the template that renders it - not on an enclosing one.
|
|
assert.ok(/paneTitleData\(\) \{[\s\S]*?paneTitle\(/.test(pageJs),
|
|
`${page}: paneTitleData must call the shared paneTitle helper`);
|
|
assert.ok(/import \{[^}]*paneTitle[^}]*\} from '\/models\/lib\/leftMenu'/.test(pageJs),
|
|
`${page}: paneTitle must be IMPORTED - an undeclared name throws inside the `
|
|
+ 'helper at render time, and Blaze answers that by rendering nothing');
|
|
}
|
|
});
|
|
|
|
test('the pane title has ONE size, shared with the table page', () => {
|
|
const rule = /\.admin-pane-title \{([^}]*)\}/.exec(css);
|
|
assert.ok(rule, '.admin-pane-title must be styled in the shared admin stylesheet');
|
|
assert.ok(/font-size:/.test(rule[1]) && /font-weight:/.test(rule[1]),
|
|
'size and weight are what make every pane title match');
|
|
assert.ok(/color:\s*inherit/.test(rule[1]),
|
|
'it must inherit its colour so it stays readable on a dark theme');
|
|
// The shared table page uses the same class on its own title, so a table pane
|
|
// and a form pane look the same.
|
|
const tableJade = read('client/components/settings/tablePage.jade');
|
|
assert.ok(/h1\.table-page-title\.admin-pane-title/.test(tableJade),
|
|
'the table page title must carry the shared class too');
|
|
});
|
|
|
|
test('a table page inside the Admin Panel does not print the title twice', () => {
|
|
// The section renders the heading for every pane, so a table page there must
|
|
// pass no titleKey - and the template must render one only if it is given.
|
|
const tableJade = read('client/components/settings/tablePage.jade');
|
|
assert.ok(/if titleKey\n\s+h1\./.test(tableJade),
|
|
'the table page title is conditional, not unconditional markup');
|
|
for (const [file, panes] of [
|
|
['peopleBody', ["titleKey: 'people'", "titleKey: 'teams'", "titleKey: 'organizations'", 'titleKey: "domains"']],
|
|
['adminReports', ['titleKey: spec.titleKey', 'title: TAPi18n.__(eventStreamTitleKey']],
|
|
['translationBody', ["titleKey: 'translation'"]],
|
|
]) {
|
|
const src = read(`client/components/settings/${file}.js`);
|
|
for (const gone of panes) {
|
|
assert.ok(!src.includes(gone),
|
|
`${file}: ${gone} would print the pane heading a second time`);
|
|
}
|
|
}
|
|
});
|
|
|
|
test('the doc explains where a pane title comes from', () => {
|
|
const at = doc.indexOf('## The pane title');
|
|
assert.ok(at > 0, 'the design doc must have a pane-title section');
|
|
const section = doc.slice(at, doc.indexOf('## Entries'));
|
|
assert.ok(/paneTitle\(items, activeId\)/.test(section), 'it must name the helper');
|
|
assert.ok(/admin-pane-title/.test(section), 'and the one class that sizes it');
|
|
assert.ok(/Table\.md/.test(section), 'and link to the table page that shares it');
|
|
assert.ok(/no.*titleKey/i.test(section),
|
|
'and say why a table page inside the Admin Panel passes no title');
|
|
});
|
|
|
|
test('Version is the FIRST Settings pane, and has no page of its own', () => {
|
|
const js = read('client/components/settings/settingBody.js');
|
|
const jadeSrc = read('client/components/settings/settingBody.jade');
|
|
// First entry in the menu, and the pane that opens with the page: Admin Panel
|
|
// opens on Settings, so this is what an admin sees first.
|
|
const menu = /function settingsMenu\(user\) \{[\s\S]*?\n\}/.exec(js)[0];
|
|
const ids = [...menu.matchAll(/id: '([\w-]+)'/g)].map(m => m[1]);
|
|
assert.strictEqual(ids[0], 'version-setting', 'Version must be the first entry');
|
|
// …and the pane that is open when the page loads. Multitenancy option D added one
|
|
// caller who has no Version pane - an Organization's own admin, whose only Settings
|
|
// pane is Visibility - so "open Version" is now "open Version if you are the site
|
|
// admin", and Visibility opens for the other one.
|
|
assert.ok(/this\.versionSetting = new ReactiveVar\(siteAdmin\)/.test(js),
|
|
'and the pane that is open when the page loads');
|
|
assert.ok(/this\.tableVisibilityModeSetting = new ReactiveVar\(!siteAdmin\)/.test(js),
|
|
'so Visibility no longer opens by default for the site admin');
|
|
assert.ok(/const siteAdmin = tenantAdmin\.isSiteAdmin\(/.test(js),
|
|
'and the two are decided by one flag, so exactly one pane opens');
|
|
assert.ok(/\+statistics/.test(jadeSrc), 'Settings renders the statistics pane');
|
|
// The old page, its tab and its menu are gone; the URL redirects.
|
|
const info = read('client/components/settings/informationBody.jade');
|
|
assert.ok(!/template\(name='information'\)/.test(info), 'the page template is gone');
|
|
assert.ok(!/\+leftMenu/.test(info), 'and with it the one-entry menu');
|
|
assert.ok(/template\(name='statistics'\)/.test(info), 'the pane itself stays');
|
|
const header = read('client/components/settings/settingHeader.jade');
|
|
assert.ok(!/pathFor 'information'/.test(header), 'the Admin Panel tab must be gone');
|
|
assert.ok(!/isInformationActive/.test(read('client/components/settings/settingHeader.js')));
|
|
const router = read('config/router.js');
|
|
assert.ok(!/content: 'information'/.test(router), 'it must not render the old template');
|
|
const route = router.slice(router.indexOf("FlowRouter.route('/information'"));
|
|
assert.ok(/FlowRouter\.go\('setting'\)/.test(route.slice(0, 400)),
|
|
'a bookmarked /information must land in Settings');
|
|
});
|
|
|
|
console.log(`\nleftMenu: ${passed} tests passed`);
|