40 lines
2.9 KiB
JavaScript
40 lines
2.9 KiB
JavaScript
const test = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const path = require('node:path');
|
|
const createLoader = require('./load-module.cjs');
|
|
function setup(initial, seen = true) {
|
|
const storage = new Map(seen ? [['launchIntroSeen', true]] : []);
|
|
let definition, notify, unsubscribed = false;
|
|
const timers = new Map();let timerId=0;
|
|
const app={observeAuth(callback){notify=callback;callback(initial,'');return ()=>{unsubscribed=true;};}};
|
|
const load=createLoader({wx:{getStorageSync:k=>storage.get(k),setStorageSync:(k,v)=>storage.set(k,v)},Component:c=>definition=c,getApp:()=>app,Date,
|
|
setTimeout(fn){timers.set(++timerId,fn);return timerId;},clearTimeout(id){timers.delete(id);}});
|
|
load(path.join(__dirname,'../components/launch-transition/launch-transition.js'));
|
|
const updates=[];
|
|
const component={...definition.methods,data:{...definition.data},setData(values){updates.push(values);Object.assign(this.data,values);}};
|
|
return {definition,component,updates,timers,storage,notify:(...args)=>notify(...args),unsubscribed:()=>unsubscribed};
|
|
}
|
|
test('authenticated page transitions never show the launch overlay, even on initial render',()=>{
|
|
const e=setup('ready');assert.equal(e.component.data.visible,false);
|
|
e.definition.lifetimes.attached.call(e.component);
|
|
assert.equal(e.component.data.visible,false);assert.ok(e.updates.every(update=>update.visible!==true));assert.equal(e.timers.size,0);
|
|
});
|
|
test('cold-start waiting and login failures still show overlay and release subscriptions',()=>{
|
|
const e=setup('loading',false);e.definition.lifetimes.attached.call(e.component);assert.equal(e.component.data.visible,true);
|
|
e.notify('error','login failed');assert.equal(e.component.data.state,'error');assert.equal(e.component.data.message,'login failed');
|
|
e.notify('ready');assert.equal(e.timers.size,0);assert.equal(e.component.data.visible,false);
|
|
e.definition.lifetimes.detached.call(e.component);assert.equal(e.unsubscribed(),true);assert.equal(e.timers.size,0);
|
|
});
|
|
|
|
test('introduction is shown once per device, including when login is already ready',()=>{
|
|
const first=setup('ready',false);first.definition.lifetimes.attached.call(first.component);
|
|
assert.equal(first.component.data.visible,true);assert.equal(first.component.data.intro,true);
|
|
assert.equal(first.storage.get('launchIntroSeen'),true);
|
|
for(const fn of first.timers.values())fn();assert.equal(first.component.data.visible,false);
|
|
first.notify('loading');assert.equal(first.component.data.visible,false);
|
|
const next=setup('loading',first.storage.get('launchIntroSeen'));next.definition.lifetimes.attached.call(next.component);
|
|
assert.equal(next.component.data.visible,false);
|
|
next.notify('error','network unavailable');assert.equal(next.component.data.visible,true);assert.equal(next.component.data.intro,false);
|
|
next.notify('ready');assert.equal(next.component.data.visible,false);
|
|
});
|