-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: I forgot to include this file in D47215002 Reviewed By: thegreatercurve Differential Revision: D47226955 fbshipit-source-id: 5c123f200bf2f31db076c43b1bec43c5a9fa7680
1 parent
c8239c4
commit 352a128
Showing
1 changed file
with
64 additions
and
0 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
Plugins/LexicalInlineImagePlugin/LexicalInlineImagePluginTests/InlineImageTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
@testable import Lexical | ||
@testable import LexicalInlineImagePlugin | ||
import XCTest | ||
|
||
class InlineImageTests: XCTestCase { | ||
var view: LexicalView? | ||
var editor: Editor { | ||
get { | ||
guard let editor = view?.editor else { | ||
XCTFail("Editor unexpectedly nil") | ||
fatalError() | ||
} | ||
return editor | ||
} | ||
} | ||
|
||
override func setUp() { | ||
view = LexicalView(editorConfig: EditorConfig(theme: Theme(), plugins: [InlineImagePlugin()]), featureFlags: FeatureFlags()) | ||
} | ||
|
||
override func tearDown() { | ||
view = nil | ||
} | ||
|
||
func testNewParaAfterImage() throws { | ||
try editor.update { | ||
let imageNode = ImageNode(url: "https://example.com/image.png", size: CGSize(width: 300, height: 300), sourceID: "") | ||
let textNode1 = TextNode(text: "123") | ||
let textNode2 = TextNode(text: "456") | ||
if let selection = try getSelection() { | ||
_ = try selection.insertNodes(nodes: [textNode1, imageNode, textNode2], selectStart: false) | ||
} | ||
|
||
guard let root = getRoot() else { | ||
XCTFail() | ||
return | ||
} | ||
XCTAssertEqual(root.getChildrenSize(), 1, "Root should have 1 child (paragraph)") | ||
|
||
let newSelection = RangeSelection(anchor: Point(key: textNode2.getKey(), offset: 0, type: .text), focus: Point(key: textNode2.getKey(), offset: 0, type: .text), format: TextFormat()) | ||
try newSelection.insertParagraph() | ||
|
||
XCTAssertEqual(root.getChildrenSize(), 2, "Root should now have 2 paragraphs") | ||
|
||
let firstPara = root.getChildren()[0] as? ParagraphNode | ||
let secondPara = root.getChildren()[1] as? ParagraphNode | ||
|
||
guard let firstPara, let secondPara else { | ||
XCTFail() | ||
return | ||
} | ||
|
||
XCTAssertEqual(firstPara.getChildrenSize(), 2, "First para should contain 1 text node and 1 image node") | ||
XCTAssertEqual(secondPara.getChildrenSize(), 1, "Second para should contain 1 text node") | ||
} | ||
} | ||
} |