shelving 1.319.1 → 1.321.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/guides/building-with-shelving.md +26 -0
- package/docs/llms-full.txt +752 -265
- package/docs/ui/BackButton.md +75 -0
- package/docs/ui/BackButtonProps.md +21 -0
- package/docs/ui/ClickableProps.md +0 -2
- package/docs/ui/FADE_TRANSITION_CLASS.md +9 -0
- package/docs/ui/FadeTransition.md +13 -0
- package/docs/ui/Head.md +2 -2
- package/docs/ui/HorizontalTransition.md +21 -5
- package/docs/ui/LinkClickable.md +0 -1
- package/docs/ui/Meta.md +3 -1
- package/docs/ui/Navigation.md +93 -37
- package/docs/ui/NavigationEntryState.md +22 -0
- package/docs/ui/NavigationPosition.md +24 -0
- package/docs/ui/NavigationPositionContext.md +8 -0
- package/docs/ui/NavigationProps.md +12 -2
- package/docs/ui/NavigationStore/back.md +6 -4
- package/docs/ui/NavigationStore/forward.md +6 -2
- package/docs/ui/NavigationStore/history.md +15 -0
- package/docs/ui/NavigationStore/listen.md +14 -0
- package/docs/ui/NavigationStore/replace.md +15 -0
- package/docs/ui/NavigationStore.md +100 -19
- package/docs/ui/RouteCache.md +72 -36
- package/docs/ui/RouteCacheProps.md +3 -3
- package/docs/ui/Router.md +4 -2
- package/docs/ui/SLIDE_DOWN_TRANSITION_CLASS.md +9 -0
- package/docs/ui/SLIDE_LEFT_TRANSITION_CLASS.md +9 -0
- package/docs/ui/SLIDE_RIGHT_TRANSITION_CLASS.md +9 -0
- package/docs/ui/SLIDE_UP_TRANSITION_CLASS.md +9 -0
- package/docs/ui/StackButton.md +64 -0
- package/docs/ui/StackButtonProps.md +21 -0
- package/docs/ui/VerticalTransition.md +21 -5
- package/docs/ui/mergeMeta.md +2 -1
- package/docs/ui.md +18 -10
- package/package.json +1 -1
- package/ui/button/Clickable.d.ts +1 -3
- package/ui/button/Clickable.js +2 -2
- package/ui/button/Clickable.tsx +0 -4
- package/ui/dialog/Dialog.d.ts +0 -1
- package/ui/dialog/Dialog.js +2 -2
- package/ui/dialog/Dialog.tsx +2 -2
- package/ui/notice/NoticesTransition.module.css +1 -1
- package/ui/page/Head.d.ts +2 -2
- package/ui/page/Head.js +9 -8
- package/ui/page/Head.tsx +8 -6
- package/ui/router/BackButton.d.ts +22 -0
- package/ui/router/BackButton.js +19 -0
- package/ui/router/BackButton.md +47 -0
- package/ui/router/BackButton.tsx +34 -0
- package/ui/router/Navigation.d.ts +22 -12
- package/ui/router/Navigation.js +67 -51
- package/ui/router/Navigation.md +84 -27
- package/ui/router/Navigation.test.tsx +27 -7
- package/ui/router/Navigation.tsx +90 -53
- package/ui/router/NavigationContext.d.ts +9 -1
- package/ui/router/NavigationContext.js +9 -0
- package/ui/router/NavigationContext.tsx +11 -1
- package/ui/router/NavigationStore.d.ts +126 -19
- package/ui/router/NavigationStore.js +301 -30
- package/ui/router/NavigationStore.md +82 -9
- package/ui/router/NavigationStore.test.ts +384 -0
- package/ui/router/NavigationStore.tsx +347 -30
- package/ui/router/RouteCache.d.ts +15 -22
- package/ui/router/RouteCache.js +36 -47
- package/ui/router/RouteCache.md +59 -16
- package/ui/router/RouteCache.tsx +55 -62
- package/ui/router/Router.d.ts +2 -1
- package/ui/router/Router.js +9 -14
- package/ui/router/Router.md +2 -1
- package/ui/router/Router.tsx +9 -20
- package/ui/router/StackButton.d.ts +24 -0
- package/ui/router/StackButton.js +35 -0
- package/ui/router/StackButton.md +34 -0
- package/ui/router/StackButton.tsx +44 -0
- package/ui/router/index.d.ts +2 -2
- package/ui/router/index.js +2 -2
- package/ui/router/index.ts +2 -2
- package/ui/transition/FadeTransition.d.ts +9 -1
- package/ui/transition/FadeTransition.js +12 -2
- package/ui/transition/FadeTransition.md +13 -0
- package/ui/transition/{FadeTransition.css → FadeTransition.module.css} +9 -2
- package/ui/transition/FadeTransition.tsx +13 -2
- package/ui/transition/HorizontalTransition.d.ts +18 -1
- package/ui/transition/HorizontalTransition.js +21 -2
- package/ui/transition/HorizontalTransition.md +21 -5
- package/ui/transition/{HorizontalTransition.css → HorizontalTransition.module.css} +17 -5
- package/ui/transition/HorizontalTransition.tsx +30 -2
- package/ui/transition/VerticalTransition.d.ts +18 -1
- package/ui/transition/VerticalTransition.js +21 -2
- package/ui/transition/VerticalTransition.md +21 -5
- package/ui/transition/{VerticalTransition.css → VerticalTransition.module.css} +17 -5
- package/ui/transition/VerticalTransition.tsx +25 -2
- package/ui/util/meta.d.ts +4 -1
- package/ui/util/meta.ts +4 -1
- package/docs/ui/NavigationStore/redirect.md +0 -12
- package/docs/ui/RouteConfig.md +0 -75
- package/docs/ui/RouteConfigProps.md +0 -24
- package/docs/ui/RouteContext.md +0 -6
- package/docs/ui/RouteState.md +0 -30
- package/ui/router/RouteConfig.d.ts +0 -28
- package/ui/router/RouteConfig.js +0 -30
- package/ui/router/RouteConfig.md +0 -42
- package/ui/router/RouteConfig.tsx +0 -44
- package/ui/router/RouteContext.d.ts +0 -22
- package/ui/router/RouteContext.js +0 -8
- package/ui/router/RouteContext.tsx +0 -26
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
|
|
2
|
+
import { NavigationStore } from "shelving/ui";
|
|
3
|
+
|
|
4
|
+
// A small fake of the browser Navigation API and `window.history`, enough for `NavigationStore`.
|
|
5
|
+
|
|
6
|
+
type Listener = (e: Record<string, unknown>) => void;
|
|
7
|
+
|
|
8
|
+
class FakeEntry {
|
|
9
|
+
readonly url: string;
|
|
10
|
+
readonly key: string;
|
|
11
|
+
readonly index: number;
|
|
12
|
+
state: unknown;
|
|
13
|
+
constructor(url: string, key: string, index: number, state: unknown) {
|
|
14
|
+
this.url = url;
|
|
15
|
+
this.key = key;
|
|
16
|
+
this.index = index;
|
|
17
|
+
this.state = state;
|
|
18
|
+
}
|
|
19
|
+
getState(): unknown {
|
|
20
|
+
return this.state;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
class FakeNavigation {
|
|
25
|
+
list: FakeEntry[] = [];
|
|
26
|
+
index = 0;
|
|
27
|
+
count = 0;
|
|
28
|
+
readonly listeners = new Map<string, Set<Listener>>();
|
|
29
|
+
constructor(url: string) {
|
|
30
|
+
this.list = [new FakeEntry(url, "k0", 0, undefined)];
|
|
31
|
+
}
|
|
32
|
+
entries(): FakeEntry[] {
|
|
33
|
+
return this.list;
|
|
34
|
+
}
|
|
35
|
+
get currentEntry(): FakeEntry {
|
|
36
|
+
return this.list[this.index] as FakeEntry;
|
|
37
|
+
}
|
|
38
|
+
updateCurrentEntry({ state }: { state: unknown }): void {
|
|
39
|
+
this.currentEntry.state = state;
|
|
40
|
+
}
|
|
41
|
+
addEventListener(type: string, listener: Listener): void {
|
|
42
|
+
this.listeners.set(type, (this.listeners.get(type) ?? new Set()).add(listener));
|
|
43
|
+
}
|
|
44
|
+
removeEventListener(type: string, listener: Listener): void {
|
|
45
|
+
this.listeners.get(type)?.delete(listener);
|
|
46
|
+
}
|
|
47
|
+
fire(type: string, e: Record<string, unknown>): void {
|
|
48
|
+
for (const l of this.listeners.get(type) ?? []) l(e);
|
|
49
|
+
}
|
|
50
|
+
push(url: string): void {
|
|
51
|
+
const from = this.currentEntry;
|
|
52
|
+
this.fire("navigate", { info: undefined, hasUAVisualTransition: false });
|
|
53
|
+
this.index++;
|
|
54
|
+
this.list = [...this.list.slice(0, this.index), new FakeEntry(new URL(url, from.url).href, `k${++this.count}`, this.index, undefined)];
|
|
55
|
+
this.fire("currententrychange", { navigationType: "push", from });
|
|
56
|
+
}
|
|
57
|
+
replace(url: string): void {
|
|
58
|
+
const from = this.currentEntry;
|
|
59
|
+
this.list[this.index] = new FakeEntry(new URL(url, from.url).href, from.key, this.index, undefined);
|
|
60
|
+
this.fire("currententrychange", { navigationType: "replace", from });
|
|
61
|
+
}
|
|
62
|
+
traverseTo(key: string, { info }: { info?: unknown } = {}): { finished: Promise<void> } {
|
|
63
|
+
const from = this.currentEntry;
|
|
64
|
+
this.fire("navigate", { info, hasUAVisualTransition: false });
|
|
65
|
+
this.index = this.list.findIndex(e => e.key === key);
|
|
66
|
+
this.fire("currententrychange", { navigationType: "traverse", from });
|
|
67
|
+
return { finished: Promise.resolve() };
|
|
68
|
+
}
|
|
69
|
+
go(delta: number): void {
|
|
70
|
+
const target = this.list[this.index + delta];
|
|
71
|
+
if (target) this.traverseTo(target.key);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const ORIGIN = "https://app.test";
|
|
76
|
+
const STACKS = ["/home", "/discover", "/profile"] as const;
|
|
77
|
+
const globals = globalThis as { navigation?: unknown; window?: unknown };
|
|
78
|
+
let fake: FakeNavigation;
|
|
79
|
+
|
|
80
|
+
/** Open the app at `path`, in `stack` (by default the stack whose root is `path`, else `/`). */
|
|
81
|
+
function setup(path = "/home", stack = (STACKS as readonly string[]).includes(path) ? path : "/"): NavigationStore {
|
|
82
|
+
fake = new FakeNavigation(`${ORIGIN}${path}`);
|
|
83
|
+
globals.navigation = fake;
|
|
84
|
+
globals.window = {
|
|
85
|
+
location: { href: `${ORIGIN}${path}` },
|
|
86
|
+
history: {
|
|
87
|
+
pushState: (_s: unknown, _t: string, url: string) => fake.push(url),
|
|
88
|
+
replaceState: (_s: unknown, _t: string, url: string) => fake.replace(url),
|
|
89
|
+
},
|
|
90
|
+
addEventListener: () => undefined,
|
|
91
|
+
removeEventListener: () => undefined,
|
|
92
|
+
};
|
|
93
|
+
const nav = new NavigationStore(`${ORIGIN}${path}`, `${ORIGIN}/`, stack as `/${string}`, ...STACKS);
|
|
94
|
+
nav.listen();
|
|
95
|
+
return nav;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function getEntries(): string[] {
|
|
99
|
+
return fake.list.map(e => {
|
|
100
|
+
const s = e.state as { stack: string; depth: number } | undefined;
|
|
101
|
+
return `${new URL(e.url).pathname}${s ? ` ${s.stack}@${s.depth}` : ""}`;
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
beforeEach(() => {
|
|
106
|
+
delete globals.navigation;
|
|
107
|
+
delete globals.window;
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
afterEach(() => {
|
|
111
|
+
delete globals.navigation;
|
|
112
|
+
delete globals.window;
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
describe("NavigationStore", () => {
|
|
116
|
+
test("has no history without the Navigation API", () => {
|
|
117
|
+
const nav = new NavigationStore(`${ORIGIN}/home`, `${ORIGIN}/`, "/home", ...STACKS);
|
|
118
|
+
expect(nav.stack.value).toBe("/home");
|
|
119
|
+
expect(nav.history("/home")).toEqual([]);
|
|
120
|
+
expect(nav.position).toBe(undefined);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
test("defaults to one stack at the root", () => {
|
|
124
|
+
expect(new NavigationStore(`${ORIGIN}/home`, `${ORIGIN}/`).stack.value).toBe("/");
|
|
125
|
+
fake = new FakeNavigation(`${ORIGIN}/a/b`);
|
|
126
|
+
globals.navigation = fake;
|
|
127
|
+
expect(new NavigationStore(`${ORIGIN}/a/b`, `${ORIGIN}/`).stack.value).toBe("/");
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
test("keeps the starting stack without the Navigation API", () => {
|
|
131
|
+
globals.window = {
|
|
132
|
+
location: { href: `${ORIGIN}/home` },
|
|
133
|
+
history: { pushState: () => undefined, replaceState: () => undefined },
|
|
134
|
+
};
|
|
135
|
+
const nav = new NavigationStore(`${ORIGIN}/home`, `${ORIGIN}/`, "/home", ...STACKS);
|
|
136
|
+
nav.forward("/profile/settings");
|
|
137
|
+
nav.back("/discover");
|
|
138
|
+
expect(nav.stack.value).toBe("/home");
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
test("opens in the starting stack", () => {
|
|
142
|
+
const nav = setup("/profile/settings", "/profile");
|
|
143
|
+
expect(nav.stack.value).toBe("/profile");
|
|
144
|
+
expect(getEntries()).toEqual(["/profile/settings /profile@0"]);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
test("opens a stack root in / with no starting stack", () => {
|
|
148
|
+
const nav = setup("/profile", "/");
|
|
149
|
+
expect(nav.stack.value).toBe("/");
|
|
150
|
+
expect(getEntries()).toEqual(["/profile /@0"]);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
test("keeps the saved stack after a reload", () => {
|
|
154
|
+
fake = new FakeNavigation(`${ORIGIN}/home/post/1`);
|
|
155
|
+
(fake.list[0] as FakeEntry).state = { stack: "/home", depth: 1 };
|
|
156
|
+
globals.navigation = fake;
|
|
157
|
+
globals.window = { location: { href: `${ORIGIN}/home/post/1` } };
|
|
158
|
+
const nav = new NavigationStore(`${ORIGIN}/home/post/1`, `${ORIGIN}/`, "/profile", ...STACKS);
|
|
159
|
+
expect(nav.stack.value).toBe("/home");
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
describe("unstacked pages", () => {
|
|
163
|
+
test("open any other page in the unstacked / stack", () => {
|
|
164
|
+
const nav = setup("/profile/settings");
|
|
165
|
+
expect(nav.stack.value).toBe("/");
|
|
166
|
+
expect(getEntries()).toEqual(["/profile/settings /@0"]);
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
test("push links deeper in the unstacked stack", () => {
|
|
170
|
+
const nav = setup("/login");
|
|
171
|
+
nav.forward("/login/reset");
|
|
172
|
+
expect(nav.stack.value).toBe("/");
|
|
173
|
+
expect(nav.history()).toEqual(["/login", "/login/reset"]);
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
test("stay unstacked when a link or a replace goes to a stack root", () => {
|
|
177
|
+
const nav = setup("/login");
|
|
178
|
+
nav.forward("/home");
|
|
179
|
+
expect(getEntries().at(-1)).toBe("/home /@1");
|
|
180
|
+
nav.replace("/profile");
|
|
181
|
+
expect(getEntries().at(-1)).toBe("/profile /@1");
|
|
182
|
+
expect(nav.stack.value).toBe("/");
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
test("move into a stack when forward names it", () => {
|
|
186
|
+
const nav = setup("/login");
|
|
187
|
+
nav.forward("/home", "/home");
|
|
188
|
+
expect(nav.stack.value).toBe("/home");
|
|
189
|
+
expect(getEntries().at(-1)).toBe("/home /home@0");
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
test("move into a stack when a replace names it", () => {
|
|
193
|
+
const nav = setup("/login");
|
|
194
|
+
nav.replace("/home", "/home");
|
|
195
|
+
expect(nav.stack.value).toBe("/home");
|
|
196
|
+
expect(getEntries()).toEqual(["/home /home@0"]);
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
test("move onto the top of a stack when a replace names it", () => {
|
|
200
|
+
const nav = setup("/home");
|
|
201
|
+
nav.forward("/home/post/1");
|
|
202
|
+
nav.forward("/login", "/");
|
|
203
|
+
nav.replace("/home/post/2", "/home");
|
|
204
|
+
expect(getEntries().at(-1)).toBe("/home/post/2 /home@2");
|
|
205
|
+
expect(nav.history("/home")).toEqual(["/home", "/home/post/1", "/home/post/2"]);
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
test("move into a stack when back names it", () => {
|
|
209
|
+
const nav = setup("/home/post/1");
|
|
210
|
+
nav.back("/home", "/home");
|
|
211
|
+
expect(nav.stack.value).toBe("/home");
|
|
212
|
+
expect(getEntries().at(-1)).toBe("/home /home@0");
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
test("have no parent", () => {
|
|
216
|
+
const nav = setup("/home/post/1");
|
|
217
|
+
expect(nav.position?.parent).toBe(undefined);
|
|
218
|
+
});
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
describe("forward()", () => {
|
|
222
|
+
test("pushes one level deeper in the current stack", () => {
|
|
223
|
+
const nav = setup();
|
|
224
|
+
nav.forward("/home/post/1");
|
|
225
|
+
nav.forward("/home/post/1/comments");
|
|
226
|
+
expect(nav.history("/home")).toEqual(["/home", "/home/post/1", "/home/post/1/comments"]);
|
|
227
|
+
expect(nav.transition).toBe("forward");
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
test("pushes onto the current stack wherever the link points", () => {
|
|
231
|
+
const nav = setup();
|
|
232
|
+
nav.forward("/profile/settings");
|
|
233
|
+
expect(nav.stack.value).toBe("/home");
|
|
234
|
+
expect(nav.history("/home")).toEqual(["/home", "/profile/settings"]);
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
test("switches stack at the same depth and slides by tab order", () => {
|
|
238
|
+
const nav = setup();
|
|
239
|
+
nav.forward("/home/post/1");
|
|
240
|
+
nav.forward("/profile", "/profile");
|
|
241
|
+
expect(nav.transition).toBe("forward");
|
|
242
|
+
nav.forward("/home/post/1", "/home");
|
|
243
|
+
expect(nav.transition).toBe("back");
|
|
244
|
+
expect(nav.stack.value).toBe("/home");
|
|
245
|
+
expect(getEntries().at(-1)).toBe("/home/post/1 /home@1");
|
|
246
|
+
expect(nav.history("/home")).toEqual(["/home", "/home/post/1"]);
|
|
247
|
+
expect(nav.history("/profile")).toEqual(["/profile"]);
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
test("replaces when the URL is the current one", () => {
|
|
251
|
+
const nav = setup();
|
|
252
|
+
nav.forward("/home");
|
|
253
|
+
expect(fake.list.length).toBe(1);
|
|
254
|
+
expect(nav.transition).toBe(null);
|
|
255
|
+
});
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
describe("back()", () => {
|
|
259
|
+
test("goes back in the browser history when the page is the previous entry", () => {
|
|
260
|
+
const nav = setup();
|
|
261
|
+
nav.forward("/home/post/1");
|
|
262
|
+
nav.back("/home");
|
|
263
|
+
expect(fake.index).toBe(0);
|
|
264
|
+
expect(fake.list.length).toBe(2);
|
|
265
|
+
expect(nav.transition).toBe("back");
|
|
266
|
+
expect(nav.history("/home")).toEqual(["/home"]);
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
test("pushes the page again when other stacks are in between", () => {
|
|
270
|
+
const nav = setup();
|
|
271
|
+
nav.forward("/home/post/1");
|
|
272
|
+
nav.forward("/profile", "/profile");
|
|
273
|
+
nav.forward("/profile/settings");
|
|
274
|
+
nav.forward("/home/post/1", "/home");
|
|
275
|
+
nav.back("/home");
|
|
276
|
+
expect(getEntries().at(-1)).toBe("/home /home@0");
|
|
277
|
+
expect(nav.history("/home")).toEqual(["/home"]);
|
|
278
|
+
expect(nav.history("/profile")).toEqual(["/profile", "/profile/settings"]);
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
test("goes back to the root of another stack when it is named", () => {
|
|
282
|
+
const nav = setup("/profile");
|
|
283
|
+
nav.forward("/profile/settings");
|
|
284
|
+
nav.forward("/discover", "/discover");
|
|
285
|
+
nav.back("/profile", "/profile");
|
|
286
|
+
expect(getEntries().at(-1)).toBe("/profile /profile@0");
|
|
287
|
+
expect(nav.history("/profile")).toEqual(["/profile"]);
|
|
288
|
+
});
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
describe("replace()", () => {
|
|
292
|
+
test("keeps the stack and depth", () => {
|
|
293
|
+
const nav = setup();
|
|
294
|
+
nav.forward("/home/post/1");
|
|
295
|
+
nav.replace("/home/post/1/info");
|
|
296
|
+
expect(getEntries().at(-1)).toBe("/home/post/1/info /home@1");
|
|
297
|
+
expect(nav.transition).toBe(null);
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
test("puts the state back after another script replaces the entry", () => {
|
|
301
|
+
const nav = setup();
|
|
302
|
+
nav.forward("/home/post/1");
|
|
303
|
+
fake.replace(`${ORIGIN}/home/post/1?x=1`);
|
|
304
|
+
expect(getEntries().at(-1)).toBe("/home/post/1 /home@1");
|
|
305
|
+
expect(nav.value.href).toBe(`${ORIGIN}/home/post/1?x=1`);
|
|
306
|
+
});
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
describe("history()", () => {
|
|
310
|
+
test("allows the same page twice in one stack", () => {
|
|
311
|
+
const nav = setup();
|
|
312
|
+
nav.forward("/home/post/1");
|
|
313
|
+
nav.forward("/home/user/ada");
|
|
314
|
+
nav.forward("/home/post/1");
|
|
315
|
+
expect(nav.history("/home")).toEqual(["/home", "/home/post/1", "/home/user/ada", "/home/post/1"]);
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
test("starts with the root when its entry is gone", () => {
|
|
319
|
+
const nav = setup();
|
|
320
|
+
nav.forward("/home/post/1");
|
|
321
|
+
fake.list = fake.list.slice(1).map((e, i) => new FakeEntry(e.url, e.key, i, e.state));
|
|
322
|
+
fake.index = 0;
|
|
323
|
+
expect(nav.history("/home")).toEqual(["/home", "/home/post/1"]);
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
test("ignores entries with no state", () => {
|
|
327
|
+
fake = new FakeNavigation(`${ORIGIN}/landing`);
|
|
328
|
+
const nav = setup();
|
|
329
|
+
fake.list = [
|
|
330
|
+
new FakeEntry(`${ORIGIN}/landing`, "x", 0, undefined),
|
|
331
|
+
...fake.list.map((e, i) => new FakeEntry(e.url, e.key, i + 1, e.state)),
|
|
332
|
+
];
|
|
333
|
+
fake.index = 1;
|
|
334
|
+
expect(nav.history("/home")).toEqual(["/home"]);
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
test("returns the current stack with no stack", () => {
|
|
338
|
+
const nav = setup();
|
|
339
|
+
nav.forward("/home/post/1");
|
|
340
|
+
nav.forward("/profile", "/profile");
|
|
341
|
+
expect(nav.history()).toEqual(["/profile"]);
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
test("keeps the query", () => {
|
|
345
|
+
const nav = setup();
|
|
346
|
+
nav.forward("/home/search?q=birds");
|
|
347
|
+
expect(nav.history("/home")).toEqual(["/home", "/home/search?q=birds"]);
|
|
348
|
+
});
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
describe("browser back and forward", () => {
|
|
352
|
+
test("slides by depth in a stack and by tab order across stacks", () => {
|
|
353
|
+
const nav = setup();
|
|
354
|
+
nav.forward("/home/post/1");
|
|
355
|
+
nav.forward("/profile", "/profile");
|
|
356
|
+
fake.go(-1);
|
|
357
|
+
expect(nav.transition).toBe("back");
|
|
358
|
+
expect(nav.stack.value).toBe("/home");
|
|
359
|
+
fake.go(-1);
|
|
360
|
+
expect(nav.transition).toBe("back");
|
|
361
|
+
expect(nav.value.pathname).toBe("/home");
|
|
362
|
+
fake.go(1);
|
|
363
|
+
expect(nav.transition).toBe("forward");
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
test("slides forward when undoing a pushed back", () => {
|
|
367
|
+
const nav = setup();
|
|
368
|
+
nav.forward("/home/post/1");
|
|
369
|
+
nav.forward("/profile", "/profile");
|
|
370
|
+
nav.forward("/home/post/1", "/home");
|
|
371
|
+
nav.back("/home");
|
|
372
|
+
fake.go(-1);
|
|
373
|
+
expect(nav.transition).toBe("forward");
|
|
374
|
+
});
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
test("position has the depth of each stack's top page and the parent", () => {
|
|
378
|
+
const nav = setup();
|
|
379
|
+
nav.forward("/home/post/1");
|
|
380
|
+
nav.forward("/profile", "/profile");
|
|
381
|
+
nav.forward("/home/post/1", "/home");
|
|
382
|
+
expect(nav.position).toEqual({ stack: "/home", depth: 1, tops: { "/home": 1, "/profile": 0 }, parent: "/home" });
|
|
383
|
+
});
|
|
384
|
+
});
|