@proteinjs/user-ui 1.7.3 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/dist/test/adminInvitedByRendering.test.d.ts +5 -0
- package/dist/test/adminInvitedByRendering.test.d.ts.map +1 -0
- package/dist/test/adminInvitedByRendering.test.js +213 -0
- package/dist/test/adminInvitedByRendering.test.js.map +1 -0
- package/jest.config.js +6 -0
- package/package.json +4 -4
- package/test/adminInvitedByRendering.test.tsx +134 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [1.8.0](https://github.com/proteinjs/user/compare/@proteinjs/user-ui@1.7.3...@proteinjs/user-ui@1.8.0) (2026-08-29)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* invitedBy is a real user reference on the user and invite tables — retyped IN PLACE via ReferenceColumn width adoption (db 1.37.0's maxLength option at the column's original 255 width; a reference stores the same id bytes, so deployed rows read back unchanged and the schema sync sees zero DDL — verified against the emulator in @proteinjs/db-driver-spanner's ReferenceColumnAdoptWidth suite). Writers stamp references: sendInvite mints Reference(user, inviter id), createUser carries the invite's reference onto the new account (devLogin's null unchanged); the purge contract holds — a purged inviter leaves the reference dangling, which IS the pseudonymization. Admin payoff: the generic Users/Invites record tables render the inviter as their linked NAME via db-ui's ReferenceCellValue — bound over the real table declarations by the new user-ui suite. Floors: @proteinjs/db ^1.37.0 (user), @proteinjs/db-ui ^1.13.0 (ui); user-ui's jest config adopts the estate singleton pin user-server carries (CI-inert) ([1c5f32a](https://github.com/proteinjs/user/commit/1c5f32a2603f27c41e39e4cfc07f1c3ff17af827))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
## [1.7.3](https://github.com/proteinjs/user/compare/@proteinjs/user-ui@1.7.2...@proteinjs/user-ui@1.7.3) (2026-08-28)
|
|
7
18
|
|
|
8
19
|
**Note:** Version bump only for package @proteinjs/user-ui
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adminInvitedByRendering.test.d.ts","sourceRoot":"","sources":["../../test/adminInvitedByRendering.test.tsx"],"names":[],"mappings":"AAyCA,OAAO,CAAC,MAAM,CAAC;IAEb,IAAI,wBAAwB,EAAE,OAAO,CAAC;CACvC"}
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
50
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
|
+
};
|
|
52
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
|
+
/**
|
|
54
|
+
* @jest-environment jsdom
|
|
55
|
+
* @jest-environment-options {"customExportConditions": ["node", "node-addons"]}
|
|
56
|
+
*
|
|
57
|
+
* The admin payoff of `invitedBy` being a REFERENCE column: the generic admin record tables
|
|
58
|
+
* (Users, Invites) render the inviter as the referenced user's NAME, linked to their record
|
|
59
|
+
* form — not a raw uuid. The rendering machinery is @proteinjs/db-ui's (ReferenceCellValue,
|
|
60
|
+
* covered generically there); what these assertions bind is that THE REAL user/invite table
|
|
61
|
+
* declarations reach it — i.e. `invitedBy` is a reference column on both tables, through the
|
|
62
|
+
* exact RecordTable surface the admin pages mount.
|
|
63
|
+
*/
|
|
64
|
+
var react_1 = __importDefault(require("react"));
|
|
65
|
+
var client_1 = require("react-dom/client");
|
|
66
|
+
var test_utils_1 = require("react-dom/test-utils");
|
|
67
|
+
var react_router_dom_1 = require("react-router-dom");
|
|
68
|
+
var react_query_1 = require("react-query");
|
|
69
|
+
var ui_1 = require("@proteinjs/ui");
|
|
70
|
+
// ReferenceCellValue resolves through Reference.get(); the fake resolves the inviter to a named
|
|
71
|
+
// record so the enrichment path is observable without a db.
|
|
72
|
+
jest.mock('@proteinjs/db', function () {
|
|
73
|
+
var actual = jest.requireActual('@proteinjs/db');
|
|
74
|
+
var FakeReference = /** @class */ (function () {
|
|
75
|
+
function FakeReference(_table, _id) {
|
|
76
|
+
this._table = _table;
|
|
77
|
+
this._id = _id;
|
|
78
|
+
}
|
|
79
|
+
FakeReference.prototype.get = function () {
|
|
80
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
81
|
+
return __generator(this, function (_a) {
|
|
82
|
+
if (this._table === 'user' && this._id === 'inviter-1') {
|
|
83
|
+
return [2 /*return*/, { id: 'inviter-1', name: 'Ada Inviter' }];
|
|
84
|
+
}
|
|
85
|
+
throw new Error('not visible');
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
};
|
|
89
|
+
return FakeReference;
|
|
90
|
+
}());
|
|
91
|
+
return __assign(__assign({}, actual), { Reference: FakeReference });
|
|
92
|
+
});
|
|
93
|
+
var db_1 = require("@proteinjs/db");
|
|
94
|
+
var db_ui_1 = require("@proteinjs/db-ui");
|
|
95
|
+
var user_1 = require("@proteinjs/user");
|
|
96
|
+
globalThis.IS_REACT_ACT_ENVIRONMENT = true;
|
|
97
|
+
var StubIntersectionObserver = /** @class */ (function () {
|
|
98
|
+
function StubIntersectionObserver() {
|
|
99
|
+
}
|
|
100
|
+
StubIntersectionObserver.prototype.observe = function () { };
|
|
101
|
+
StubIntersectionObserver.prototype.unobserve = function () { };
|
|
102
|
+
StubIntersectionObserver.prototype.disconnect = function () { };
|
|
103
|
+
return StubIntersectionObserver;
|
|
104
|
+
}());
|
|
105
|
+
globalThis.IntersectionObserver = StubIntersectionObserver;
|
|
106
|
+
var inviterReference = function () { return new db_1.Reference(user_1.tables.User.name, 'inviter-1'); };
|
|
107
|
+
var userRow = {
|
|
108
|
+
id: 'user-2',
|
|
109
|
+
name: 'Invited Person',
|
|
110
|
+
email: 'invited@test.local',
|
|
111
|
+
password: 'irrelevant',
|
|
112
|
+
emailVerified: true,
|
|
113
|
+
roles: [],
|
|
114
|
+
invitedBy: inviterReference(),
|
|
115
|
+
};
|
|
116
|
+
var inviteRow = {
|
|
117
|
+
id: 'invite-1',
|
|
118
|
+
email: 'invitee@test.local',
|
|
119
|
+
token: 'tok',
|
|
120
|
+
tokenExpiresAt: null,
|
|
121
|
+
invitedBy: inviterReference(),
|
|
122
|
+
};
|
|
123
|
+
describe('admin tables render invitedBy as the linked inviter', function () {
|
|
124
|
+
var container;
|
|
125
|
+
var root;
|
|
126
|
+
var client;
|
|
127
|
+
beforeEach(function () {
|
|
128
|
+
(0, db_ui_1.clearReferenceNameCache)();
|
|
129
|
+
container = document.createElement('div');
|
|
130
|
+
document.body.appendChild(container);
|
|
131
|
+
root = (0, client_1.createRoot)(container);
|
|
132
|
+
client = new react_query_1.QueryClient({ defaultOptions: { queries: { retry: false, cacheTime: 0 } } });
|
|
133
|
+
});
|
|
134
|
+
afterEach(function () {
|
|
135
|
+
(0, test_utils_1.act)(function () { return root.unmount(); });
|
|
136
|
+
container.remove();
|
|
137
|
+
});
|
|
138
|
+
var mount = function (table, rows, columns) { return __awaiter(void 0, void 0, void 0, function () {
|
|
139
|
+
return __generator(this, function (_a) {
|
|
140
|
+
switch (_a.label) {
|
|
141
|
+
case 0: return [4 /*yield*/, (0, test_utils_1.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
142
|
+
return __generator(this, function (_a) {
|
|
143
|
+
root.render(react_1.default.createElement(react_query_1.QueryClientProvider, { client: client },
|
|
144
|
+
react_1.default.createElement(react_router_dom_1.MemoryRouter, null,
|
|
145
|
+
react_1.default.createElement(db_ui_1.RecordTable, { table: table, tableLoader: new ui_1.StaticTableLoader(rows, { dataKey: "invited-by-".concat(Math.random()), dataQueryKey: 'all' }), hideButtons: true, columns: columns }))));
|
|
146
|
+
return [2 /*return*/];
|
|
147
|
+
});
|
|
148
|
+
}); })];
|
|
149
|
+
case 1:
|
|
150
|
+
_a.sent();
|
|
151
|
+
// one macrotask for the name resolution to land
|
|
152
|
+
return [4 /*yield*/, (0, test_utils_1.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
153
|
+
return __generator(this, function (_a) {
|
|
154
|
+
switch (_a.label) {
|
|
155
|
+
case 0: return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, 0); })];
|
|
156
|
+
case 1:
|
|
157
|
+
_a.sent();
|
|
158
|
+
return [2 /*return*/];
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
}); })];
|
|
162
|
+
case 2:
|
|
163
|
+
// one macrotask for the name resolution to land
|
|
164
|
+
_a.sent();
|
|
165
|
+
return [4 /*yield*/, (0, test_utils_1.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
166
|
+
return __generator(this, function (_a) {
|
|
167
|
+
switch (_a.label) {
|
|
168
|
+
case 0: return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, 0); })];
|
|
169
|
+
case 1:
|
|
170
|
+
_a.sent();
|
|
171
|
+
return [2 /*return*/];
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
}); })];
|
|
175
|
+
case 3:
|
|
176
|
+
_a.sent();
|
|
177
|
+
return [2 /*return*/];
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
}); };
|
|
181
|
+
var invitedByCell = function () { return container.querySelectorAll('tbody td')[1]; };
|
|
182
|
+
it('the Users table links the inviter by name to their user record', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
183
|
+
var link;
|
|
184
|
+
return __generator(this, function (_a) {
|
|
185
|
+
switch (_a.label) {
|
|
186
|
+
case 0: return [4 /*yield*/, mount(user_1.tables.User, [userRow], ['name', 'invitedBy'])];
|
|
187
|
+
case 1:
|
|
188
|
+
_a.sent();
|
|
189
|
+
link = invitedByCell().querySelector('a');
|
|
190
|
+
expect(link).not.toBeNull();
|
|
191
|
+
expect(link.getAttribute('href')).toBe('/record/form?table=user&record=inviter-1');
|
|
192
|
+
expect(invitedByCell().textContent).toBe('Ada Inviter');
|
|
193
|
+
return [2 /*return*/];
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
}); });
|
|
197
|
+
it('the Invites table links the inviter by name to their user record', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
198
|
+
var link;
|
|
199
|
+
return __generator(this, function (_a) {
|
|
200
|
+
switch (_a.label) {
|
|
201
|
+
case 0: return [4 /*yield*/, mount(user_1.tables.Invite, [inviteRow], ['email', 'invitedBy'])];
|
|
202
|
+
case 1:
|
|
203
|
+
_a.sent();
|
|
204
|
+
link = invitedByCell().querySelector('a');
|
|
205
|
+
expect(link).not.toBeNull();
|
|
206
|
+
expect(link.getAttribute('href')).toBe('/record/form?table=user&record=inviter-1');
|
|
207
|
+
expect(invitedByCell().textContent).toBe('Ada Inviter');
|
|
208
|
+
return [2 /*return*/];
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
}); });
|
|
212
|
+
});
|
|
213
|
+
//# sourceMappingURL=adminInvitedByRendering.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adminInvitedByRendering.test.js","sourceRoot":"","sources":["../../test/adminInvitedByRendering.test.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;GAUG;AACH,gDAA0B;AAC1B,2CAAoD;AACpD,mDAA2C;AAC3C,qDAAgD;AAChD,2CAA+D;AAC/D,oCAAkD;AAElD,gGAAgG;AAChG,4DAA4D;AAC5D,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE;IACzB,IAAM,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC,eAAe,CAAC,CAAC;IACnD;QACE,uBACS,MAAc,EACd,GAAY;YADZ,WAAM,GAAN,MAAM,CAAQ;YACd,QAAG,GAAH,GAAG,CAAS;QAClB,CAAC;QACE,2BAAG,GAAT;;;oBACE,IAAI,IAAI,CAAC,MAAM,KAAK,MAAM,IAAI,IAAI,CAAC,GAAG,KAAK,WAAW,EAAE;wBACtD,sBAAO,EAAE,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,aAAa,EAAE,EAAC;qBACjD;oBACD,MAAM,IAAI,KAAK,CAAC,aAAa,CAAC,CAAC;;;SAChC;QACH,oBAAC;IAAD,CAAC,AAXD,IAWC;IACD,6BAAY,MAAM,KAAE,SAAS,EAAE,aAAa,IAAG;AACjD,CAAC,CAAC,CAAC;AAEH,oCAA0C;AAC1C,0CAAwE;AACxE,wCAAuD;AAMvD,UAAU,CAAC,wBAAwB,GAAG,IAAI,CAAC;AAE3C;IAAA;IAIA,CAAC;IAHC,0CAAO,GAAP,cAAW,CAAC;IACZ,4CAAS,GAAT,cAAa,CAAC;IACd,6CAAU,GAAV,cAAc,CAAC;IACjB,+BAAC;AAAD,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WAAW,CAAC,CAAC,EAAA;;oBAA1D,SAA0D,CAAC;oBACrD,IAAI,GAAG,aAAa,EAAE,CAAC,aAAa,CAAC,GAAG,CAAsB,CAAC;oBACrE,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC;oBAC5B,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,0CAA0C,CAAC,CAAC;oBACnF,MAAM,CAAC,aAAa,EAAE,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;;;;SACzD,CAAC,CAAC;IAEH,EAAE,CAAC,kEAAkE,EAAE;;;;wBACrE,qBAAM,KAAK,CAAC,aAAM,CAAC,MAAM,EAAE,CAAC,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC,EAAA;;oBAA/D,SAA+D,CAAC;oBAC1D,IAAI,GAAG,aAAa,EAAE,CAAC,aAAa,CAAC,GAAG,CAAsB,CAAC;oBACrE,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC;oBAC5B,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,0CAA0C,CAAC,CAAC;oBACnF,MAAM,CAAC,aAAa,EAAE,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;;;;SACzD,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/jest.config.js
CHANGED
|
@@ -5,5 +5,11 @@ module.exports = {
|
|
|
5
5
|
},
|
|
6
6
|
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$',
|
|
7
7
|
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
|
|
8
|
+
// One copy of each @proteinjs package per process — a second copy reached through a
|
|
9
|
+
// symlinked estate splits module-level state (the reflection singleton, ReferenceCellValue's
|
|
10
|
+
// name cache). Same pin user-server carries; CI's npm dedupe makes this a no-op there.
|
|
11
|
+
moduleNameMapper: {
|
|
12
|
+
'^@proteinjs/([^/]+)$': '<rootDir>/node_modules/@proteinjs/$1',
|
|
13
|
+
},
|
|
8
14
|
testEnvironment: 'node',
|
|
9
15
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@proteinjs/user-ui",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
4
4
|
"description": "User ui components",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -25,11 +25,11 @@
|
|
|
25
25
|
"@mui/icons-material": "5.14.11",
|
|
26
26
|
"@mui/material": "5.14.11",
|
|
27
27
|
"@proteinjs/db": "^1.35.0",
|
|
28
|
-
"@proteinjs/db-ui": "^1.
|
|
28
|
+
"@proteinjs/db-ui": "^1.13.0",
|
|
29
29
|
"@proteinjs/reflection": "^1.2.0",
|
|
30
30
|
"@proteinjs/server-api": "^3.0.11",
|
|
31
31
|
"@proteinjs/ui": "^4.5.0",
|
|
32
|
-
"@proteinjs/user": "^1.
|
|
32
|
+
"@proteinjs/user": "^1.12.0",
|
|
33
33
|
"@proteinjs/util": "^1.6.1",
|
|
34
34
|
"moment": "2.29.4",
|
|
35
35
|
"react": "18.2.0",
|
|
@@ -56,5 +56,5 @@
|
|
|
56
56
|
},
|
|
57
57
|
"main": "./dist/generated/index.js",
|
|
58
58
|
"types": "./dist/generated/index.d.ts",
|
|
59
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "96ebc933680809c62b8c55bb14604d85a80912a9"
|
|
60
60
|
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jest-environment jsdom
|
|
3
|
+
* @jest-environment-options {"customExportConditions": ["node", "node-addons"]}
|
|
4
|
+
*
|
|
5
|
+
* The admin payoff of `invitedBy` being a REFERENCE column: the generic admin record tables
|
|
6
|
+
* (Users, Invites) render the inviter as the referenced user's NAME, linked to their record
|
|
7
|
+
* form — not a raw uuid. The rendering machinery is @proteinjs/db-ui's (ReferenceCellValue,
|
|
8
|
+
* covered generically there); what these assertions bind is that THE REAL user/invite table
|
|
9
|
+
* declarations reach it — i.e. `invitedBy` is a reference column on both tables, through the
|
|
10
|
+
* exact RecordTable surface the admin pages mount.
|
|
11
|
+
*/
|
|
12
|
+
import React from 'react';
|
|
13
|
+
import { createRoot, Root } from 'react-dom/client';
|
|
14
|
+
import { act } from 'react-dom/test-utils';
|
|
15
|
+
import { MemoryRouter } from 'react-router-dom';
|
|
16
|
+
import { QueryClient, QueryClientProvider } from 'react-query';
|
|
17
|
+
import { StaticTableLoader } from '@proteinjs/ui';
|
|
18
|
+
|
|
19
|
+
// ReferenceCellValue resolves through Reference.get(); the fake resolves the inviter to a named
|
|
20
|
+
// record so the enrichment path is observable without a db.
|
|
21
|
+
jest.mock('@proteinjs/db', () => {
|
|
22
|
+
const actual = jest.requireActual('@proteinjs/db');
|
|
23
|
+
class FakeReference {
|
|
24
|
+
constructor(
|
|
25
|
+
public _table: string,
|
|
26
|
+
public _id?: string
|
|
27
|
+
) {}
|
|
28
|
+
async get() {
|
|
29
|
+
if (this._table === 'user' && this._id === 'inviter-1') {
|
|
30
|
+
return { id: 'inviter-1', name: 'Ada Inviter' };
|
|
31
|
+
}
|
|
32
|
+
throw new Error('not visible');
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return { ...actual, Reference: FakeReference };
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
import { Reference } from '@proteinjs/db';
|
|
39
|
+
import { RecordTable, clearReferenceNameCache } from '@proteinjs/db-ui';
|
|
40
|
+
import { tables, Invite, User } from '@proteinjs/user';
|
|
41
|
+
|
|
42
|
+
declare global {
|
|
43
|
+
// eslint-disable-next-line no-var
|
|
44
|
+
var IS_REACT_ACT_ENVIRONMENT: boolean;
|
|
45
|
+
}
|
|
46
|
+
globalThis.IS_REACT_ACT_ENVIRONMENT = true;
|
|
47
|
+
|
|
48
|
+
class StubIntersectionObserver {
|
|
49
|
+
observe() {}
|
|
50
|
+
unobserve() {}
|
|
51
|
+
disconnect() {}
|
|
52
|
+
}
|
|
53
|
+
(globalThis as any).IntersectionObserver = StubIntersectionObserver;
|
|
54
|
+
|
|
55
|
+
const inviterReference = () => new Reference<User>(tables.User.name, 'inviter-1');
|
|
56
|
+
|
|
57
|
+
const userRow = {
|
|
58
|
+
id: 'user-2',
|
|
59
|
+
name: 'Invited Person',
|
|
60
|
+
email: 'invited@test.local',
|
|
61
|
+
password: 'irrelevant',
|
|
62
|
+
emailVerified: true,
|
|
63
|
+
roles: [],
|
|
64
|
+
invitedBy: inviterReference(),
|
|
65
|
+
} as unknown as User;
|
|
66
|
+
|
|
67
|
+
const inviteRow = {
|
|
68
|
+
id: 'invite-1',
|
|
69
|
+
email: 'invitee@test.local',
|
|
70
|
+
token: 'tok',
|
|
71
|
+
tokenExpiresAt: null,
|
|
72
|
+
invitedBy: inviterReference(),
|
|
73
|
+
} as unknown as Invite;
|
|
74
|
+
|
|
75
|
+
describe('admin tables render invitedBy as the linked inviter', () => {
|
|
76
|
+
let container: HTMLDivElement;
|
|
77
|
+
let root: Root;
|
|
78
|
+
let client: QueryClient;
|
|
79
|
+
|
|
80
|
+
beforeEach(() => {
|
|
81
|
+
clearReferenceNameCache();
|
|
82
|
+
container = document.createElement('div');
|
|
83
|
+
document.body.appendChild(container);
|
|
84
|
+
root = createRoot(container);
|
|
85
|
+
client = new QueryClient({ defaultOptions: { queries: { retry: false, cacheTime: 0 } } });
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
afterEach(() => {
|
|
89
|
+
act(() => root.unmount());
|
|
90
|
+
container.remove();
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
const mount = async (table: any, rows: any[], columns: string[]) => {
|
|
94
|
+
await act(async () => {
|
|
95
|
+
root.render(
|
|
96
|
+
<QueryClientProvider client={client}>
|
|
97
|
+
<MemoryRouter>
|
|
98
|
+
<RecordTable
|
|
99
|
+
table={table}
|
|
100
|
+
tableLoader={new StaticTableLoader(rows, { dataKey: `invited-by-${Math.random()}`, dataQueryKey: 'all' })}
|
|
101
|
+
hideButtons
|
|
102
|
+
columns={columns as any}
|
|
103
|
+
/>
|
|
104
|
+
</MemoryRouter>
|
|
105
|
+
</QueryClientProvider>
|
|
106
|
+
);
|
|
107
|
+
});
|
|
108
|
+
// one macrotask for the name resolution to land
|
|
109
|
+
await act(async () => {
|
|
110
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
111
|
+
});
|
|
112
|
+
await act(async () => {
|
|
113
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
114
|
+
});
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
const invitedByCell = () => container.querySelectorAll('tbody td')[1] as HTMLElement;
|
|
118
|
+
|
|
119
|
+
it('the Users table links the inviter by name to their user record', async () => {
|
|
120
|
+
await mount(tables.User, [userRow], ['name', 'invitedBy']);
|
|
121
|
+
const link = invitedByCell().querySelector('a') as HTMLAnchorElement;
|
|
122
|
+
expect(link).not.toBeNull();
|
|
123
|
+
expect(link.getAttribute('href')).toBe('/record/form?table=user&record=inviter-1');
|
|
124
|
+
expect(invitedByCell().textContent).toBe('Ada Inviter');
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it('the Invites table links the inviter by name to their user record', async () => {
|
|
128
|
+
await mount(tables.Invite, [inviteRow], ['email', 'invitedBy']);
|
|
129
|
+
const link = invitedByCell().querySelector('a') as HTMLAnchorElement;
|
|
130
|
+
expect(link).not.toBeNull();
|
|
131
|
+
expect(link.getAttribute('href')).toBe('/record/form?table=user&record=inviter-1');
|
|
132
|
+
expect(invitedByCell().textContent).toBe('Ada Inviter');
|
|
133
|
+
});
|
|
134
|
+
});
|