Files
ichmagmaus111andClaude Opus 5.5 0622057a4f Ghostgram: open-source release
Ghostgram for iOS, rebuilt from scratch on Telegram iOS 13.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 17:57:09 +01:00

53 lines
2.4 KiB
Swift
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#if canImport(UIKit)
import XCTest
import RichTextEditorCore
@testable import RichTextEditorUIKit
/// Regression guard for the shared `makeBox` factory (Task 3 of the block-quote rewrite).
/// Asserts that the document root and table cells build the same box TYPES as before the refactor.
final class MakeBoxTests: XCTestCase {
// MARK: - Root builds all box types
func test_root_buildsAllBoxTypes_unchanged() {
let canvas = DocumentCanvasView()
canvas.frame = CGRect(x: 0, y: 0, width: 320, height: 400)
canvas.setBlocks([
.paragraph(ParagraphBlock(id: BlockID("p"), runs: [TextRun(text: "a")])),
.code(CodeBlock(id: BlockID("c"), runs: [TextRun(text: "x")])),
.pullQuote(PullQuote(id: BlockID("pq"), runs: [TextRun(text: "q")])),
], width: 320)
XCTAssertTrue(canvas.boxes[0] is BlockBox, "paragraph → BlockBox")
XCTAssertTrue(canvas.boxes[1] is CodeBlockBox, "code → CodeBlockBox")
XCTAssertTrue(canvas.boxes[2] is PullQuoteBox, "pullQuote → PullQuoteBox")
}
// MARK: - Cell restriction preserved
func test_tableCell_stillRestrictsToParagraphAndMedia() {
// A 1×1 table whose single cell holds [paragraph, code].
// After the makeBox refactor the cell must still yield exactly ONE box (the paragraph)
// — the code block must be dropped by the restriction guard.
let cell = Cell(id: BlockID("cell"), blocks: [
.paragraph(ParagraphBlock(id: BlockID("para"), runs: [TextRun(text: "hello")])),
.code(CodeBlock(id: BlockID("code"), runs: [TextRun(text: "x")])),
])
let table = TableBlock(
id: BlockID("t"),
columns: [ColumnSpec(width: 200)],
rows: [Row(id: BlockID("r0"), cells: [cell])]
)
let canvas = DocumentCanvasView()
canvas.frame = CGRect(x: 0, y: 0, width: 320, height: 400)
canvas.setBlocks([.table(table)], width: 320)
canvas.layoutIfNeeded()
let tableBox = canvas.boxes.first as! TableBlockBox
let cellStack = tableBox.cells[0][0]
// The paragraph is built; the code block is dropped (restriction preserved).
XCTAssertEqual(cellStack.boxes.count, 1, "cell stack must have exactly 1 box (code block dropped)")
XCTAssertTrue(cellStack.boxes[0] is BlockBox, "the surviving box is the paragraph BlockBox")
}
}
#endif