History as compat layer over Navigation

This commit is contained in:
Muki Kiboigo
2025-10-12 16:03:52 -07:00
parent e80c8d5bff
commit f97697535f
4 changed files with 76 additions and 57 deletions

View File

@@ -5,7 +5,6 @@
testing.expectEqual('auto', history.scrollRestoration);
history.scrollRestoration = 'manual';
history.scrollRestoration = 'foo';
testing.expectEqual('manual', history.scrollRestoration);
history.scrollRestoration = 'auto';

View File

@@ -0,0 +1,49 @@
<!DOCTYPE html>
<script src="../testing.js"></script>
<script id=navigation>
testing.expectEqual('object', typeof navigation);
testing.expectEqual('object', typeof navigation.currentEntry);
testing.expectEqual('string', typeof navigation.currentEntry.id);
testing.expectEqual('string', typeof navigation.currentEntry.key);
testing.expectEqual('string', typeof navigation.currentEntry.url);
testing.expectEqual(0, navigation.currentEntry.index);
testing.expectEqual(true, navigation.currentEntry.sameDocument);
let result = navigation.navigate('http://127.0.0.1:9582/xhr/json', {
state: { testInProgress: true }
});
testing.expectEqual('object', typeof result);
testing.expectEqual('object', typeof result.committed);
testing.expectEqual('object', typeof result.finished);
testing.expectEqual({ testInProgress: true }, navigation.currentEntry.getState());
testing.expectEqual(1, navigation.currentEntry.index);
testing.expectEqual(true, navigation.canGoBack);
testing.expectEqual(false, navigation.canGoForward);
testing.expectEqual(undefined, navigation.back());
testing.onPageWait(() => {
testing.expectEqual(0, navigation.currentEntry.index);
testing.expectEqual(true, navigation.canGoForward);
testing.expectEqual(undefined, navigation.forward());
});
testing.onPageWait(() => {
testing.expectEqual(1, navigation.currentEntry.index);
testing.expectEqual({ testInProgress: true }, navigation.currentEntry.getState());
let targetKey = navigation.currentEntry.key;
testing.expectEqual(undefined, navigation.traverseTo(targetKey));
});
navigation.updateCurrentEntry({ state: { updated: true, testComplete: true } });
testing.expectEqual({ updated: true, testComplete: true }, navigation.currentEntry.getState());
testing.onPageWait(() => {
testing.expectEqual(true, navigation.currentEntry.getState().testComplete);
});
</script>