redesign console page

This commit is contained in:
2026-09-03 12:31:07 +05:30
parent d39956a2f1
commit e1bb0a5307
22 changed files with 2478 additions and 22 deletions

View File

@@ -0,0 +1,67 @@
import { strict as assert } from 'node:assert';
import { test } from 'node:test';
import { consoleScope } from './consoleScope';
/*
The rules a later refactor is most likely to break are the ones about what a
store user may see. They are asserted here rather than left to be noticed.
*/
const admin = { role: 'admin' as const, branchCount: 13 };
const storeUser = { role: 'store-user' as const, branchCount: 1 };
test('an admin across branches is told the numbers are aggregated', () => {
const scope = consoleScope({ ...admin, selected: null });
assert.equal(scope.countLabel, '13 branches');
assert.equal(scope.isAggregate, true);
assert.match(scope.blurb, /across your branches/);
assert.equal(scope.buddyContext, 'Across your branches');
});
test('one branch is never described as many', () => {
const scope = consoleScope({ role: 'admin', branchCount: 1, selected: null });
assert.equal(scope.countLabel, '1 branch');
});
test('choosing a branch narrows the header, the blurb and Buddy together', () => {
const scope = consoleScope({ ...admin, selected: 1185, branchName: 'R mart' });
assert.equal(scope.countLabel, 'R mart');
assert.equal(scope.blurb, 'Everything trading right now — for R mart.');
assert.equal(scope.buddyContext, 'R mart');
assert.equal(scope.isAggregate, false);
});
test('a store user never aggregates, even if the selection arrives null', () => {
// The frontend pins them, but a pin that fails open is the whole risk. This
// asserts the fallback is "your own store", never "everything".
const scope = consoleScope({ ...storeUser, selected: null });
assert.equal(scope.isAggregate, false);
assert.equal(scope.showBranchOverview, false);
assert.equal(scope.buddyContext, 'your store');
});
test('a store user is never offered the branch overview', () => {
for (const selected of [null, 1185]) {
const scope = consoleScope({ ...storeUser, selected, branchName: 'R mart' });
assert.equal(scope.showBranchOverview, false, String(selected));
}
});
test('the shop section is not called "your shop" when many are in view', () => {
assert.equal(consoleScope({ ...admin, selected: null }).shopSectionTitle, 'Branch performance');
assert.equal(
consoleScope({ ...storeUser, selected: 1185, branchName: 'R mart' }).shopSectionTitle,
'Your shop',
);
});
test('a branch column only earns its width when branches are mixed', () => {
assert.equal(consoleScope({ ...admin, selected: null }).showBranchColumn, true);
assert.equal(consoleScope({ ...admin, selected: 1185 }).showBranchColumn, false);
assert.equal(consoleScope({ ...storeUser, selected: 1185 }).showBranchColumn, false);
});
test('a blank branch name does not produce a sentence with a hole in it', () => {
const scope = consoleScope({ ...admin, selected: 1185, branchName: ' ' });
assert.equal(scope.blurb, 'Everything trading right now — for your store.');
});