Files
past-go/weapp/tests/pet-binding.test.cjs
2026-10-26 17:32:47 +08:00

17 lines
1.2 KiB
JavaScript

const test=require('node:test');
const assert=require('node:assert/strict');
const path=require('node:path');
const createLoader=require('./load-module.cjs');
test('pet page guides unbound users to binding and loads adoption after binding',async()=>{
let definition,unbound=true,calls=0,url;const app={globalData:{}};
const load=createLoader({Page:p=>definition=p,console,Date,getApp:()=>app,wx:{switchTab:p=>url=p.url}}, {
'../../utils/page-cache':{withDataCache:p=>p},
'../../utils/request':{api:{coupleInfo:async()=>({not_bound:unbound}),petInfo:async()=>{calls++;return {has_pet:false};}}}
});
load(path.join(__dirname,'../pages/pet/pet.js'));
const page={...definition,data:{...definition.data},setData:p=>Object.assign(page.data,p)};
await page.loadPetInfo();assert.equal(calls,0);assert.equal(page.data.needsBinding,true);assert.equal(page.data.loading,false);assert.equal(page.data.loadError,false);
page.bindPartner();assert.equal(app.globalData.openProfileBind,true);assert.equal(url,'/pages/profile/profile');
unbound=false;await page.loadPetInfo();assert.equal(calls,1);assert.equal(page.data.needsBinding,false);assert.equal(page.data.hasPet,false);
});