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(/{ 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}}"')); });