@@ -167,7 +167,10 @@ describe("dirty triggers", () => {
167167
168168 it("title change and path change mark the group dirty", () => {
169169 expect(step(base(), { type: "tabUpdated", tab: tab(1, { groupId: 10, title: "New" }) }, ctx()).actions).toEqual([{ type: "dirty", groupId: 10 }]);
170− expect(step(base(), { type: "tabUpdated", tab: tab(1, { groupId: 10, url: "https://example.com/other" }) }, ctx()).actions).toEqual([{ type: "dirty", groupId: 10 }]);
170+ expect(step(base(), { type: "tabUpdated", tab: tab(1, { groupId: 10, url: "https://example.com/other" }) }, ctx()).actions).toEqual([
171+ { type: "checkFit" },
172+ { type: "dirty", groupId: 10 },
173+ ]);
171174 });
172175
173176 it("reload, fragment and query changes do not", () => {
@@ -252,3 +255,58 @@ describe("auto-organize triggers", () => {
252255 expect(state.tabs[1].lastActivatedAt).toBe(5_000_000);
253256 });
254257});
258+
259+describe("fit check", () => {
260+ const group = () => stateWith([tab(1, { groupId: 10 }), tab(2, { groupId: 10 }), tab(3, { groupId: 10 })], [{ id: 10, origin: "organize" }]);
261+ const moveOn = (s = group(), over = {}) =>
262+ step(s, { type: "tabUpdated", tab: tab(1, { groupId: 10, url: "https://news.example/story", ...over }) }, ctx());
263+
264+ it("a tab in a Diagonal group that goes to a new page is checked once it has loaded", () => {
265+ const loading = moveOn(group(), { status: "loading" });
266+ expect(loading.state.tabs[1].fitPending).toBe(true);
267+ expect(loading.actions).not.toContainEqual({ type: "checkFit" });
268+ const loaded = step(loading.state, { type: "tabUpdated", tab: tab(1, { groupId: 10, url: "https://news.example/story" }) }, ctx());
269+ expect(loaded.actions).toContainEqual({ type: "checkFit" });
270+ });
271+
272+ it("switching to another tab checks the pending one", () => {
273+ const { state } = moveOn(group(), { status: "loading" });
274+ expect(step(state, { type: "tabActivated", tabId: 2 }, ctx()).actions).toContainEqual({ type: "checkFit" });
275+ expect(step(state, { type: "tabActivated", tabId: 1 }, ctx()).actions).not.toContainEqual({ type: "checkFit" });
276+ });
277+
278+ it("leaves groups you named and groups you made alone", () => {
279+ const named = group();
280+ named.groups[10].userNamed = true;
281+ expect(moveOn(named).state.tabs[1].fitPending).toBeUndefined();
282+ const yours = stateWith([tab(1, { groupId: 10 }), tab(2, { groupId: 10 })], [{ id: 10, origin: "user" }]);
283+ expect(moveOn(yours).state.tabs[1].fitPending).toBeUndefined();
284+ expect(moveOn(group(), {}).state.tabs[1].fitPending).toBe(true);
285+ const off = step(group(), { type: "tabUpdated", tab: tab(1, { groupId: 10, url: "https://news.example/story" }) }, ctx(0, { autoOrganize: false }));
286+ expect(off.state.tabs[1].fitPending).toBeUndefined();
287+ });
288+
289+ it("a tab you dragged into a group stays there", () => {
290+ const s = stateWith([tab(1), tab(2, { groupId: 10 }), tab(3, { groupId: 10 })], [{ id: 10, origin: "organize" }]);
291+ const dragged = step(s, { type: "tabUpdated", tab: tab(1, { groupId: 10 }) }, ctx());
292+ expect(dragged.state.tabs[1].handPlaced).toBe(true);
293+ expect(moveOn(dragged.state).state.tabs[1].fitPending).toBeUndefined();
294+ });
295+
296+ it("a tab Diagonal put in the group is still checked", () => {
297+ const s = stateWith([tab(1), tab(2, { groupId: 10 }), tab(3, { groupId: 10 })], [{ id: 10, origin: "organize" }]);
298+ s.ownAdds[1] = 1_000_000;
299+ const added = step(s, { type: "tabUpdated", tab: tab(1, { groupId: 10 }) }, ctx());
300+ expect(added.state.tabs[1].handPlaced).toBeUndefined();
301+ expect(added.state.ownAdds[1]).toBeUndefined();
302+ expect(moveOn(added.state).state.tabs[1].fitPending).toBe(true);
303+ });
304+
305+ it("leaving the group clears both marks", () => {
306+ const pending = moveOn(group(), { status: "loading" }).state;
307+ pending.tabs[1].handPlaced = true;
308+ const out = step(pending, { type: "tabUpdated", tab: tab(1, { url: "https://news.example/story" }) }, ctx());
309+ expect(out.state.tabs[1].fitPending).toBeUndefined();
310+ expect(out.state.tabs[1].handPlaced).toBeUndefined();
311+ });
312+});