문제 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
118 lines
4.6 KiB
TypeScript
118 lines
4.6 KiB
TypeScript
// @vitest-environment jsdom
|
|
|
|
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`)
|
|
* are the template's content, not the platform (0929/10-02). 1103/09-04:
|
|
* they are `platform-examples-feature`, and this folder goes with it; the
|
|
* platform tests run on the test-only feature's pages and keep passing.
|
|
*/
|
|
|
|
function renderApp(
|
|
url: string,
|
|
application = createTestApplication(),
|
|
) {
|
|
window.history.pushState({}, "", url);
|
|
return render(
|
|
<ApplicationProvider application={application}>
|
|
<PreferenceProviders>
|
|
<AppRouter />
|
|
</PreferenceProviders>
|
|
</ApplicationProvider>,
|
|
);
|
|
}
|
|
|
|
describe("example pages", () => {
|
|
it("reaches the UI gallery from the home page's starter actions", async () => {
|
|
const user = userEvent.setup();
|
|
renderApp("/");
|
|
|
|
await user.click(
|
|
await screen.findByRole("link", { name: "UI 구성요소 보기" }),
|
|
);
|
|
|
|
await waitFor(() =>
|
|
expect(
|
|
screen.getByRole("heading", { name: "UI 구성요소", level: 1 }),
|
|
).toHaveFocus(),
|
|
);
|
|
});
|
|
|
|
// 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 () => {});
|
|
renderApp(
|
|
"/examples/auth#session",
|
|
createTestApplication({
|
|
session: { ...createAnonymousSessionAdapter(), beginSignIn },
|
|
}),
|
|
);
|
|
|
|
await user.click(
|
|
await screen.findByRole("button", { name: "로그인 시작" }),
|
|
);
|
|
expect(beginSignIn).toHaveBeenCalledWith("/examples/auth#session");
|
|
});
|
|
|
|
it("nests the state gallery's titles under the card and section around them (08-05)", () => {
|
|
render(<StateGalleryPage />);
|
|
|
|
expect(
|
|
screen.getByRole("heading", { name: "아직 표시할 항목이 없습니다.", level: 4 }),
|
|
).toBeVisible();
|
|
expect(screen.getAllByRole("heading", { level: 3 }).map((h) => h.textContent))
|
|
.toEqual(expect.arrayContaining(["빈 화면", "복구 가능한 오류"]));
|
|
// Access states sit directly under the section's h2.
|
|
expect(
|
|
screen.queryAllByRole("heading", { level: 2 }).map((h) => h.textContent),
|
|
).toEqual(["비동기 데이터 상태", "접근과 탐색 상태"]);
|
|
});
|
|
});
|