| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- import { shallowMount } from "@vue/test-utils"
- import FamilyWorkbench from "@/views/FamilyWorkbench.vue"
- import { getFamilyWorkbench } from "@/api/familyWorkbench"
- import { getFamilyTasks, getFamilyOverview } from "@/api/admin"
- jest.mock("@/api/familyWorkbench")
- jest.mock("@/api/admin", () => ({
- getFamilyTasks: jest.fn().mockResolvedValue({ data: { records: [], total: 0 } }),
- getFamilyOverview: jest.fn().mockResolvedValue({ data: { reports: [], plans: [] } })
- }))
- jest.mock("echarts", () => ({
- init: jest.fn(() => ({ setOption: jest.fn(), dispose: jest.fn(), resize: jest.fn() }))
- }))
- const mockCards = [
- { key: "reports", label: "报告", total: 7, series: [] },
- { key: "plans", label: "方案", total: 3, series: [] },
- { key: "tasks", label: "任务", total: 9, series: [] },
- { key: "messages", label: "消息", total: 2, series: [] },
- { key: "cf", label: "CF值", total: 100, series: [] },
- { key: "coupons", label: "优惠券", total: 4, series: [] }
- ]
- describe("FamilyWorkbench 单家庭工作台", () => {
- function mountPage() {
- return shallowMount(FamilyWorkbench, {
- mocks: {
- $route: { params: { id: "5" } },
- $router: { push: jest.fn() },
- $message: { error: jest.fn(), success: jest.fn() }
- }
- })
- }
- beforeEach(() => {
- getFamilyWorkbench.mockReset()
- getFamilyWorkbench.mockResolvedValue({
- data: { family: { id: 5, name: "测试家庭", inviteCode: "T5" }, cards: mockCards }
- })
- })
- it("渲染 6 张指标卡并显示总额", async () => {
- const wrapper = mountPage()
- await wrapper.vm.$nextTick()
- await wrapper.vm.$nextTick()
- const cards = wrapper.findAll(".wb-card")
- expect(cards.length).toBe(6)
- expect(wrapper.text()).toContain("9")
- expect(wrapper.text()).toContain("100")
- wrapper.destroy()
- })
- it("点击任务卡 -> 打开任务列表抽屉并加载该家庭任务", async () => {
- const wrapper = mountPage()
- await wrapper.vm.$nextTick()
- await wrapper.vm.$nextTick()
- wrapper.findAll(".wb-card").at(2).trigger("click")
- await wrapper.vm.$nextTick()
- expect(wrapper.vm.activeModule).toBe("tasks")
- expect(wrapper.vm.taskDrawerVisible).toBe(true)
- expect(getFamilyTasks).toHaveBeenCalledWith(5, expect.anything())
- wrapper.destroy()
- })
- it("优惠券卡 -> 深链 family-coupon 页", async () => {
- const wrapper = mountPage()
- await wrapper.vm.$nextTick()
- await wrapper.vm.$nextTick()
- wrapper.findAll(".wb-card").at(5).trigger("click")
- expect(wrapper.vm.$router.push).toHaveBeenCalledWith(
- expect.objectContaining({ path: "/family-coupon", query: { familyId: 5 } })
- )
- wrapper.destroy()
- })
- })
|