Files
stack/packages/webui/tests/org-tree-recovery-browser.test.mjs

24 lines
1.4 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import { w15Fixture } from './w15-fixture.mjs';
test('project tree returns after a failed refresh followed by the same data', async t => {
const { f, b, wait } = await w15Fixture(t);
await b.navigate(f.base + '/#/projects');
await wait(`document.querySelector('.project-tree-list a')`);
const result = await b.evaluate(`(async()=>{
const container=document.querySelector('.project-tree-list').parentElement;
const link=container.querySelector('.project-tree-list a'); link.focus(); const href=link.getAttribute('href');
const originalFetch=window.fetch, originalNow=Date.now;
Date.now=()=>originalNow()+20000;
window.fetch=(url,options)=>String(url)==='/api/chat/threads' ? Promise.reject(Error('offline')) : originalFetch(url,options);
await MosaicProjectTree.mount({container,path:'/projects'});
const unavailable=!!container.querySelector('[role=status],[role=alert]') && container.textContent.includes('Projects unavailable');
window.fetch=originalFetch;
await MosaicProjectTree.mount({container,path:'/projects'});
Date.now=originalNow;
return {unavailable,recovered:!!container.querySelector('.project-tree-list a'),focused:document.activeElement.getAttribute('href')===href};
})()`);
assert.deepEqual(result, {unavailable:true,recovered:true,focused:true});
});