Skip to content

Commit

Permalink
Updated snapshotting library
Browse files Browse the repository at this point in the history
  • Loading branch information
rajdeep committed Nov 16, 2024
1 parent e5102ea commit 00dc4cb
Show file tree
Hide file tree
Showing 23 changed files with 357 additions and 346 deletions.
15 changes: 12 additions & 3 deletions Proton.xcworkspace/xcshareddata/swiftpm/Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,21 @@
"object": {
"pins": [
{
"package": "SnapshotTesting",
"package": "swift-snapshot-testing",
"repositoryURL": "https://github.com/pointfreeco/swift-snapshot-testing.git",
"state": {
"branch": null,
"revision": "114882386a815f4a2e6d8f2f7ee4857acd372438",
"version": "1.7.2"
"revision": "42a086182681cf661f5c47c9b7dc3931de18c6d7",
"version": "1.17.6"
}
},
{
"package": "swift-syntax",
"repositoryURL": "https://github.com/swiftlang/swift-syntax",
"state": {
"branch": null,
"revision": "0687f71944021d616d34d922343dcef086855920",
"version": "600.0.1"
}
}
]
Expand Down
2 changes: 1 addition & 1 deletion Proton/Sources/Swift/Editor/EditorView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1113,7 +1113,7 @@ open class EditorView: UIView {
if let range {
selectedRange = range
}
richTextView.becomeFirstResponder()
_ = richTextView.becomeFirstResponder()
}

/// Makes the `EditorView` lose focus.
Expand Down
8 changes: 8 additions & 0 deletions Proton/Sources/Swift/Grid/View/GridContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,14 @@ class GridContentView: UIScrollView {
}

public override func willMove(toWindow newWindow: UIWindow?) {
defer {
for cell in grid.cells {
if !cell.editorSetupComplete {
cell.setupEditor()
}
}
}

guard isRendered == false,
newWindow != nil else {
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ class AsyncTextResolverSnapshotTests: SnapshotTestCase {
editor.attributedText = text

viewController.render(size: CGSize(width: 300, height: 170))
assertSnapshot(matching: viewController.view, as: .image, record: recordMode)
assertSnapshot(of: viewController.view, as: .image, record: recordMode)

DispatchQueue.main.asyncAfter(deadline: .now() + 0.7) {
viewController.render(size: CGSize(width: 300, height: 170))
assertSnapshot(matching: viewController.view, as: Snapshotting.image, record: self.recordMode)
assertSnapshot(of: viewController.view, as: Snapshotting.image, record: self.recordMode)
expectation.fulfill()
}

Expand All @@ -64,11 +64,11 @@ class AsyncTextResolverSnapshotTests: SnapshotTestCase {
editor.attributedText = text

viewController.render(size: CGSize(width: 300, height: 170))
assertSnapshot(matching: viewController.view, as: .image, record: recordMode)
assertSnapshot(of: viewController.view, as: .image, record: recordMode)

DispatchQueue.main.asyncAfter(deadline: .now() + 0.7) {
viewController.render(size: CGSize(width: 300, height: 170))
assertSnapshot(matching: viewController.view, as: Snapshotting.image, record: self.recordMode)
assertSnapshot(of: viewController.view, as: Snapshotting.image, record: self.recordMode)
expectation.fulfill()
}

Expand All @@ -91,11 +91,11 @@ class AsyncTextResolverSnapshotTests: SnapshotTestCase {
editor.replaceCharacters(in: NSRange(location: 65, length: 0), with: NSAttributedString(string: " "))

viewController.render(size: CGSize(width: 300, height: 170))
assertSnapshot(matching: viewController.view, as: .image, record: recordMode)
assertSnapshot(of: viewController.view, as: .image, record: recordMode)

DispatchQueue.main.asyncAfter(deadline: .now() + 0.7) {
viewController.render(size: CGSize(width: 300, height: 170))
assertSnapshot(matching: viewController.view, as: Snapshotting.image, record: self.recordMode)
assertSnapshot(of: viewController.view, as: Snapshotting.image, record: self.recordMode)

let attributeRange = viewController.editor.attributedText.rangeOf(attribute: .asyncTextResolver, startingLocation: 0)
XCTAssertNil(attributeRange)
Expand Down
20 changes: 10 additions & 10 deletions Proton/Tests/Attachments/AttachmentUpdateSnapshotTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class AttachmentUpdateSnapshotTests: SnapshotTestCase {
textView.replaceCharacters(in: textView.textEndRange, with: "Text after attachment")

viewController.render()
assertSnapshot(matching: viewController.view, as: .image, record: recordMode)
assertSnapshot(of: viewController.view, as: .image, record: recordMode)
}

func testRendersImageBasedBlockAttachment() {
Expand All @@ -51,7 +51,7 @@ class AttachmentUpdateSnapshotTests: SnapshotTestCase {
textView.replaceCharacters(in: textView.textEndRange, with: "Text after attachment")

viewController.render()
assertSnapshot(matching: viewController.view, as: .image, record: recordMode)
assertSnapshot(of: viewController.view, as: .image, record: recordMode)
}

func testRendersUpdatedImageInAttachment() {
Expand All @@ -65,10 +65,10 @@ class AttachmentUpdateSnapshotTests: SnapshotTestCase {
textView.replaceCharacters(in: textView.textEndRange, with: "Text after attachment")

viewController.render()
assertSnapshot(matching: viewController.view, as: .image, record: recordMode)
assertSnapshot(of: viewController.view, as: .image, record: recordMode)
attachment.update(with: AttachmentImage(name: EditorContent.Name("image"), image: UIImage(systemName: "car")!, size: CGSize(width: 40, height: 80), type: .block))
viewController.render(size: CGSize(width: 300, height: 150))
assertSnapshot(matching: viewController.view, as: .image, record: recordMode)
assertSnapshot(of: viewController.view, as: .image, record: recordMode)
}

func testRendersUpdatedViewInAttachment() {
Expand All @@ -93,10 +93,10 @@ class AttachmentUpdateSnapshotTests: SnapshotTestCase {
textView.replaceCharacters(in: textView.textEndRange, with: "Text after attachment")

viewController.render()
assertSnapshot(matching: viewController.view, as: .image, record: recordMode)
assertSnapshot(of: viewController, as: .image, record: recordMode)
attachment.update(panel, size: .fullWidth)
viewController.render(size: CGSize(width: 300, height: 150))
assertSnapshot(matching: viewController.view, as: .image, record: recordMode)
assertSnapshot(of: viewController, as: .image, record: recordMode)
}

func testRendersUpdatedViewInImageAttachment() {
Expand All @@ -118,11 +118,11 @@ class AttachmentUpdateSnapshotTests: SnapshotTestCase {
textView.replaceCharacters(in: textView.textEndRange, with: "Text after attachment")

viewController.render()
assertSnapshot(matching: viewController.view, as: .image, record: recordMode)
assertSnapshot(of: viewController.view, as: .image, record: recordMode)

attachment.update(panel, size: .fullWidth)
viewController.render(size: CGSize(width: 300, height: 150))
assertSnapshot(matching: viewController.view, as: .image, record: recordMode)
assertSnapshot(of: viewController.view, as: .image, record: recordMode)
}


Expand All @@ -142,10 +142,10 @@ class AttachmentUpdateSnapshotTests: SnapshotTestCase {
textView.replaceCharacters(in: textView.textEndRange, with: "Text after attachment")

viewController.render()
assertSnapshot(matching: viewController.view, as: .image, record: recordMode)
assertSnapshot(of: viewController.view, as: .image, record: recordMode)

attachment.update(with: AttachmentImage(name: EditorContent.Name("image"), image: UIImage(systemName: "car.2.fill")!, size: CGSize(width: 80, height: 40), type: .block))
viewController.render(size: CGSize(width: 300, height: 125))
assertSnapshot(matching: viewController.view, as: .image, record: recordMode)
assertSnapshot(of: viewController.view, as: .image, record: recordMode)
}
}
6 changes: 0 additions & 6 deletions Proton/Tests/Attachments/GridViewAttachment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,3 @@ extension GridView: AttachmentViewIdentifying {

public var type: AttachmentType { .block }
}

extension GridView: BackgroundColorObserving {
public func containerEditor(_ editor: EditorView, backgroundColorUpdated color: UIColor?, oldColor: UIColor?) {
backgroundColor = color
}
}
20 changes: 10 additions & 10 deletions Proton/Tests/Attachments/ViewAttachmentSnapshotTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ViewAttachmentSnapshotTests: SnapshotTestCase {
textView.insertAttachment(in: textView.textEndRange, attachment: attachment)

viewController.render()
assertSnapshot(matching: viewController.view, as: .image, record: recordMode)
assertSnapshot(of: viewController.view, as: .image, record: recordMode)
}

func testFallsToNextLineForLongContent() {
Expand All @@ -56,7 +56,7 @@ class ViewAttachmentSnapshotTests: SnapshotTestCase {
textView.replaceCharacters(in: textView.textEndRange, with: NSAttributedString(string: "after."))

viewController.render()
assertSnapshot(matching: viewController.view, as: .image, record: recordMode)
assertSnapshot(of: viewController.view, as: .image, record: recordMode)
}

func testMatchContainerRendering() {
Expand All @@ -69,7 +69,7 @@ class ViewAttachmentSnapshotTests: SnapshotTestCase {
textView.insertAttachment(in: textView.textEndRange, attachment: attachment)

viewController.render()
assertSnapshot(matching: viewController.view, as: .image, record: recordMode)
assertSnapshot(of: viewController.view, as: .image, record: recordMode)
}

func testFixedWidthRendering() {
Expand All @@ -83,7 +83,7 @@ class ViewAttachmentSnapshotTests: SnapshotTestCase {
textView.replaceCharacters(in: textView.textEndRange, with: "and some more text after it.")

viewController.render(size: CGSize(width: 300, height: 120))
assertSnapshot(matching: viewController.view, as: .image, record: recordMode)
assertSnapshot(of: viewController.view, as: .image, record: recordMode)
}

func testPercentBasedRendering() {
Expand All @@ -98,7 +98,7 @@ class ViewAttachmentSnapshotTests: SnapshotTestCase {
textView.insertAttachment(in: textView.textEndRange, attachment: attachment)

viewController.render(size: CGSize(width: 300, height: 120))
assertSnapshot(matching: viewController.view, as: .image, record: recordMode)
assertSnapshot(of: viewController.view, as: .image, record: recordMode)
}

func testWidthRangeRendering() {
Expand All @@ -114,7 +114,7 @@ class ViewAttachmentSnapshotTests: SnapshotTestCase {
textView.insertAttachment(in: textView.textEndRange, attachment: attachment2)

viewController.render(size: CGSize(width: 300, height: 120))
assertSnapshot(matching: viewController.view, as: .image, record: recordMode)
assertSnapshot(of: viewController.view, as: .image, record: recordMode)
}

func testSetsSelectionWithDisplay() {
Expand All @@ -134,7 +134,7 @@ class ViewAttachmentSnapshotTests: SnapshotTestCase {
XCTAssertNotNil(attachment1.rangeInContainer())
XCTAssertTrue(attachment1.isSelected)
XCTAssertEqual(attachment1.containerEditorView?.selectedRange, attachment1.rangeInContainer())
assertSnapshot(matching: viewController.view, as: .image, record: recordMode)
assertSnapshot(of: viewController.view, as: .image, record: recordMode)
}

func testSetsSelectionWithoutDisplay() {
Expand All @@ -154,7 +154,7 @@ class ViewAttachmentSnapshotTests: SnapshotTestCase {
XCTAssertNotNil(attachment1.rangeInContainer())
XCTAssertTrue(attachment1.isSelected)
XCTAssertEqual(attachment1.containerEditorView?.selectedRange, attachment1.rangeInContainer())
assertSnapshot(matching: viewController.view, as: .image, record: recordMode)
assertSnapshot(of: viewController.view, as: .image, record: recordMode)
}

func testGetsFocussedChildView() {
Expand All @@ -179,7 +179,7 @@ class ViewAttachmentSnapshotTests: SnapshotTestCase {

XCTAssertTrue(attachment1.firstResponderChildView is AutogrowingTextField)

assertSnapshot(matching: viewController.view, as: .image, record: recordMode)
assertSnapshot(of: viewController.view, as: .image, record: recordMode)
}

func testReturnsNilForNonFocussedChildView() {
Expand All @@ -206,7 +206,7 @@ class ViewAttachmentSnapshotTests: SnapshotTestCase {
XCTAssertFalse(attachment1.isFocussed)
XCTAssertNil(attachment1.firstResponderChildView)

assertSnapshot(matching: viewController.view, as: .image, record: recordMode)
assertSnapshot(of: viewController.view, as: .image, record: recordMode)
}

private func makeDummyAttachment(text: String, size: AttachmentSize) -> Attachment {
Expand Down
4 changes: 2 additions & 2 deletions Proton/Tests/Base/AutogrowingTextViewSnapshotTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class AutogrowingTextViewSnapshotTests: SnapshotTestCase {

viewController.render()

assertSnapshot(matching: view, as: .image, record: recordMode)
assertSnapshot(of: view, as: .image, record: recordMode)
}

func testRendersMultilineTextViewBasedOnContent() {
Expand All @@ -61,6 +61,6 @@ class AutogrowingTextViewSnapshotTests: SnapshotTestCase {

viewController.render()

assertSnapshot(matching: view, as: .image, record: recordMode)
assertSnapshot(of: view, as: .image, record: recordMode)
}
}
4 changes: 2 additions & 2 deletions Proton/Tests/Core/ListParserTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,8 @@ class ListParserTests: XCTestCase {
text.append(NSAttributedString(string: "\n"))
text.append( line3)

let list = ListParser.parse(attributedString: text)
let listNodes = ListParser.parseListHierarchy(attributedString: text)
// let list = ListParser.parse(attributedString: text)
// let listNodes = ListParser.parseListHierarchy(attributedString: text)
XCTFail()
}

Expand Down
8 changes: 4 additions & 4 deletions Proton/Tests/Core/ListsSnapshotTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class ListsSnapshotTests: SnapshotTestCase {
let attributedText = NSAttributedString(string: text, attributes: [.listItem: 1, .paragraphStyle: paraStyle])
let view = renderList(text: attributedText, viewSize: CGSize(width: 300, height: 150))

assertSnapshot(matching: view, as: .image, record: recordMode)
assertSnapshot(of: view, as: .image, record: recordMode)
}

func testMultiLevelList() {
Expand All @@ -59,7 +59,7 @@ class ListsSnapshotTests: SnapshotTestCase {
attributedString.addAttribute(.listItem, value: 1, range: attributedString.fullRange)

let view = renderList(text: attributedString, viewSize: CGSize(width: 300, height: 175), sequenceGenerators: sequenceGenerators)
assertSnapshot(matching: view, as: .image, record: recordMode)
assertSnapshot(of: view, as: .image, record: recordMode)
}

func testSequenceGeneratorsRepetition() {
Expand All @@ -82,7 +82,7 @@ class ListsSnapshotTests: SnapshotTestCase {
let attributedText = attributedString
let view = renderList(text: attributedText, viewSize: CGSize(width: 225, height: 325), sequenceGenerators: sequenceGenerators)

assertSnapshot(matching: view, as: .image, record: recordMode)
assertSnapshot(of: view, as: .image, record: recordMode)
}

func testMultiLevelRepeatingText() {
Expand All @@ -105,7 +105,7 @@ class ListsSnapshotTests: SnapshotTestCase {
let attributedText = attributedString
let view = renderList(text: attributedText, viewSize: CGSize(width: 225, height: 325), sequenceGenerators: sequenceGenerators)

assertSnapshot(matching: view, as: .image, record: recordMode)
assertSnapshot(of: view, as: .image, record: recordMode)
}

func renderList(text: NSAttributedString, viewSize: CGSize, sequenceGenerators: [SequenceGenerator] = []) -> UIView {
Expand Down
12 changes: 6 additions & 6 deletions Proton/Tests/Core/RichTextViewSnapshotTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class RichTextViewSnapshotTests: SnapshotTestCase {

viewController.render()

assertSnapshot(matching: view, as: .image, record: recordMode)
assertSnapshot(of: view, as: .image, record: recordMode)
}

func testRendersPlaceholderInTextView() {
Expand All @@ -62,19 +62,19 @@ class RichTextViewSnapshotTests: SnapshotTestCase {

textView.attributedText = NSAttributedString(string: "A")
viewController.render()
assertSnapshot(matching: view, as: .image, record: recordMode)
assertSnapshot(of: view, as: .image, record: recordMode)

textView.deleteBackward()
viewController.render()
assertSnapshot(matching: view, as: .image, record: recordMode)
assertSnapshot(of: view, as: .image, record: recordMode)

textView.attributedText = NSAttributedString(string: "B")
viewController.render()
assertSnapshot(matching: view, as: .image, record: recordMode)
assertSnapshot(of: view, as: .image, record: recordMode)

textView.attributedText = NSAttributedString();
viewController.render()
assertSnapshot(matching: view, as: .image, record: recordMode)
assertSnapshot(of: view, as: .image, record: recordMode)
}

func testRendersMultilineTextViewBasedOnContent() {
Expand Down Expand Up @@ -107,6 +107,6 @@ class RichTextViewSnapshotTests: SnapshotTestCase {

viewController.render(size: CGSize(width: 300, height: 150))

assertSnapshot(matching: view, as: .image, record: recordMode)
assertSnapshot(of: view, as: .image, record: recordMode)
}
}
Loading

0 comments on commit 00dc4cb

Please sign in to comment.