init: initial commit

This commit is contained in:
2026-10-07 09:28:43 +08:00
commit a68a4ef411
251 changed files with 38279 additions and 0 deletions
+33
View File
@@ -0,0 +1,33 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
const vm = require('node:vm');
const {tabForPage, paths} = require('../utils/navigation');
const root = path.join(__dirname, '..');
test('only the three main pages mount a tab bar; every secondary page removes its registration and reserved space',()=>{
const pages=JSON.parse(fs.readFileSync(path.join(root,'app.json'),'utf8')).pages;
for(const page of pages){
const main=Object.values(paths).includes(page);
const markup=fs.readFileSync(path.join(root,page+'.wxml'),'utf8');
const components=JSON.parse(fs.readFileSync(path.join(root,page+'.json'),'utf8')).usingComponents||{};
assert.equal(/<app-tabbar\b/.test(markup),main,page);
assert.equal(!!tabForPage(page),main,page);
if(!main){assert.ok(!components['app-tabbar'],page);assert.ok(markup.includes('app-shell--secondary'),page);}
}
assert.equal(tabForPage('/pages/profile/profile?bind=1'),'profile');
assert.equal(tabForPage('unknown'),'');
});
test('component selects the main page, hides on child routes and avoids reloading its current tab',()=>{
let definition,route='pages/profile/profile';const navigations=[];
vm.runInNewContext(fs.readFileSync(path.join(root,'components/app-tabbar/app-tabbar.js'),'utf8'),{
Component:c=>definition=c,require:()=>({tabForPage,paths}),getCurrentPages:()=>[{route}],wx:{reLaunch:o=>navigations.push(o.url)}
});
const component={...definition.methods,data:{...definition.data},setData(v){Object.assign(this.data,v);}};
definition.lifetimes.attached.call(component);assert.equal(component.data.active,'profile');
component.navigate({currentTarget:{dataset:{tab:'profile'}}});assert.equal(navigations.length,0);
component.navigate({currentTarget:{dataset:{tab:'records'}}});assert.deepEqual(navigations,['/pages/discover/discover']);
route='pages/settings/settings';definition.pageLifetimes.show.call(component);assert.equal(component.data.active,'');
const markup=fs.readFileSync(path.join(root,'components/app-tabbar/app-tabbar.wxml'),'utf8');
assert.ok(markup.includes('wx:if="{{active}}"'));
});