Skip to content

Commit

Permalink
Merge pull request #41 from ZhgChgLi/fix/ui-testing-for-iphone15
Browse files Browse the repository at this point in the history
[Chore] update uitesting env
  • Loading branch information
zhgchgli0718 authored Nov 24, 2023
2 parents b780865 + 55bfa99 commit 3bdb960
Show file tree
Hide file tree
Showing 17 changed files with 41 additions and 97 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:

jobs:
build:
runs-on: macos-12
runs-on: macos-13
steps:
- uses: actions/checkout@v3
- name: macOS build and test
Expand All @@ -20,7 +20,7 @@ jobs:
- name: iOS build and test
run: |
set -o pipefail
xcodebuild test -workspace ZMarkupParser.xcworkspace -testPlan ZMarkupParser -scheme ZMarkupParser -enableCodeCoverage YES -resultBundlePath './scripts/TestResult.xcresult' -destination 'platform=iOS Simulator,name=iPhone 14,OS=16.2' build test | xcpretty
xcodebuild test -workspace ZMarkupParser.xcworkspace -testPlan ZMarkupParser -scheme ZMarkupParser -enableCodeCoverage YES -resultBundlePath './scripts/TestResult.xcresult' -destination 'platform=iOS Simulator,name=iPhone 15,OS=17.0.1' build test | xcpretty
- name: Codecov
uses: codecov/[email protected]
with:
Expand Down
3 changes: 3 additions & 0 deletions .swiftpm/xcode/xcshareddata/xcschemes/ZMarkupParser.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@
<TestPlanReference
reference = "container:UnitTest.xctestplan">
</TestPlanReference>
<TestPlanReference
reference = "container:FullTest.xctestplan">
</TestPlanReference>
</TestPlans>
<Testables>
<TestableReference
Expand Down
31 changes: 31 additions & 0 deletions FullTest.xctestplan
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"configurations" : [
{
"id" : "007ED148-E1D2-46CA-9325-F6B6669440FC",
"name" : "Configuration 1",
"options" : {

}
}
],
"defaultOptions" : {
"testTimeoutsEnabled" : true
},
"testTargets" : [
{
"target" : {
"containerPath" : "container:",
"identifier" : "ZMarkupParserSnapshotTests",
"name" : "ZMarkupParserSnapshotTests"
}
},
{
"target" : {
"containerPath" : "container:",
"identifier" : "ZMarkupParserTests",
"name" : "ZMarkupParserTests"
}
}
],
"version" : 1
}
4 changes: 2 additions & 2 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-snapshot-testing",
"state" : {
"revision" : "dc46eeb3928a75390651fac6c1ef7f93ad59a73b",
"version" : "1.11.1"
"revision" : "26ed3a2b4a2df47917ca9b790a57f91285b923fb",
"version" : "1.12.0"
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let package = Package(
.library(name: "ZMarkupParser", targets: ["ZMarkupParser"])
],
dependencies: [
.package(url: "https://github.com/pointfreeco/swift-snapshot-testing", from: "1.11.0"),
.package(url: "https://github.com/pointfreeco/swift-snapshot-testing", exact: "1.12.0"),
.package(url: "https://github.com/ZhgChgLi/ZNSTextAttachment", from: "1.1.6")
],
targets: [
Expand Down
94 changes: 2 additions & 92 deletions Tests/ZMarkupParserSnapshotTests/ZMarkupParserSnapshotTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -172,93 +172,6 @@ final class ZHTMLToNSAttributedStringSnapshotTests: XCTestCase {
}
self.waitForExpectations(timeout: 5, handler: nil)
}

#elseif canImport(AppKit)
private var testAsyncImageTextView: NSTextView?
private var testAsyncXCTestExpectation: XCTestExpectation?

func testAsyncImageNSAttributedString() {
let attributedString = NSMutableAttributedString(attributedString: attributedHTMLString)
attributedString.append(NSAttributedString(string: #"<br/><img src="https://user-images.githubusercontent.com/33706588/219608966-20e0c017-d05c-433a-9a52-091bc0cfd403.jpg"/>test"#))
let parser = makeSUT()
let textView = NSTextView()
textView.frame.size.width = 390
textView.frame.size.height = 1000
textView.backgroundColor = .white
textView.setHtmlString(attributedString, with: parser)

testAsyncImageTextView = textView

textView.textStorage?.enumerateAttribute(NSAttributedString.Key.attachment, in: NSMakeRange(0, textView.textStorage?.string.utf16.count ?? 0), options: []) { (value, effectiveRange, nil) in
guard let attachment = value as? ZNSTextAttachment else {
return
}
if let textStorage = textView.textStorage {
attachment.register(textStorage)
}
attachment.startDownlaod()
}


testAsyncXCTestExpectation = self.expectation(description: "testAsyncImageNSAttributedString")
self.waitForExpectations(timeout: 5, handler: nil)
}

func testNSTextViewSetHTMLString() {
let parser = makeSUT()

let textView = NSTextView()
textView.frame.size.width = 390
textView.frame.size.height = 500
textView.backgroundColor = .white
textView.setHtmlString(attributedHTMLString, with: parser)
textView.layout()
assertSnapshot(matching: textView, as: .image, record: self.record)
}

func testNSTextViewSetHTMLStringAsync() {
let parser = makeSUT()
let textView = NSTextView()
textView.frame.size.width = 390
textView.frame.size.height = 500
textView.backgroundColor = .white
let expectation = self.expectation(description: "testNSTextViewSetHTMLStringAsync")
textView.setHtmlString(attributedHTMLString, with: parser) { _ in
textView.layout()
assertSnapshot(matching: textView, as: .image, record: self.record)
expectation.fulfill()
}
self.waitForExpectations(timeout: 5, handler: nil)
}

func testNSTextFieldSetHTMLString() {
let parser = makeSUT()

let textField = NSTextField()
textField.frame.size.width = 390
textField.frame.size.height = 500
textField.backgroundColor = .white
textField.textColor = .black
textField.setHtmlString(attributedHTMLString, with: parser)
textField.layout()
assertSnapshot(matching: textField, as: .image, record: self.record)
}

func testNSTextFieldSetHTMLStringAsync() {
let parser = makeSUT()
let textField = NSTextField()
textField.frame.size.width = 390
textField.frame.size.height = 500
textField.backgroundColor = .white
textField.textColor = .black
let expectation = self.expectation(description: "testNSTextFieldSetHTMLStringAsync")
textField.setHtmlString(attributedHTMLString, with: parser) { _ in
textField.layout()
assertSnapshot(matching: textField, as: .image, record: self.record)
expectation.fulfill()
}
self.waitForExpectations(timeout: 5, handler: nil)
}
#endif
}

Expand All @@ -281,16 +194,13 @@ extension ZHTMLToNSAttributedStringSnapshotTests {

extension ZHTMLToNSAttributedStringSnapshotTests: ZNSTextAttachmentDelegate, ZNSTextAttachmentDataSource {
func zNSTextAttachment(didLoad textAttachment: ZNSTextAttachment, to: ZResizableNSTextAttachment) {
#if canImport(UIKit)
if let textView = testAsyncImageTextView {
#if canImport(UIKit)
textView.layoutIfNeeded()
assertSnapshot(matching: textView, as: .image, record: self.record, testName: "testAsyncImageNSAttributedString_uiTextView")
#elseif canImport(AppKit)
textView.layout()
assertSnapshot(matching: textView, as: .image, record: self.record, testName: "testAsyncImageNSAttributedString_nsTextView")
#endif
}
testAsyncXCTestExpectation?.fulfill()
#endif
}

func zNSTextAttachment(_ textAttachment: ZNSTextAttachment, loadImageURL imageURL: URL, completion: @escaping (Data) -> Void) {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 3bdb960

Please sign in to comment.