Skip to content

Commit

Permalink
Node view tests are green!
Browse files Browse the repository at this point in the history
  • Loading branch information
smoores-dev committed Aug 16, 2023
1 parent 0ebff83 commit b49b5fa
Show file tree
Hide file tree
Showing 6 changed files with 607 additions and 80 deletions.
40 changes: 20 additions & 20 deletions src/components/__tests__/EditorView.domchange.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe("DOM change", () => {
});

it("notices when text is added", async () => {
const view = tempEditor({ doc: doc(p("he<a>llo")) });
const { view } = tempEditor({ doc: doc(p("he<a>llo")) });
const user = userEvent.setup();

await act(async () => {
Expand All @@ -35,7 +35,7 @@ describe("DOM change", () => {
});

it("notices when text is removed", async () => {
const view = tempEditor({ doc: doc(p("hell<a>o")) });
const { view } = tempEditor({ doc: doc(p("hell<a>o")) });
const user = userEvent.setup();

await act(async () => {
Expand All @@ -46,7 +46,7 @@ describe("DOM change", () => {
});

it("respects stored marks", async () => {
const view = tempEditor({ doc: doc(p("hello<a>")) });
const { view } = tempEditor({ doc: doc(p("hello<a>")) });
const user = userEvent.setup();
await act(async () => {
view.dispatch(
Expand All @@ -59,7 +59,7 @@ describe("DOM change", () => {
});

it("support inserting repeated text", async () => {
const view = tempEditor({ doc: doc(p("hello")) });
const { view } = tempEditor({ doc: doc(p("hello")) });
const user = userEvent.setup();
await act(async () => {
await user.type(view.dom, "hel");
Expand All @@ -70,7 +70,7 @@ describe("DOM change", () => {

it("detects an enter press", async () => {
let enterPressed = false;
const view = tempEditor({
const { view } = tempEditor({
doc: doc(blockquote(p("foo"), p("<a>"))),
handleKeyDown: (_, event) => {
if (event.key === "Enter") return (enterPressed = true);
Expand All @@ -89,7 +89,7 @@ describe("DOM change", () => {
it("detects a simple backspace press", async () => {
let backspacePressed = false;

const view = tempEditor({
const { view } = tempEditor({
doc: doc(blockquote(p("foo"), p("<a>"))),
handleKeyDown: (_, event) => {
if (event.key === "Backspace") return (backspacePressed = true);
Expand All @@ -107,7 +107,7 @@ describe("DOM change", () => {

it("correctly adjusts the selection", async () => {
const user = userEvent.setup();
const view = tempEditor({ doc: doc(p("abc<a>")) });
const { view } = tempEditor({ doc: doc(p("abc<a>")) });
await act(async () => {
await user.type(view.dom, "d");
});
Expand All @@ -130,7 +130,7 @@ describe("DOM change", () => {
// This test instead ensures that we only modify the character data,
// rather than replacing entire nodes.
it("does not replace a text node when it's typed into", async () => {
const view = tempEditor({
const { view } = tempEditor({
doc: doc(p("fo<a>o")),
});

Expand All @@ -154,7 +154,7 @@ describe("DOM change", () => {

it("understands text typed into an empty paragraph", async () => {
const user = userEvent.setup();
const view = tempEditor({ doc: doc(p("<a>")) });
const { view } = tempEditor({ doc: doc(p("<a>")) });
await act(async () => {
await user.type(view.dom, "i");
});
Expand All @@ -163,7 +163,7 @@ describe("DOM change", () => {
});

it("fixes text changes when input is ignored", async () => {
const view = tempEditor({
const { view } = tempEditor({
doc: doc(p("foo<a>")),
dispatchTransaction: () => undefined,
});
Expand All @@ -175,7 +175,7 @@ describe("DOM change", () => {
});

it("aborts when an incompatible state is set", async () => {
const view = tempEditor({ doc: doc(p("<a>abcde")) });
const { view } = tempEditor({ doc: doc(p("<a>abcde")) });

const user = userEvent.setup();
await act(async () => {
Expand All @@ -189,7 +189,7 @@ describe("DOM change", () => {

// TODO: Investigate why this fails!
it.skip("preserves marks on deletion", async () => {

Check warning on line 191 in src/components/__tests__/EditorView.domchange.test.tsx

View workflow job for this annotation

GitHub Actions / check

Disabled test
const view = tempEditor({ doc: doc(p("one", em("x<a>"))) });
const { view } = tempEditor({ doc: doc(p("one", em("x<a>"))) });

const user = userEvent.setup();

Expand All @@ -203,7 +203,7 @@ describe("DOM change", () => {
});

it("works when a node's contentDOM is deleted", async () => {
const view = tempEditor({ doc: doc(p("one"), pre("two<a>")) });
const { view } = tempEditor({ doc: doc(p("one"), pre("two<a>")) });
const user = userEvent.setup();
await act(async () => {
await user.type(view.dom, "[Backspace>3/]");
Expand All @@ -216,7 +216,7 @@ describe("DOM change", () => {
// TODO: Do we want to fix this? This is happening because we
// use the node position as the React key,
it.skip("doesn't redraw content with marks when typing in front", async () => {

Check warning on line 218 in src/components/__tests__/EditorView.domchange.test.tsx

View workflow job for this annotation

GitHub Actions / check

Disabled test
const view = tempEditor({
const { view } = tempEditor({
doc: doc(p("f<a>oo", em("bar"), strong("baz"))),
});
const bar = await screen.findByText("bar");
Expand All @@ -235,7 +235,7 @@ describe("DOM change", () => {
});

it("doesn't redraw content with marks when typing inside mark", async () => {
const view = tempEditor({
const { view } = tempEditor({
doc: doc(p("foo", em("b<a>ar"), strong("baz"))),
});
const bar = await screen.findByText("bar");
Expand All @@ -254,7 +254,7 @@ describe("DOM change", () => {
});

it("maps input to coordsAtPos through pending changes", () => {
const view = tempEditor({ doc: doc(p("foo")) });
const { view } = tempEditor({ doc: doc(p("foo")) });
act(() => {
view.dispatchEvent({ type: "input" } as Event);
view.dispatch(view.state.tr.insertText("more text"));
Expand All @@ -263,7 +263,7 @@ describe("DOM change", () => {
});

it("notices text added to a cursor wrapper at the start of a mark", async () => {
const view = tempEditor({ doc: doc(p(strong(a("foo<a>"), "bar"))) });
const { view } = tempEditor({ doc: doc(p(strong(a("foo<a>"), "bar"))) });
const user = userEvent.setup();
await act(async () => {
await user.type(view.dom, "xy");
Expand All @@ -273,7 +273,7 @@ describe("DOM change", () => {
});

it("removes cursor wrapper text when the wrapper otherwise remains valid", async () => {
const view = tempEditor({ doc: doc(p(a(strong("foo<a>"), "bar"))) });
const { view } = tempEditor({ doc: doc(p(a(strong("foo<a>"), "bar"))) });
const user = userEvent.setup();
await act(async () => {
await user.type(view.dom, "q");
Expand All @@ -285,7 +285,7 @@ describe("DOM change", () => {

it("creates a correct step for an ambiguous selection-deletion", async () => {
let steps: Step[];
const view = tempEditor({
const { view } = tempEditor({
doc: doc(p("la<a>la<b>la")),
dispatchTransaction(tr) {
steps = tr.steps;
Expand All @@ -307,7 +307,7 @@ describe("DOM change", () => {

it("creates a step that covers the entire selection for partially-matching replacement", async () => {
let steps: Step[];
const view = tempEditor({
const { view } = tempEditor({
doc: doc(p("one <a>two<b> three")),
dispatchTransaction(tr) {
steps = tr.steps;
Expand Down
Loading

0 comments on commit b49b5fa

Please sign in to comment.