@proteinjs/user-ui 1.7.3 → 1.8.1
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 +22 -0
- package/dist/test/adminAccessGrantPrincipalRendering.test.d.ts +5 -0
- package/dist/test/adminAccessGrantPrincipalRendering.test.d.ts.map +1 -0
- package/dist/test/adminAccessGrantPrincipalRendering.test.js +199 -0
- package/dist/test/adminAccessGrantPrincipalRendering.test.js.map +1 -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/adminAccessGrantPrincipalRendering.test.tsx +128 -0
- package/test/adminInvitedByRendering.test.tsx +134 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,28 @@
|
|
|
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.1](https://github.com/proteinjs/user/compare/@proteinjs/user-ui@1.8.0...@proteinjs/user-ui@1.8.1) (2026-08-29)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* AccessGrant.principal names its reference table 'user', not the class name — UserTable.name is the class's static JS name ('UserTable'), which deserialize stamped onto every read-back principal, so principal.get() threw (Unable to find table: UserTable) and the admin grant table could never render principals as linked names. Stored cells are bare ids — verified against the live emulator (the raw principal cell is exactly the user id; nothing 'UserTable'-shaped in the row) — so the fix is declaration-only: zero data touched, zero DDL (same STRING(36) column). Tests: user-server emulator suite (stored-bare-id premise, read-back principal resolves the user record, admin/owner insert-gate id-equality pin) + user-ui admin grant-table linked-name rendering bound over the real declaration (the adminInvitedByRendering pattern). Red-before-green: the resolution and rendering legs fail at the pre-fix declaration ('UserTable' stamped on the reference; link at ?table=UserTable). ([037f3ef](https://github.com/proteinjs/user/commit/037f3efd316b56d557c044639f7cd8e044e7d313))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# [1.8.0](https://github.com/proteinjs/user/compare/@proteinjs/user-ui@1.7.3...@proteinjs/user-ui@1.8.0) (2026-08-29)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Features
|
|
21
|
+
|
|
22
|
+
* 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))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
6
28
|
## [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
29
|
|
|
8
30
|
**Note:** Version bump only for package @proteinjs/user-ui
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adminAccessGrantPrincipalRendering.test.d.ts","sourceRoot":"","sources":["../../test/adminAccessGrantPrincipalRendering.test.tsx"],"names":[],"mappings":"AA2CA,OAAO,CAAC,MAAM,CAAC;IAEb,IAAI,wBAAwB,EAAE,OAAO,CAAC;CACvC"}
|
|
@@ -0,0 +1,199 @@
|
|
|
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 AccessGrants table renders `principal` as the referenced USER's name, linked to
|
|
58
|
+
* their record form — the same ReferenceCellValue surface the Users/Invites tables use for
|
|
59
|
+
* `invitedBy`. What this suite binds is the REAL AccessGrantTable declaration reaching it:
|
|
60
|
+
* rows are built the way the db layer builds them — `deserialize` stamps the COLUMN
|
|
61
|
+
* DECLARATION's reference-table name onto every read-back Reference — so a declaration naming
|
|
62
|
+
* the class (`'UserTable'`) instead of the table (`'user'`) fails these assertions (the
|
|
63
|
+
* resolver finds no such table; the link would point at `?table=UserTable`).
|
|
64
|
+
*/
|
|
65
|
+
var react_1 = __importDefault(require("react"));
|
|
66
|
+
var client_1 = require("react-dom/client");
|
|
67
|
+
var test_utils_1 = require("react-dom/test-utils");
|
|
68
|
+
var react_router_dom_1 = require("react-router-dom");
|
|
69
|
+
var react_query_1 = require("react-query");
|
|
70
|
+
var ui_1 = require("@proteinjs/ui");
|
|
71
|
+
// ReferenceCellValue resolves through Reference.get(); the fake resolves the principal to a
|
|
72
|
+
// named user record so the enrichment path is observable without a db. Note the fake only
|
|
73
|
+
// answers for the real table name 'user' — a declaration-corrupted table name gets nothing.
|
|
74
|
+
jest.mock('@proteinjs/db', function () {
|
|
75
|
+
var actual = jest.requireActual('@proteinjs/db');
|
|
76
|
+
var FakeReference = /** @class */ (function () {
|
|
77
|
+
function FakeReference(_table, _id) {
|
|
78
|
+
this._table = _table;
|
|
79
|
+
this._id = _id;
|
|
80
|
+
}
|
|
81
|
+
FakeReference.prototype.get = function () {
|
|
82
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
83
|
+
return __generator(this, function (_a) {
|
|
84
|
+
if (this._table === 'user' && this._id === 'principal-1') {
|
|
85
|
+
return [2 /*return*/, { id: 'principal-1', name: 'Priya Principal' }];
|
|
86
|
+
}
|
|
87
|
+
throw new Error('not visible');
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
};
|
|
91
|
+
return FakeReference;
|
|
92
|
+
}());
|
|
93
|
+
return __assign(__assign({}, actual), { Reference: FakeReference });
|
|
94
|
+
});
|
|
95
|
+
var db_1 = require("@proteinjs/db");
|
|
96
|
+
var db_ui_1 = require("@proteinjs/db-ui");
|
|
97
|
+
var user_1 = require("@proteinjs/user");
|
|
98
|
+
globalThis.IS_REACT_ACT_ENVIRONMENT = true;
|
|
99
|
+
var StubIntersectionObserver = /** @class */ (function () {
|
|
100
|
+
function StubIntersectionObserver() {
|
|
101
|
+
}
|
|
102
|
+
StubIntersectionObserver.prototype.observe = function () { };
|
|
103
|
+
StubIntersectionObserver.prototype.unobserve = function () { };
|
|
104
|
+
StubIntersectionObserver.prototype.disconnect = function () { };
|
|
105
|
+
return StubIntersectionObserver;
|
|
106
|
+
}());
|
|
107
|
+
globalThis.IntersectionObserver = StubIntersectionObserver;
|
|
108
|
+
/**
|
|
109
|
+
* The principal reference exactly as the db layer would hand it to the table: the reference's
|
|
110
|
+
* table name comes from the COLUMN DECLARATION (ReferenceColumn.deserialize stamps
|
|
111
|
+
* `this.referenceTable`), never from stored data — stored cells are bare ids.
|
|
112
|
+
*/
|
|
113
|
+
var principalReference = function () {
|
|
114
|
+
var principalColumn = user_1.tables.AccessGrant.columns.principal;
|
|
115
|
+
return new db_1.Reference(principalColumn.referenceTable, 'principal-1');
|
|
116
|
+
};
|
|
117
|
+
var grantRow = {
|
|
118
|
+
id: 'grant-1',
|
|
119
|
+
principal: principalReference(),
|
|
120
|
+
resource: new db_1.Reference('thought', 'thought-1'),
|
|
121
|
+
resourceTable: 'thought',
|
|
122
|
+
accessLevel: 'read',
|
|
123
|
+
};
|
|
124
|
+
describe('the admin AccessGrants table renders principal as the linked user', function () {
|
|
125
|
+
var container;
|
|
126
|
+
var root;
|
|
127
|
+
var client;
|
|
128
|
+
beforeEach(function () {
|
|
129
|
+
(0, db_ui_1.clearReferenceNameCache)();
|
|
130
|
+
container = document.createElement('div');
|
|
131
|
+
document.body.appendChild(container);
|
|
132
|
+
root = (0, client_1.createRoot)(container);
|
|
133
|
+
client = new react_query_1.QueryClient({ defaultOptions: { queries: { retry: false, cacheTime: 0 } } });
|
|
134
|
+
});
|
|
135
|
+
afterEach(function () {
|
|
136
|
+
(0, test_utils_1.act)(function () { return root.unmount(); });
|
|
137
|
+
container.remove();
|
|
138
|
+
});
|
|
139
|
+
var mount = function (rows) { return __awaiter(void 0, void 0, void 0, function () {
|
|
140
|
+
return __generator(this, function (_a) {
|
|
141
|
+
switch (_a.label) {
|
|
142
|
+
case 0: return [4 /*yield*/, (0, test_utils_1.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
143
|
+
return __generator(this, function (_a) {
|
|
144
|
+
root.render(react_1.default.createElement(react_query_1.QueryClientProvider, { client: client },
|
|
145
|
+
react_1.default.createElement(react_router_dom_1.MemoryRouter, null,
|
|
146
|
+
react_1.default.createElement(db_ui_1.RecordTable, { table: user_1.tables.AccessGrant, tableLoader: new ui_1.StaticTableLoader(rows, { dataKey: "grant-principal-".concat(Math.random()), dataQueryKey: 'all' }), hideButtons: true, columns: ['accessLevel', 'principal'] }))));
|
|
147
|
+
return [2 /*return*/];
|
|
148
|
+
});
|
|
149
|
+
}); })];
|
|
150
|
+
case 1:
|
|
151
|
+
_a.sent();
|
|
152
|
+
// one macrotask for the name resolution to land
|
|
153
|
+
return [4 /*yield*/, (0, test_utils_1.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
154
|
+
return __generator(this, function (_a) {
|
|
155
|
+
switch (_a.label) {
|
|
156
|
+
case 0: return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, 0); })];
|
|
157
|
+
case 1:
|
|
158
|
+
_a.sent();
|
|
159
|
+
return [2 /*return*/];
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
}); })];
|
|
163
|
+
case 2:
|
|
164
|
+
// one macrotask for the name resolution to land
|
|
165
|
+
_a.sent();
|
|
166
|
+
return [4 /*yield*/, (0, test_utils_1.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
167
|
+
return __generator(this, function (_a) {
|
|
168
|
+
switch (_a.label) {
|
|
169
|
+
case 0: return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, 0); })];
|
|
170
|
+
case 1:
|
|
171
|
+
_a.sent();
|
|
172
|
+
return [2 /*return*/];
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
}); })];
|
|
176
|
+
case 3:
|
|
177
|
+
_a.sent();
|
|
178
|
+
return [2 /*return*/];
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
}); };
|
|
182
|
+
var principalCell = function () { return container.querySelectorAll('tbody td')[1]; };
|
|
183
|
+
it('links the principal by name to their user record', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
184
|
+
var link;
|
|
185
|
+
return __generator(this, function (_a) {
|
|
186
|
+
switch (_a.label) {
|
|
187
|
+
case 0: return [4 /*yield*/, mount([grantRow])];
|
|
188
|
+
case 1:
|
|
189
|
+
_a.sent();
|
|
190
|
+
link = principalCell().querySelector('a');
|
|
191
|
+
expect(link).not.toBeNull();
|
|
192
|
+
expect(link.getAttribute('href')).toBe('/record/form?table=user&record=principal-1');
|
|
193
|
+
expect(principalCell().textContent).toBe('Priya Principal');
|
|
194
|
+
return [2 /*return*/];
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
}); });
|
|
198
|
+
});
|
|
199
|
+
//# sourceMappingURL=adminAccessGrantPrincipalRendering.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adminAccessGrantPrincipalRendering.test.js","sourceRoot":"","sources":["../../test/adminAccessGrantPrincipalRendering.test.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;GAWG;AACH,gDAA0B;AAC1B,2CAAoD;AACpD,mDAA2C;AAC3C,qDAAgD;AAChD,2CAA+D;AAC/D,oCAAkD;AAElD,4FAA4F;AAC5F,0FAA0F;AAC1F,4FAA4F;AAC5F,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,CAA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C;;;;6BACxD,CAAC,EAAA;;oBAHF,gDAAgD;oBAChD,SAEE,CAAC;oBACH,qBAAM,IAAA,gBAAG,EAAC;;;4CACR,qBAAM,IAAI,OAAO,CAAC,UAAC,OAAO,IAAK,OAAA,UAAU,CAAC,OAAO,EAAE,CAAC,CAAC,EAAtB,CAAsB,CAAC,EAAA;;wCAAtD,SAAsD,CAAC;;;;6BACxD,CAAC,EAAA;;oBAFF,SAEE,CAAC;;;;SACJ,CAAC;IAEF,IAAM,aAAa,GAAG,cAAM,OAAA,SAAS,CAAC,gBAAgB,CAAC,UAAU,CAAC,CAAC,CAAC,CAAgB,EAAxD,CAAwD,CAAC;IAErF,EAAE,CAAC,kDAAkD,EAAE;;;;wBACrD,qBAAM,KAAK,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAA;;oBAAvB,SAAuB,CAAC;oBAClB,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,4CAA4C,CAAC,CAAC;oBACrF,MAAM,CAAC,aAAa,EAAE,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;;;;SAC7D,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -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;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AC,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.1",
|
|
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.1",
|
|
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": "afc8981f566682ae188b8a204d4a2fe0669bbd11"
|
|
60
60
|
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jest-environment jsdom
|
|
3
|
+
* @jest-environment-options {"customExportConditions": ["node", "node-addons"]}
|
|
4
|
+
*
|
|
5
|
+
* The admin AccessGrants table renders `principal` as the referenced USER's name, linked to
|
|
6
|
+
* their record form — the same ReferenceCellValue surface the Users/Invites tables use for
|
|
7
|
+
* `invitedBy`. What this suite binds is the REAL AccessGrantTable declaration reaching it:
|
|
8
|
+
* rows are built the way the db layer builds them — `deserialize` stamps the COLUMN
|
|
9
|
+
* DECLARATION's reference-table name onto every read-back Reference — so a declaration naming
|
|
10
|
+
* the class (`'UserTable'`) instead of the table (`'user'`) fails these assertions (the
|
|
11
|
+
* resolver finds no such table; the link would point at `?table=UserTable`).
|
|
12
|
+
*/
|
|
13
|
+
import React from 'react';
|
|
14
|
+
import { createRoot, Root } from 'react-dom/client';
|
|
15
|
+
import { act } from 'react-dom/test-utils';
|
|
16
|
+
import { MemoryRouter } from 'react-router-dom';
|
|
17
|
+
import { QueryClient, QueryClientProvider } from 'react-query';
|
|
18
|
+
import { StaticTableLoader } from '@proteinjs/ui';
|
|
19
|
+
|
|
20
|
+
// ReferenceCellValue resolves through Reference.get(); the fake resolves the principal to a
|
|
21
|
+
// named user record so the enrichment path is observable without a db. Note the fake only
|
|
22
|
+
// answers for the real table name 'user' — a declaration-corrupted table name gets nothing.
|
|
23
|
+
jest.mock('@proteinjs/db', () => {
|
|
24
|
+
const actual = jest.requireActual('@proteinjs/db');
|
|
25
|
+
class FakeReference {
|
|
26
|
+
constructor(
|
|
27
|
+
public _table: string,
|
|
28
|
+
public _id?: string
|
|
29
|
+
) {}
|
|
30
|
+
async get() {
|
|
31
|
+
if (this._table === 'user' && this._id === 'principal-1') {
|
|
32
|
+
return { id: 'principal-1', name: 'Priya Principal' };
|
|
33
|
+
}
|
|
34
|
+
throw new Error('not visible');
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return { ...actual, Reference: FakeReference };
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
import { Reference, ReferenceColumn } from '@proteinjs/db';
|
|
41
|
+
import { RecordTable, clearReferenceNameCache } from '@proteinjs/db-ui';
|
|
42
|
+
import { tables, AccessGrant, User } from '@proteinjs/user';
|
|
43
|
+
|
|
44
|
+
declare global {
|
|
45
|
+
// eslint-disable-next-line no-var
|
|
46
|
+
var IS_REACT_ACT_ENVIRONMENT: boolean;
|
|
47
|
+
}
|
|
48
|
+
globalThis.IS_REACT_ACT_ENVIRONMENT = true;
|
|
49
|
+
|
|
50
|
+
class StubIntersectionObserver {
|
|
51
|
+
observe() {}
|
|
52
|
+
unobserve() {}
|
|
53
|
+
disconnect() {}
|
|
54
|
+
}
|
|
55
|
+
(globalThis as any).IntersectionObserver = StubIntersectionObserver;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The principal reference exactly as the db layer would hand it to the table: the reference's
|
|
59
|
+
* table name comes from the COLUMN DECLARATION (ReferenceColumn.deserialize stamps
|
|
60
|
+
* `this.referenceTable`), never from stored data — stored cells are bare ids.
|
|
61
|
+
*/
|
|
62
|
+
const principalReference = () => {
|
|
63
|
+
const principalColumn = tables.AccessGrant.columns.principal as unknown as ReferenceColumn<User>;
|
|
64
|
+
return new Reference<User>(principalColumn.referenceTable, 'principal-1');
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const grantRow = {
|
|
68
|
+
id: 'grant-1',
|
|
69
|
+
principal: principalReference(),
|
|
70
|
+
resource: new Reference('thought', 'thought-1'),
|
|
71
|
+
resourceTable: 'thought',
|
|
72
|
+
accessLevel: 'read',
|
|
73
|
+
} as unknown as AccessGrant;
|
|
74
|
+
|
|
75
|
+
describe('the admin AccessGrants table renders principal as the linked user', () => {
|
|
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 (rows: AccessGrant[]) => {
|
|
94
|
+
await act(async () => {
|
|
95
|
+
root.render(
|
|
96
|
+
<QueryClientProvider client={client}>
|
|
97
|
+
<MemoryRouter>
|
|
98
|
+
<RecordTable
|
|
99
|
+
table={tables.AccessGrant}
|
|
100
|
+
tableLoader={
|
|
101
|
+
new StaticTableLoader(rows, { dataKey: `grant-principal-${Math.random()}`, dataQueryKey: 'all' })
|
|
102
|
+
}
|
|
103
|
+
hideButtons
|
|
104
|
+
columns={['accessLevel', 'principal'] as any}
|
|
105
|
+
/>
|
|
106
|
+
</MemoryRouter>
|
|
107
|
+
</QueryClientProvider>
|
|
108
|
+
);
|
|
109
|
+
});
|
|
110
|
+
// one macrotask for the name resolution to land
|
|
111
|
+
await act(async () => {
|
|
112
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
113
|
+
});
|
|
114
|
+
await act(async () => {
|
|
115
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
116
|
+
});
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
const principalCell = () => container.querySelectorAll('tbody td')[1] as HTMLElement;
|
|
120
|
+
|
|
121
|
+
it('links the principal by name to their user record', async () => {
|
|
122
|
+
await mount([grantRow]);
|
|
123
|
+
const link = principalCell().querySelector('a') as HTMLAnchorElement;
|
|
124
|
+
expect(link).not.toBeNull();
|
|
125
|
+
expect(link.getAttribute('href')).toBe('/record/form?table=user&record=principal-1');
|
|
126
|
+
expect(principalCell().textContent).toBe('Priya Principal');
|
|
127
|
+
});
|
|
128
|
+
});
|
|
@@ -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
|
+
});
|