damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

commit 7bed47c919f545794d93198891b78a4995e59e27
parent 7a6a6dffbce69bcd233c593dbb5578d46fbd276b
Author: Daniel D’Aquino <daniel@daquino.me>
Date:   Sat,  7 Oct 2023 01:21:53 +0000

test: Setup Snapshot testing library and add a snapshot test (testTextWrapperViewWillWrapText)

This change adds `https://github.com/pointfreeco/swift-snapshot-testing` as a package dependency and links it to the `damusTests` target.
It also adds one snapshot test to demonstrate its usefulness, by adding coverage to one particular aspect that we have never been able to test before: Whether or not the post text editor will wrap the text once the text gets long.

Testing of the test
-------------------

PASS

iOS: 17.0
Device: Simulator
Damus: This commit
Test steps:

1. Run `testTextWrapperViewWillWrapText`. PASS
2. Change TextViewWrapper.swift and remove this line:
```
textView.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
```
3. Rerun. It fails. PASS (This is expected)

Closes: https://github.com/damus-io/damus/issues/1562
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
Signed-off-by: William Casarin <jb55@jb55.com>

Diffstat:
Mdamus.xcodeproj/project.pbxproj | 27+++++++++++++++++++++++++++
Mdamus.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved | 18++++++++++++++++++
MdamusTests/PostViewTests.swift | 25+++++++++++++++++++++++++
3 files changed, 70 insertions(+), 0 deletions(-)

diff --git a/damus.xcodeproj/project.pbxproj b/damus.xcodeproj/project.pbxproj @@ -435,6 +435,8 @@ D78525252A7B2EA4002FA637 /* NoteContentViewTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D78525242A7B2EA4002FA637 /* NoteContentViewTests.swift */; }; D7870BC12AC4750B0080BA88 /* MentionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7870BC02AC4750B0080BA88 /* MentionView.swift */; }; D7870BC32AC47EBC0080BA88 /* EventLoaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7870BC22AC47EBC0080BA88 /* EventLoaderView.swift */; }; + D7A343EE2AD0D77C00CED48B /* InlineSnapshotTesting in Frameworks */ = {isa = PBXBuildFile; productRef = D7A343ED2AD0D77C00CED48B /* InlineSnapshotTesting */; }; + D7A343F02AD0D77C00CED48B /* SnapshotTesting in Frameworks */ = {isa = PBXBuildFile; productRef = D7A343EF2AD0D77C00CED48B /* SnapshotTesting */; }; D7DEEF2F2A8C021E00E0C99F /* NostrEventTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7DEEF2E2A8C021E00E0C99F /* NostrEventTests.swift */; }; D7FF94002AC7AC5300FD969D /* RelayURL.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7FF93FF2AC7AC5200FD969D /* RelayURL.swift */; }; E4FA1C032A24BB7F00482697 /* SearchSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4FA1C022A24BB7F00482697 /* SearchSettingsView.swift */; }; @@ -1164,6 +1166,8 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + D7A343EE2AD0D77C00CED48B /* InlineSnapshotTesting in Frameworks */, + D7A343F02AD0D77C00CED48B /* SnapshotTesting in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -2382,6 +2386,10 @@ 4CE6DEF527F7A08200C66700 /* PBXTargetDependency */, ); name = damusTests; + packageProductDependencies = ( + D7A343ED2AD0D77C00CED48B /* InlineSnapshotTesting */, + D7A343EF2AD0D77C00CED48B /* SnapshotTesting */, + ); productName = damusTests; productReference = 4CE6DEF327F7A08200C66700 /* damusTests.xctest */; productType = "com.apple.product-type.bundle.unit-test"; @@ -2470,6 +2478,7 @@ 4C06670228FC7EC500038D2A /* XCRemoteSwiftPackageReference "Kingfisher" */, 4CCF9AB02A1FE80B00E03CFB /* XCRemoteSwiftPackageReference "GSPlayer" */, 4C27C9302A64766F007DBC75 /* XCRemoteSwiftPackageReference "swift-markdown-ui" */, + D7A343EC2AD0D77C00CED48B /* XCRemoteSwiftPackageReference "swift-snapshot-testing" */, ); productRefGroup = 4CE6DEE427F7A08100C66700 /* Products */; projectDirPath = ""; @@ -3490,6 +3499,14 @@ minimumVersion = 0.2.26; }; }; + D7A343EC2AD0D77C00CED48B /* XCRemoteSwiftPackageReference "swift-snapshot-testing" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/pointfreeco/swift-snapshot-testing"; + requirement = { + kind = upToNextMajorVersion; + minimumVersion = 1.14.1; + }; + }; /* End XCRemoteSwiftPackageReference section */ /* Begin XCSwiftPackageProductDependency section */ @@ -3508,6 +3525,16 @@ package = 4C64987F286E0EE300EAE2B3 /* XCRemoteSwiftPackageReference "secp256k1" */; productName = secp256k1; }; + D7A343ED2AD0D77C00CED48B /* InlineSnapshotTesting */ = { + isa = XCSwiftPackageProductDependency; + package = D7A343EC2AD0D77C00CED48B /* XCRemoteSwiftPackageReference "swift-snapshot-testing" */; + productName = InlineSnapshotTesting; + }; + D7A343EF2AD0D77C00CED48B /* SnapshotTesting */ = { + isa = XCSwiftPackageProductDependency; + package = D7A343EC2AD0D77C00CED48B /* XCRemoteSwiftPackageReference "swift-snapshot-testing" */; + productName = SnapshotTesting; + }; /* End XCSwiftPackageProductDependency section */ }; rootObject = 4CE6DEDB27F7A08100C66700 /* Project object */; diff --git a/damus.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/damus.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -33,6 +33,24 @@ "state" : { "revision" : "76bb7971da7fbf429de1c84f1244adf657242fee" } + }, + { + "identity" : "swift-snapshot-testing", + "kind" : "remoteSourceControl", + "location" : "https://github.com/pointfreeco/swift-snapshot-testing", + "state" : { + "revision" : "5b356adceabff6ca027f6574aac79e9fee145d26", + "version" : "1.14.1" + } + }, + { + "identity" : "swift-syntax", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-syntax.git", + "state" : { + "revision" : "74203046135342e4a4a627476dd6caf8b28fe11b", + "version" : "509.0.0" + } } ], "version" : 2 diff --git a/damusTests/PostViewTests.swift b/damusTests/PostViewTests.swift @@ -6,6 +6,8 @@ // import Foundation import XCTest +import SnapshotTesting +import SwiftUI @testable import damus import SwiftUI @@ -19,6 +21,29 @@ final class PostViewTests: XCTestCase { // Put teardown code here. This method is called after the invocation of each test method in the class. } + func testTextWrapperViewWillWrapText() { + // Setup test variables to be passed into the TextViewWrapper + let tagModel: TagModel = TagModel() + var textHeight: CGFloat? = nil + let textHeightBinding: Binding<CGFloat?> = Binding(get: { + return textHeight + }, set: { newValue in + textHeight = newValue + }) + + // Setup the test view + let textEditorView = TextViewWrapper( + attributedText: .constant(NSMutableAttributedString(string: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.")), + textHeight: textHeightBinding, + cursorIndex: 9, + updateCursorPosition: { _ in return } + ).environmentObject(tagModel) + let hostView = UIHostingController(rootView: textEditorView) + + // Run snapshot check + assertSnapshot(matching: hostView, as: .image(on: .iPhoneSe(.portrait))) + } + /// Based on https://github.com/damus-io/damus/issues/1375 /// Tests whether the editor properly handles mention links after they have been added, to avoid manual editing of attributed links func testMentionLinkEditorHandling() throws {