@vtex/faststore-plugin-buyer-portal 2.0.44 → 2.0.46
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/package.json
CHANGED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
|
|
5
|
+
import { describe, expect, it } from "vitest";
|
|
6
|
+
|
|
7
|
+
import { LOCALIZATION_ENTRY_IDS } from "../constants";
|
|
8
|
+
|
|
9
|
+
import type { LocalizationFeature } from "../constants";
|
|
10
|
+
|
|
11
|
+
const PAGES_DIR = path.join(
|
|
12
|
+
path.dirname(fileURLToPath(import.meta.url)),
|
|
13
|
+
"../../../../pages"
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
// Returns the text of the `entryIds` option passed to getLocalizationLabelsService,
|
|
17
|
+
// e.g. `[LOCALIZATION_ENTRY_IDS.orgUnits, LOCALIZATION_ENTRY_IDS.users]`.
|
|
18
|
+
const getRequestedEntries = (page: string): LocalizationFeature[] => {
|
|
19
|
+
const source = fs.readFileSync(path.join(PAGES_DIR, `${page}.tsx`), "utf8");
|
|
20
|
+
const call = source.match(
|
|
21
|
+
/getLocalizationLabelsService\(\{\s*entryIds:\s*([\s\S]*?)\s*,\s*locale/
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
if (!call) throw new Error(`No getLocalizationLabelsService call in ${page}`);
|
|
25
|
+
|
|
26
|
+
return Array.from(call[1].matchAll(/LOCALIZATION_ENTRY_IDS\.(\w+)/g)).map(
|
|
27
|
+
([, name]) => name as LocalizationFeature
|
|
28
|
+
);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
// Components rendered by a page resolve `t("<feature>.…")` keys from the entries
|
|
32
|
+
// its loader requests. A shared component whose entry is not requested renders
|
|
33
|
+
// the raw key (B2BTEAM-4276, B2BTEAM-4277).
|
|
34
|
+
const REQUIRED_ENTRIES: Record<string, LocalizationFeature[]> = {
|
|
35
|
+
// Sidebar → AccountingFieldDropdown, CreateAccountingFieldDrawer
|
|
36
|
+
profile: ["accountingFields"],
|
|
37
|
+
// OrgUnitsDropdownMenu → CreateUserDrawerSelector → CreateUserDrawer*
|
|
38
|
+
"org-units": ["users"],
|
|
39
|
+
// AddAllToOrgUnitDropdown → CreateUserDrawerSelector → CreateUserDrawer*
|
|
40
|
+
"org-unit-details": ["users"],
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
describe("page loaders request the localization entries their components use", () => {
|
|
44
|
+
it("knows every required entry", () => {
|
|
45
|
+
Object.values(REQUIRED_ENTRIES)
|
|
46
|
+
.flat()
|
|
47
|
+
.forEach((feature) => {
|
|
48
|
+
expect(LOCALIZATION_ENTRY_IDS).toHaveProperty(feature);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
Object.entries(REQUIRED_ENTRIES).forEach(([page, features]) => {
|
|
53
|
+
it.each(features)(`${page} requests %s`, (feature) => {
|
|
54
|
+
expect(getRequestedEntries(page)).toContain(feature);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
});
|
package/src/pages/org-units.tsx
CHANGED
|
@@ -87,7 +87,10 @@ const loaderFunction = async (
|
|
|
87
87
|
}),
|
|
88
88
|
getUserByIdService({ orgUnitId, userId, cookie }),
|
|
89
89
|
getLocalizationLabelsService({
|
|
90
|
-
entryIds:
|
|
90
|
+
entryIds: [
|
|
91
|
+
LOCALIZATION_ENTRY_IDS.orgUnits,
|
|
92
|
+
LOCALIZATION_ENTRY_IDS.users,
|
|
93
|
+
],
|
|
91
94
|
locale: data.locale,
|
|
92
95
|
}),
|
|
93
96
|
contractDetailsPromise,
|
package/src/pages/profile.tsx
CHANGED
|
@@ -46,7 +46,10 @@ export async function loaderFunction(
|
|
|
46
46
|
data,
|
|
47
47
|
async ({ customerId, cookie, userId, ...clientContext }) => {
|
|
48
48
|
const labelsPromise = getLocalizationLabelsService({
|
|
49
|
-
entryIds:
|
|
49
|
+
entryIds: [
|
|
50
|
+
LOCALIZATION_ENTRY_IDS.profile,
|
|
51
|
+
LOCALIZATION_ENTRY_IDS.accountingFields,
|
|
52
|
+
],
|
|
50
53
|
locale: data.locale,
|
|
51
54
|
});
|
|
52
55
|
|