Files
outline/app/models/base/Model.test.ts
Tom MoorandClaude Opus 5.5 9e2565184e chore: Prune stale comments, TODOs, and type suppressions (#14092)
* chore: Remove unused lint disable directives

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WJegM4QsoYSKrBKb6eB4CH

* chore: Replace TODO type suppressions with typed code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WJegM4QsoYSKrBKb6eB4CH

* chore: Remove obsolete workaround comments in tests and MediaDimension

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WJegM4QsoYSKrBKb6eB4CH

* chore: Remove Tippy compatibility props from Tooltip

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WJegM4QsoYSKrBKb6eB4CH

* chore: Decouple DropdownMenu props from Tooltip and clarify sharing styles

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WJegM4QsoYSKrBKb6eB4CH

* chore: Remove stale retention TODOs from cleanup tasks

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WJegM4QsoYSKrBKb6eB4CH

* chore: Register relations synchronously and clarify workaround comments

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WJegM4QsoYSKrBKb6eB4CH

* chore: Replace Notion import TODOs with descriptive comments

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WJegM4QsoYSKrBKb6eB4CH

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-10-15 08:54:37 -04:00

136 lines
4.8 KiB
TypeScript

import { autorun, isAction, isObservableProp } from "mobx";
import stores from "~/stores";
describe("Model observability", () => {
it("annotates fields declared on the base class and on subclasses", () => {
const doc = stores.documents.add({
id: "aaaaaaaa-1111-1111-1111-111111111111",
title: "hello",
});
expect(isObservableProp(doc, "id")).toBe(true); // base Model, in payload
expect(isObservableProp(doc, "isSaving")).toBe(true); // base Model, has a default
expect(isObservableProp(doc, "title")).toBe(true); // subclass, in payload
expect(isObservableProp(doc, "embedsDisabled")).toBe(true); // subclass, has a default
});
it("annotates fields omitted from the initial payload", () => {
// A model created from a partial payload, as a list response returns.
const doc = stores.documents.add({
id: "aaaaaaaa-3333-3333-3333-333333333333",
title: "partial",
});
expect(isObservableProp(doc, "fullWidth")).toBe(true);
});
it("reacts when a later payload populates an omitted field", () => {
const doc = stores.documents.add({
id: "aaaaaaaa-5555-5555-5555-555555555555",
title: "partial",
});
const seen: Array<boolean | undefined> = [];
const dispose = autorun(() => seen.push(doc.fullWidth));
// The full payload introduces the field, which must become reactive.
stores.documents.add({
id: "aaaaaaaa-5555-5555-5555-555555555555",
title: "partial",
fullWidth: false,
});
doc.fullWidth = true;
dispose();
expect(seen).toEqual([undefined, false, true]);
});
it("annotates fields inherited from base classes and omitted from the payload", () => {
const doc = stores.documents.add({
id: "aaaaaaaa-6666-6666-6666-666666666666",
title: "partial",
});
expect(isObservableProp(doc, "createdAt")).toBe(true); // Model
expect(isObservableProp(doc, "deletedAt")).toBe(true); // ParanoidModel
expect(isObservableProp(doc, "archivedAt")).toBe(true); // ArchivableModel
});
it("annotates observable fields that are not serializable fields", () => {
// Revision content is observable but not a @Field, and list responses
// omit it entirely.
const revision = stores.revisions.add({
id: "bbbbbbbb-1111-1111-1111-111111111111",
documentId: "aaaaaaaa-1111-1111-1111-111111111111",
title: "partial",
});
expect(isObservableProp(revision, "data")).toBe(true);
});
it("tracks reads of an omitted field made before it is populated", () => {
const revision = stores.revisions.add({
id: "bbbbbbbb-2222-2222-2222-222222222222",
documentId: "aaaaaaaa-1111-1111-1111-111111111111",
title: "partial",
});
const seen: Array<string | undefined> = [];
const dispose = autorun(() => seen.push(revision.data?.type));
stores.revisions.add({
id: "bbbbbbbb-2222-2222-2222-222222222222",
documentId: "aaaaaaaa-1111-1111-1111-111111111111",
title: "partial",
data: { type: "doc", content: [] },
});
dispose();
expect(seen).toEqual([undefined, "doc"]);
});
it("reacts to changes", () => {
const doc = stores.documents.add({
id: "aaaaaaaa-2222-2222-2222-222222222222",
title: "a",
});
const seen: string[] = [];
const dispose = autorun(() => seen.push(doc.title));
doc.title = "b";
dispose();
expect(seen).toEqual(["a", "b"]);
});
it("annotates computed values inherited from the base class", () => {
const doc = stores.documents.add({
id: "aaaaaaaa-4444-4444-4444-444444444444",
title: "c",
});
const seen: boolean[] = [];
const dispose = autorun(() => seen.push(doc.isDeleted));
doc.deletedAt = "2026-08-18T00:00:00.000Z";
dispose();
expect(seen).toEqual([false, true]);
});
it("makes store fields observable", () => {
expect(isObservableProp(stores.documents, "isFetching")).toBe(true);
expect(isObservableProp(stores.documents, "backlinks")).toBe(true);
expect(isObservableProp(stores.ui, "theme")).toBe(true);
expect(isObservableProp(stores.auth, "currentUserId")).toBe(true);
});
it("annotates actions declared as store fields", () => {
expect(isAction(stores.collections.import)).toBe(true);
expect(isAction(stores.comments.resolve)).toBe(true);
expect(isAction(stores.groupUsers.removeGroupMemberships)).toBe(true);
expect(isAction(stores.imports.cancel)).toBe(true);
expect(isAction(stores.memberships.removeCollectionMemberships)).toBe(true);
expect(isAction(stores.notifications.markAllAsRead)).toBe(true);
expect(isAction(stores.templates.duplicate)).toBe(true);
expect(isAction(Reflect.get(stores.unfurls, "unfurl"))).toBe(true);
expect(isAction(stores.userMemberships.fetchDocumentMemberships)).toBe(
true
);
expect(isAction(stores.users.invite)).toBe(true);
});
});