File size: 892 Bytes
b152fd5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { describe, expect, it } from "vitest";
import { restoreSubmittedCommentDraft } from "./comment-submit-draft";

describe("restoreSubmittedCommentDraft", () => {
  it("restores the submitted body when the editor is still empty after a failed request", () => {
    expect(
      restoreSubmittedCommentDraft({
        currentBody: "",
        submittedBody: "Retry me",
      }),
    ).toBe("Retry me");
  });

  it("treats whitespace-only input as empty when restoring a failed draft", () => {
    expect(
      restoreSubmittedCommentDraft({
        currentBody: "   ",
        submittedBody: "Retry me",
      }),
    ).toBe("Retry me");
  });

  it("preserves newer input when the user has already typed again", () => {
    expect(
      restoreSubmittedCommentDraft({
        currentBody: "new draft",
        submittedBody: "Retry me",
      }),
    ).toBe("new draft");
  });
});