|
1
|
import { createRuleTester } from "../../../test-utils" |
|
2
|
import { rule } from "../rule" |
|
3
|
|
|
4
|
const ruleTester = createRuleTester() |
|
5
|
|
|
6
|
const STATIC_PAGE = "src/admin/routes/custom/page.tsx" |
|
7
|
const DYNAMIC_PAGE = "src/admin/routes/products/[id]/page.tsx" |
|
8
|
const NESTED_DYNAMIC_PAGE = |
|
9
|
"src/admin/routes/products/[id]/edit/[step]/page.tsx" |
|
10
|
const DYNAMIC_PAGE_NO_SRC = "admin/routes/orders/[id]/page.tsx" |
|
11
|
|
|
12
|
ruleTester.run("no-config-on-dynamic-ui-route", rule, { |
|
13
|
valid: [ |
|
14
|
// Static (non-dynamic) route — defineRouteConfig is fine here. |
|
15
|
{ |
|
16
|
code: `import { defineRouteConfig } from "@medusajs/admin-sdk" |
|
17
|
const CustomPage = () => null |
|
18
|
export const config = defineRouteConfig({ label: "Custom" }) |
|
19
|
export default CustomPage`, |
|
20
|
filename: STATIC_PAGE, |
|
21
|
}, |
|
22
|
// Dynamic route with NO config at all — nothing to flag. |
|
23
|
{ |
|
24
|
code: `const ProductPage = () => null |
|
25
|
export default ProductPage`, |
|
26
|
filename: DYNAMIC_PAGE, |
|
27
|
}, |
|
28
|
// Dynamic route with a plain-object `config` (not defineRouteConfig) — out |
|
29
|
// of scope for this rule; it only targets the defineRouteConfig helper. |
|
30
|
{ |
|
31
|
code: `const ProductPage = () => null |
|
32
|
export const config = { label: "Product" } |
|
33
|
export default ProductPage`, |
|
34
|
filename: DYNAMIC_PAGE, |
|
35
|
}, |
|
36
|
// `defineRouteConfig` is a local shadow, not the admin SDK import. |
|
37
|
{ |
|
38
|
code: `const defineRouteConfig = (x) => x |
|
39
|
const ProductPage = () => null |
|
40
|
export const config = defineRouteConfig({ label: "Product" }) |
|
41
|
export default ProductPage`, |
|
42
|
filename: DYNAMIC_PAGE, |
|
43
|
}, |
|
44
|
], |
|
45
|
invalid: [ |
|
46
|
// Dynamic route exporting config via defineRouteConfig — reported on the call. |
|
47
|
{ |
|
48
|
code: `import { defineRouteConfig } from "@medusajs/admin-sdk" |
|
49
|
const ProductPage = () => null |
|
50
|
export const config = defineRouteConfig({ label: "Product" }) |
|
51
|
export default ProductPage`, |
|
52
|
filename: DYNAMIC_PAGE, |
|
53
|
errors: [{ messageId: "configOnDynamicRoute", line: 3, column: 23 }], |
|
54
|
}, |
|
55
|
// The variable name doesn't matter — any defineRouteConfig usage is flagged. |
|
56
|
{ |
|
57
|
code: `import { defineRouteConfig } from "@medusajs/admin-sdk" |
|
58
|
const ProductPage = () => null |
|
59
|
export const routeConfig = defineRouteConfig({ label: "Product" }) |
|
60
|
export default ProductPage`, |
|
61
|
filename: DYNAMIC_PAGE, |
|
62
|
errors: [{ messageId: "configOnDynamicRoute" }], |
|
63
|
}, |
|
64
|
// Not exported at all — still a pointless defineRouteConfig call on a |
|
65
|
// dynamic route. |
|
66
|
{ |
|
67
|
code: `import { defineRouteConfig } from "@medusajs/admin-sdk" |
|
68
|
const ProductPage = () => null |
|
69
|
const config = defineRouteConfig({ label: "Product" }) |
|
70
|
export default ProductPage`, |
|
71
|
filename: DYNAMIC_PAGE, |
|
72
|
errors: [{ messageId: "configOnDynamicRoute" }], |
|
73
|
}, |
|
74
|
// Aliased defineRouteConfig import. |
|
75
|
{ |
|
76
|
code: `import { defineRouteConfig as drc } from "@medusajs/admin-sdk" |
|
77
|
const ProductPage = () => null |
|
78
|
export const config = drc({ label: "Product" }) |
|
79
|
export default ProductPage`, |
|
80
|
filename: DYNAMIC_PAGE, |
|
81
|
errors: [{ messageId: "configOnDynamicRoute" }], |
|
82
|
}, |
|
83
|
// Nested dynamic segment deeper in the path. |
|
84
|
{ |
|
85
|
code: `import { defineRouteConfig } from "@medusajs/admin-sdk" |
|
86
|
const StepPage = () => null |
|
87
|
export const config = defineRouteConfig({ label: "Step" }) |
|
88
|
export default StepPage`, |
|
89
|
filename: NESTED_DYNAMIC_PAGE, |
|
90
|
errors: [{ messageId: "configOnDynamicRoute" }], |
|
91
|
}, |
|
92
|
// Bare `admin/routes/...` layout (no `src/` prefix). |
|
93
|
{ |
|
94
|
code: `import { defineRouteConfig } from "@medusajs/admin-sdk" |
|
95
|
const OrderPage = () => null |
|
96
|
export const config = defineRouteConfig({ label: "Order" }) |
|
97
|
export default OrderPage`, |
|
98
|
filename: DYNAMIC_PAGE_NO_SRC, |
|
99
|
errors: [{ messageId: "configOnDynamicRoute" }], |
|
100
|
}, |
|
101
|
], |
|
102
|
}) |