feat: support shared pet care tasks and smooth daily page return
ci-cd / verify (push) Successful in 2m18s
ci-cd / deploy (push) Skipped

This commit is contained in:
2026-10-05 20:20:05 +08:00
parent fbc1eda561
commit 3175936266
16 changed files with 196 additions and 119 deletions
+27
View File
@@ -57,6 +57,33 @@ test("编辑任务走 PUT,并保留选中的宠物", async () => {
});
});
test("新建任务可选择全部宠物,编辑后保留范围", async () => {
const writes = [];
const pets = [{ id: "a", name: "奶盖" }, { id: "b", name: "布丁" }];
const task = { id: "task-all", all_pets: true, pet_id: null, title: "换水", category: "water", time_of_day: "09:00", repeat_rule: "daily" };
const screen = page("tasks", async (route, method, body) => {
if (method === "POST" || method === "PUT") writes.push({ route, method, body });
if (route === "/pets") return pets;
if (route.startsWith("/tasks?")) return { items: [task] };
return task;
});
await screen.load();
assert.equal(screen.data.petOptions[2].name, "全部宠物");
assert.equal(screen.data.tasks[0].petName, "全部宠物");
screen.open();
screen.petChange({ detail: { value: "2" } });
screen.setData({ title: "换水" });
await screen.save();
assert.equal(writes[0].method, "POST");
assert.equal(writes[0].body.all_pets, true);
assert.equal(writes[0].body.pet_id, undefined);
screen.edit({ currentTarget: { dataset: { index: 0 } } });
assert.equal(screen.data.petIndex, 2);
await screen.save();
assert.equal(writes[1].method, "PUT");
assert.equal(writes[1].body.all_pets, true);
});
test("多宠物遛狗发送全部 ID,结束后可再次开始", async () => {
const calls = [];
const active = { id: "walk-1", status: "active", started_at: new Date().toISOString(), pet_ids: ["a", "b"], distance_meters: 0, points: [] };
+39 -2
View File
@@ -88,13 +88,13 @@ test("缓存 token 过期时只重新登录一次,延迟的旧 401 不清除
assert.equal(r.logins.length, 1);
});
function home(login, secure) {
function home(login, secure, app = { login }) {
let definition;
const wx = { getStorageSync: () => [], navigateTo: () => {} };
vm.runInNewContext(fs.readFileSync("pets-fe/pages/home/home.js", "utf8"), {
wx,
Date,
getApp: () => ({ login }),
getApp: () => app,
Page: (value) => {
definition = value;
},
@@ -193,3 +193,40 @@ test("首页请求失败不显示空数据状态,刷新失败保留已有记
assert.equal(page.data.pets[0].id, "existing");
assert.equal(page.data.error, "网络异常");
});
test("从其他页面回到日常立即显示已有数据,后台刷新不清空内容", async () => {
const app = { login: async () => "token", globalData: { token: "token", user: { id: "user-1" } } };
const first = home(app.login, data, app);
await first.load();
first.setData({ pets: [{ id: "pet-1" }], tasks: [{ id: "task-1", completed: true }], undoneCount: 0 });
first.onUnload();
let finish;
const pending = new Promise((resolve) => { finish = resolve; });
const next = home(app.login, async (route) => { await pending; return data(route); }, app);
next.onLoad();
assert.equal(next.data.ready, true);
assert.equal(next.data.phase, "ready");
assert.equal(next.data.pets[0].id, "pet-1");
assert.equal(next.data.tasks[0].completed, true);
const refreshing = next.load();
await tick();
assert.equal(next.data.ready, true);
assert.equal(next.data.pets[0].id, "pet-1");
finish();
await refreshing;
assert.equal(next.data.loading, false);
});
test("日常缓存不跨账号、不显示上一天的任务", async () => {
const app = { login: async () => "token", globalData: { user: { id: "new-user" } }, homeSnapshot: {
account: "old-user", date: "2026-10-05", data: { pets: [{ id: "private" }] },
} };
const page = home(app.login, data, app);
page.onLoad();
assert.equal(page.data.ready, false);
assert.equal(page.data.pets.length, 0);
app.homeSnapshot.account = "new-user";
app.homeSnapshot.date = "2026-10-04";
page.onLoad();
assert.equal(page.data.ready, false);
});