Files
past-go/weapp/tests/profile-swipe.test.cjs
T
Blizzard b854d2873e feat: require couple binding and refine miniapp settings
Gate record features and storage entry points with invitation guidance; enforce record access in the backend. Add homepage greetings, right-swipe profile dismissal, and move the smoking switch to settings. Simplify API base configuration and remove the unused legacy tab bar component.
2026-11-04 21:27:03 +08:00

24 lines
2.2 KiB
JavaScript

const test=require('node:test'),assert=require('node:assert/strict'),path=require('node:path');
function setup(partner=false){
let def;const calls=[];
const load=require('./load-module.cjs')({Page:p=>def=p,console,Date,wx:{hideKeyboard:()=>calls.push('keyboard'),navigateBack:()=>calls.push('back')}},{'../../utils/page-cache':{withDataCache:p=>p},'../../utils/request':{api:{}}});
load(path.join(__dirname,'../pages/profile/profile.js'));
const p={...def,data:{...def.data,showEditProfileModal:!partner,showEditPartnerModal:partner},setData(v){Object.assign(this.data,v)},getTabBar:()=>({setHidden:v=>calls.push(v)})};return {p,calls};
}
const start=(x,y,ignore=false)=>({touches:[{clientX:x,clientY:y}],target:{dataset:{swipeIgnore:ignore}}});
const end=(x,y)=>({changedTouches:[{clientX:x,clientY:y}]});
test('leftward swipe keeps either editor open',()=>{
for(const partner of [false,true]){const {p,calls}=setup(partner);p.onEditTouchStart(start(280,300));p.onEditTouchEnd(end(100,310));assert.equal(partner?p.data.showEditPartnerModal:p.data.showEditProfileModal,true);assert.deepEqual(calls,[]);}
});
test('vertical scrolling, short gestures and text selection keep the editor open',()=>{
for(const [s,e] of [[start(40,300),end(80,305)],[start(40,300),end(160,500)],[start(40,300,true),end(180,310)]]){const {p,calls}=setup();p.onEditTouchStart(s);p.onEditTouchEnd(e);assert.equal(p.data.showEditProfileModal,true);assert.equal(calls.length,0);}
});
test('cancelled touches and partner saving never dismiss the editor',()=>{
const {p}=setup();p.onEditTouchStart(start(12,300));p.onEditTouchCancel();p.onEditTouchEnd(end(160,300));assert.equal(p.data.showEditProfileModal,true);
const e=setup(true);e.p.data.partnerSaving=true;e.p.onEditTouchStart(start(12,300));e.p.onEditTouchEnd(end(160,300));assert.equal(e.p.data.showEditPartnerModal,true);
});
test('right swipe closes either editor exactly once without navigating the tab page',()=>{
for(const partner of [false,true]){const {p,calls}=setup(partner);p.onEditTouchStart(start(12,300));p.onEditTouchEnd(end(160,310));p.onEditTouchEnd(end(160,310));assert.equal(p.data.showEditProfileModal,false);assert.equal(p.data.showEditPartnerModal,false);assert.deepEqual(calls,[false,'keyboard']);}
});