fix(home): 홈 시작 링크가 런타임에 꺼진 기능을 고르지 않는다
문제 home-page.tsx의 STARTER_ROUTES는 모듈을 불러올 때 NAVIGATION_ROUTES에서 APP_HOME을 빼고 앞 3개를 고른다. 기능이 켜져 있는지는 보지 않는다. 셸 탐색은 같은 목록을 runtime.isFeatureActive(owner)로 거르고, 라우터는 꺼진 기능의 라우트에 사용 중지 화면을 그린다. 그래서 운영자가 런타임 설정으로 platform-examples-feature를 끄면 홈의 주요 버튼 셋 중 둘(/examples/ui, /examples/states)이 사용 중지 화면으로 간다(리뷰 08-R1 C, 1103/09-04 수정 b96d61d8이 만듦). 고른 방법 셸과 홈이 같은 함수를 쓴다. navigation-policy.ts에 activeNavigationRoutes (isFeatureActive)를 두고(설치된 레지스트리를 읽어도 되는 기존 예외 파일이다), 셸 탐색과 홈 시작 링크가 렌더 때 그 목록을 읽는다. 홈은 그 뒤에 APP_HOME을 빼고 앞 3개를 고른다. 홈은 여전히 기능 라우트를 이름으로 부르지 않는다(1103/09-04의 보존 조건). 테스트는 platform-examples-feature 테스트 폴더에 두어 기능을 지울 때 함께 지워진다. 버린 대안 홈에서만 같은 filter를 한 번 더 쓴다: 셸과 홈의 조건이 다시 갈라질 수 있다. 위험·한계 빌드에서 뺀 기능은 처음부터 목록에 없으므로 해당 없다. 시작 링크가 셋보다 적을 수 있다(템플릿에서 예제를 끄면 둘). 검증 desktop batch에서 확인: node scripts/run-vitest.ts run tests/features/platform-examples-feature/example-pages.test.tsx tests/component/product-feature-switch.test.tsx tests/component/starter-pages.test.tsx tests/unit/navigation-policy.test.ts Refs: 1105/08-03
This commit is contained in:
@@ -3,11 +3,7 @@ import { NavLink, Outlet, useLocation } from "react-router-dom";
|
||||
|
||||
import type { SessionState } from "../../application/ports/in/application-api.ts";
|
||||
import { normalizeColorSchemePreference } from "../../application/policies/color-scheme.ts";
|
||||
import {
|
||||
NAVIGATION_ROUTES,
|
||||
ROUTE_FEATURE_OWNER,
|
||||
routePath,
|
||||
} from "../../features/installed-feature-contracts.ts";
|
||||
import { routePath } from "../../features/installed-feature-contracts.ts";
|
||||
import {
|
||||
Button,
|
||||
Drawer,
|
||||
@@ -26,6 +22,7 @@ import {
|
||||
useSessionAction,
|
||||
} from "../providers/session-provider.tsx";
|
||||
import { useTheme } from "../providers/theme-provider.tsx";
|
||||
import { activeNavigationRoutes } from "../routes/navigation-policy.ts";
|
||||
|
||||
const SESSION_MESSAGE_KEYS = Object.freeze({
|
||||
authenticated: "shell.session.authenticated",
|
||||
@@ -196,10 +193,9 @@ function PrimaryNavigation({
|
||||
const runtime = useApplicationRuntime();
|
||||
// §3.5. A feature the runtime document disabled does not advertise itself.
|
||||
// The router refuses its routes too, so this is presentation, not the switch.
|
||||
const routes = NAVIGATION_ROUTES.filter((definition) => {
|
||||
const owner = ROUTE_FEATURE_OWNER[definition.routeId];
|
||||
return owner === undefined || runtime.isFeatureActive(owner);
|
||||
});
|
||||
const routes = activeNavigationRoutes((featureId) =>
|
||||
runtime.isFeatureActive(featureId),
|
||||
);
|
||||
return (
|
||||
<nav id={id} aria-label={message("shell.primaryNavigation")}>
|
||||
<ul className="app-navigation">
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
|
||||
import { NAVIGATION_ROUTES } from "../../features/installed-feature-contracts.ts";
|
||||
import { PageHeader } from "../design-system/index.ts";
|
||||
import { useLocale } from "../i18n/index.ts";
|
||||
import { useApplicationRuntime } from "../providers/application-provider.tsx";
|
||||
import { activeNavigationRoutes } from "../routes/navigation-policy.ts";
|
||||
|
||||
const READINESS_ITEMS = Object.freeze([
|
||||
"contract",
|
||||
@@ -12,19 +12,21 @@ const READINESS_ITEMS = Object.freeze([
|
||||
"accessibility",
|
||||
] as const);
|
||||
|
||||
/**
|
||||
* 1103/09-04. The first screens of the navigation after this page. In the
|
||||
* template those are its example screens, a removable feature; a
|
||||
* product that leaves them out gets its own screens here, and the page names
|
||||
* no feature's route.
|
||||
*/
|
||||
const STARTER_ROUTES = Object.freeze(
|
||||
NAVIGATION_ROUTES.filter((route) => route.routeId !== "APP_HOME").slice(0, 3),
|
||||
);
|
||||
|
||||
export default function HomePage() {
|
||||
const runtime = useApplicationRuntime();
|
||||
const { message, resolve } = useLocale();
|
||||
/**
|
||||
* 1103/09-04. The first screens of the navigation after this page. In the
|
||||
* template those are its example screens, a removable feature; a product
|
||||
* that leaves them out gets its own screens here, and the page names no
|
||||
* feature's route. 1105/08-03. Read at render, like the shell's
|
||||
* navigation: a feature the runtime document disabled is not offered.
|
||||
*/
|
||||
const starterRoutes = activeNavigationRoutes((featureId) =>
|
||||
runtime.isFeatureActive(featureId),
|
||||
)
|
||||
.filter((route) => route.routeId !== "APP_HOME")
|
||||
.slice(0, 3);
|
||||
const [release, setRelease] = useState<
|
||||
Awaited<ReturnType<typeof runtime.getReleaseSummary>> | "failed" | null
|
||||
>(null);
|
||||
@@ -69,14 +71,14 @@ export default function HomePage() {
|
||||
})
|
||||
: message("home.runtime.checking")}
|
||||
</p>
|
||||
{STARTER_ROUTES.length > 0 ? (
|
||||
{starterRoutes.length > 0 ? (
|
||||
<section className="ui-panel starter-actions" aria-labelledby="starter-title">
|
||||
<div>
|
||||
<h2 id="starter-title">{message("home.starter.title")}</h2>
|
||||
<p>{message("home.starter.description")}</p>
|
||||
</div>
|
||||
<div className="button-row">
|
||||
{STARTER_ROUTES.map((route, index) => (
|
||||
{starterRoutes.map((route, index) => (
|
||||
<Link
|
||||
key={route.routeId}
|
||||
className={
|
||||
|
||||
@@ -1,5 +1,24 @@
|
||||
import type { SessionState } from "../../application/ports/in/application-api.ts";
|
||||
import { getRoute } from "../../features/installed-feature-contracts.ts";
|
||||
import {
|
||||
getRoute,
|
||||
NAVIGATION_ROUTES,
|
||||
ROUTE_FEATURE_OWNER,
|
||||
} from "../../features/installed-feature-contracts.ts";
|
||||
|
||||
/**
|
||||
* §3.5. The navigation routes a screen may advertise: a feature the runtime
|
||||
* document disabled does not advertise itself. The router refuses its routes
|
||||
* too, so this is presentation, not the switch. 1105/08-03. The shell's
|
||||
* navigation and the home page's starter links read this one list.
|
||||
*/
|
||||
export function activeNavigationRoutes(
|
||||
isFeatureActive: (featureId: string) => boolean,
|
||||
): typeof NAVIGATION_ROUTES {
|
||||
return NAVIGATION_ROUTES.filter((definition) => {
|
||||
const owner = ROUTE_FEATURE_OWNER[definition.routeId];
|
||||
return owner === undefined || isFeatureActive(owner);
|
||||
});
|
||||
}
|
||||
|
||||
export type RouteAccessDecision =
|
||||
| Readonly<{ allowed: true; action: "none" }>
|
||||
|
||||
@@ -1,15 +1,21 @@
|
||||
// @vitest-environment jsdom
|
||||
|
||||
import { render, screen, waitFor } from "@testing-library/react";
|
||||
import { render, screen, waitFor, within } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { createAnonymousSessionAdapter } from "../../../src/adapters/auth/external-session-adapter.ts";
|
||||
import {
|
||||
ROUTE_FEATURE_OWNER,
|
||||
ROUTE_REGISTRY,
|
||||
} from "../../../src/features/installed-feature-contracts.ts";
|
||||
import { PLATFORM_EXAMPLES_FEATURE_ID } from "../../../src/features/platform-examples-feature/contracts/platform-examples-contract.ts";
|
||||
import StateGalleryPage from "../../../src/features/platform-examples-feature/presentation/state-gallery-page.tsx";
|
||||
import { ApplicationProvider } from "../../../src/presentation/providers/application-provider.tsx";
|
||||
import { PreferenceProviders } from "../../../src/presentation/providers/preference-providers.tsx";
|
||||
import { AppRouter } from "../../../src/presentation/routes/app-router.tsx";
|
||||
import { createTestApplication } from "../../helpers/create-test-application.ts";
|
||||
import { createProductFeaturesStub } from "../../helpers/runtime-capabilities-stub.ts";
|
||||
|
||||
/**
|
||||
* The example screens (`/examples/ui`, `/examples/states`, `/examples/auth`)
|
||||
@@ -48,6 +54,37 @@ describe("example pages", () => {
|
||||
);
|
||||
});
|
||||
|
||||
// 1105/08-03. The home page's starter links read the same switch as the
|
||||
// shell's navigation: switched off at runtime, this feature's screens are
|
||||
// not offered there, and the next active screens take their place.
|
||||
it("leaves this feature's screens out of the home page's starter links when it is switched off", async () => {
|
||||
renderApp(
|
||||
"/",
|
||||
createTestApplication({
|
||||
productFeatures: createProductFeaturesStub({
|
||||
[PLATFORM_EXAMPLES_FEATURE_ID]: "DISABLED_BY_CONFIG",
|
||||
}),
|
||||
}),
|
||||
);
|
||||
|
||||
const starter = await screen.findByRole("region", { name: "준비된 화면 살펴보기" });
|
||||
const starterPaths = within(starter)
|
||||
.getAllByRole("link")
|
||||
.map((link) => link.getAttribute("href"));
|
||||
const ownPaths = Object.values(ROUTE_REGISTRY)
|
||||
.filter((route) => ROUTE_FEATURE_OWNER[route.routeId] === PLATFORM_EXAMPLES_FEATURE_ID)
|
||||
.map((route) => route.path);
|
||||
const [navigation] = screen.getAllByRole("navigation", { name: "주요 탐색" });
|
||||
const advertised = within(navigation!)
|
||||
.getAllByRole("link")
|
||||
.map((link) => link.getAttribute("href"))
|
||||
.filter((path) => path !== "/");
|
||||
|
||||
expect(ownPaths.length).toBeGreaterThan(0);
|
||||
expect(starterPaths.some((path) => ownPaths.includes(path ?? ""))).toBe(false);
|
||||
expect(starterPaths).toEqual(advertised.slice(0, 3));
|
||||
});
|
||||
|
||||
it("returns to the current URL with its hash from the auth example page", async () => {
|
||||
const user = userEvent.setup();
|
||||
const beginSignIn = vi.fn(async () => {});
|
||||
|
||||
Reference in New Issue
Block a user