@dropsh/plugin-tui 0.5.2 → 0.5.5

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.
@@ -1,34 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { GenericEntityList } from "../../src/entity-list.js";
3
- import { GenericEntityView, TuiEntityView } from "../../src/entity-view.js";
4
- import { buildRegistry } from "../../src/registry.js";
5
-
6
- class ArticleView extends TuiEntityView {
7
- static override entityType = "node";
8
- static override bundle = "article";
9
- static override viewModes = { default: {}, teaser: {} };
10
- build() {
11
- return null as never;
12
- }
13
- }
14
-
15
- describe("buildRegistry", () => {
16
- it("resolves a registered view by type+bundle, else the generic default", () => {
17
- const reg = buildRegistry([{ id: "x", entities: [ArticleView] }]);
18
- expect(reg.resolveView("node", "article")).toBe(ArticleView);
19
- expect(reg.resolveView("node", "page")).toBe(GenericEntityView);
20
- expect(reg.resolveView("user")).toBe(GenericEntityView);
21
- expect(reg.resolveList("node", "article")).toBe(GenericEntityList);
22
- });
23
-
24
- it("provides core default routes and lets sub-plugin routes override by name", () => {
25
- const custom = {
26
- name: "entity.canonical",
27
- path: "/custom/{id}",
28
- controller: async () => null as never,
29
- };
30
- const reg = buildRegistry([{ id: "x", routes: [custom] }]);
31
- expect(reg.routes.get("entity.collection")?.path).toBe("/{type}");
32
- expect(reg.routes.get("entity.canonical")).toBe(custom);
33
- });
34
- });
@@ -1,91 +0,0 @@
1
- import type { JsonApiClient } from "dropsh/plugin";
2
- import { describe, expect, it, vi } from "vitest";
3
- import { TuiEntityView } from "../../src/entity-view.js";
4
- import { buildRegistry } from "../../src/registry.js";
5
- import { createRouter } from "../../src/router.js";
6
-
7
- function client(): JsonApiClient {
8
- return {
9
- get: vi.fn(async (path: string) => ({
10
- data: { type: "node--article", id: path.split("/").pop() ?? "x" },
11
- })),
12
- post: vi.fn(),
13
- patch: vi.fn(),
14
- delete: vi.fn(),
15
- upload: vi.fn(),
16
- } as unknown as JsonApiClient;
17
- }
18
-
19
- describe("createRouter", () => {
20
- it("uses the seeded doc without fetching on the first navigate", async () => {
21
- const c = client();
22
- const router = createRouter({ registry: buildRegistry([]), client: c, viewMode: "default" });
23
- await router.navigate(
24
- "entity.canonical",
25
- { type: "node", bundle: "article", id: "u1" },
26
- {
27
- data: { type: "node--article", id: "u1", attributes: { title: "Seed" } },
28
- },
29
- );
30
- expect(router.stackDepth()).toBe(1);
31
- expect(c.get).not.toHaveBeenCalled();
32
- });
33
-
34
- it("fetches (upcasts) when navigating without a seeded doc, and back() pops", async () => {
35
- const c = client();
36
- const router = createRouter({ registry: buildRegistry([]), client: c, viewMode: "default" });
37
- await router.navigate("entity.canonical", { type: "node", bundle: "article", id: "u1" });
38
- await router.navigate("entity.canonical", { type: "user", id: "a1" });
39
- expect(c.get).toHaveBeenCalledTimes(2);
40
- expect(router.stackDepth()).toBe(2);
41
- expect(router.back()).toBe(true);
42
- expect(router.stackDepth()).toBe(1);
43
- expect(router.back()).toBe(false);
44
- });
45
-
46
- it("throws on an unknown route name", async () => {
47
- const router = createRouter({
48
- registry: buildRegistry([]),
49
- client: client(),
50
- viewMode: "default",
51
- });
52
- await expect(router.navigate("nope", {})).rejects.toThrow(/unknown route/i);
53
- });
54
-
55
- it("passes the view mode's include hints to client.get on a non-seeded canonical fetch", async () => {
56
- class ArticleView extends TuiEntityView {
57
- static override entityType = "node";
58
- static override bundle = "article";
59
- static override viewModes = { default: { include: ["uid"] } };
60
- build() {
61
- return null as never;
62
- }
63
- }
64
- const get = vi.fn(
65
- async (_path: string, _params?: import("drupal-jsonapi-params").DrupalJsonApiParams) => ({
66
- data: { type: "node--article", id: "x" },
67
- }),
68
- );
69
- const c = {
70
- get,
71
- post: vi.fn(),
72
- patch: vi.fn(),
73
- delete: vi.fn(),
74
- upload: vi.fn(),
75
- } as unknown as JsonApiClient;
76
- const router = createRouter({
77
- registry: buildRegistry([{ id: "x", entities: [ArticleView] }]),
78
- client: c,
79
- viewMode: "default",
80
- });
81
- await router.navigate("entity.canonical", { type: "node", bundle: "article", id: "x" });
82
- expect(get.mock.calls[0]?.[1]?.getQueryString()).toContain("include=uid");
83
- });
84
-
85
- it("fetches the bundle-scoped path for a collection when no seededDoc is given", async () => {
86
- const c = client();
87
- const router = createRouter({ registry: buildRegistry([]), client: c, viewMode: "default" });
88
- await router.navigate("entity.collection", { type: "node", bundle: "article" });
89
- expect(c.get).toHaveBeenCalledWith("node/article");
90
- });
91
- });
package/tsconfig.json DELETED
@@ -1,14 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.json",
3
- "compilerOptions": {
4
- "outDir": "dist",
5
- "noEmit": false,
6
- "jsx": "react-jsx",
7
- "baseUrl": ".",
8
- "paths": {
9
- "dropsh/plugin": ["../../src/plugin-api.ts"],
10
- "@dropsh/plugin-markdown/render": ["../markdown/src/render-md.ts"]
11
- }
12
- },
13
- "include": ["src", "tests"]
14
- }
package/vitest.config.ts DELETED
@@ -1,15 +0,0 @@
1
- import { resolve } from "node:path";
2
- import { defineConfig } from "vitest/config";
3
-
4
- export default defineConfig({
5
- resolve: {
6
- alias: {
7
- "dropsh/plugin": resolve(__dirname, "../../src/plugin-api.ts"),
8
- "@dropsh/plugin-markdown/render": resolve(__dirname, "../markdown/src/render-md.ts"),
9
- },
10
- },
11
- test: {
12
- include: ["tests/unit/**/*.test.{ts,tsx}"],
13
- environment: "node",
14
- },
15
- });