Skip to content

Commit d9d3f67

Browse files
committed
fix(webui): use named route for board edit link and add test
1 parent 6f6cce9 commit d9d3f67

2 files changed

Lines changed: 101 additions & 1 deletion

File tree

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import { flushPromises, mount } from "@vue/test-utils";
2+
import { beforeEach, describe, expect, it, vi } from "vitest";
3+
4+
import type { BoardConfig } from "@/types/api";
5+
6+
const listBoards = vi.fn();
7+
const listSessions = vi.fn();
8+
const deleteBoard = vi.fn();
9+
const uiStore = {
10+
clearMessages: vi.fn(),
11+
setError: vi.fn(),
12+
setSuccess: vi.fn(),
13+
confirm: vi.fn(),
14+
};
15+
16+
vi.mock("@/api", () => ({
17+
api: {
18+
listBoards,
19+
listSessions,
20+
deleteBoard,
21+
},
22+
}));
23+
24+
vi.mock("@/stores/ui", () => ({
25+
useUiStore: () => uiStore,
26+
}));
27+
28+
function makeBoard(id = "rk3568-1"): BoardConfig {
29+
return {
30+
id,
31+
board_type: "rk3568",
32+
tags: ["lab"],
33+
serial: null,
34+
power_management: {
35+
kind: "custom",
36+
power_on_cmd: "echo on",
37+
power_off_cmd: "echo off",
38+
},
39+
boot: {
40+
kind: "uboot",
41+
use_tftp: true,
42+
dtb_name: null,
43+
kernel_load_addr: null,
44+
fit_load_addr: null,
45+
bootm_addr: null,
46+
network_mode: "dhcp",
47+
board_ip: null,
48+
server_ip: null,
49+
netmask: null,
50+
gatewayip: null,
51+
},
52+
notes: null,
53+
disabled: false,
54+
};
55+
}
56+
57+
describe("BoardsView", () => {
58+
beforeEach(() => {
59+
listBoards.mockReset();
60+
listSessions.mockReset();
61+
deleteBoard.mockReset();
62+
uiStore.clearMessages.mockReset();
63+
uiStore.setError.mockReset();
64+
uiStore.setSuccess.mockReset();
65+
uiStore.confirm.mockReset();
66+
uiStore.confirm.mockResolvedValue(true);
67+
listBoards.mockResolvedValue([makeBoard()]);
68+
listSessions.mockResolvedValue({ sessions: [] });
69+
});
70+
71+
it("links board edit actions to the registered edit route", async () => {
72+
const BoardsView = (await import("./BoardsView.vue")).default;
73+
const wrapper = mount(BoardsView, {
74+
global: {
75+
stubs: {
76+
RouterLink: {
77+
name: "RouterLink",
78+
props: ["to"],
79+
template: "<a><slot /></a>",
80+
},
81+
},
82+
},
83+
});
84+
await flushPromises();
85+
86+
const editLink = wrapper.findAllComponents({ name: "RouterLink" }).find((link) => {
87+
return link.text() === "编辑";
88+
});
89+
90+
expect(editLink?.props("to")).toEqual({
91+
name: "admin-resource-board-edit",
92+
params: { boardId: "rk3568-1" },
93+
});
94+
});
95+
});

ostool-server/webui/src/views/admin/BoardsView.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,12 @@ onMounted(() => {
200200
</td>
201201
<td>
202202
<div class="row-actions">
203-
<RouterLink :to="`/admin/resources/boards/${board.id}/edit`" class="btn btn-ghost btn-sm">编辑</RouterLink>
203+
<RouterLink
204+
:to="{ name: 'admin-resource-board-edit', params: { boardId: board.id } }"
205+
class="btn btn-ghost btn-sm"
206+
>
207+
编辑
208+
</RouterLink>
204209
<button class="btn btn-danger btn-sm" @click="removeBoard(board.id)">删除</button>
205210
</div>
206211
</td>

0 commit comments

Comments
 (0)