Shell: one-shot #example-<id> deep link consumed at startup

This commit is contained in:
2026-07-04 16:40:56 +03:00
parent db258a4e54
commit 5ec7c3aa77
5 changed files with 79 additions and 0 deletions
+19
View File
@@ -1,6 +1,7 @@
import { describe, it, expect, beforeEach } from 'vitest';
import {
parseHash,
parseExampleHash,
serializeHash,
readView,
replaceView,
@@ -75,6 +76,24 @@ describe('parseHash', () => {
});
});
describe('parseExampleHash', () => {
it('extracts the example id from the one-shot action link', () => {
expect(parseExampleHash('#example-brush')).toBe('brush');
expect(parseExampleHash('example-bar')).toBe('bar'); // leading "#" optional
});
it('returns null for anything that is not an example link', () => {
expect(parseExampleHash('')).toBeNull();
expect(parseExampleHash('#example-')).toBeNull(); // empty id
expect(parseExampleHash('#snippet-abc')).toBeNull();
expect(parseExampleHash('#build')).toBeNull();
});
it('is not a ViewState: parseHash degrades an example link to the default view', () => {
expect(parseHash('#example-brush')).toEqual({ kind: 'snippets' });
});
});
describe('round-trip identity', () => {
it('parseHash(serializeHash(v)) deep-equals v for every variant', () => {
for (const v of ALL_VIEWS) {