-
Notifications
You must be signed in to change notification settings - Fork 17
Add tests #235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
trevor-e
wants to merge
9
commits into
main
Choose a base branch
from
telkins/add-tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add tests #235
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c835695
Add tests
trevor-e 5687cc5
fix
trevor-e ba24ecf
progress
trevor-e f7db7d0
cleanup
trevor-e ceab84f
more
trevor-e 24c99b6
Update modifier view
trevor-e d9b3646
revert breaking change
trevor-e ca97b6c
woops
trevor-e c364ff1
revert
trevor-e File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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 @@ | ||
| // | ||
| // ModifierFinder.swift | ||
| // | ||
| // | ||
| // Created by Noah Martin on 7/8/24. | ||
| // | ||
|
|
||
| import Foundation | ||
| import SnapshotSharedModels | ||
| import SwiftUI | ||
|
|
||
| public struct EmergeModifierView: View { | ||
|
|
||
| private static let modifierFinderClass = | ||
| (NSClassFromString("EmergeModifierFinder") as? NSObject.Type)?.init() | ||
| private static let finder = | ||
| modifierFinderClass != nil | ||
| ? Mirror(reflecting: modifierFinderClass!).descendant("finder") | ||
| as? (any View) -> any View : nil | ||
| private static let modifierState = | ||
| NSClassFromString("EmergeModifierState") as? NSObject.Type | ||
| private static let stateMirror = | ||
| modifierState != nil | ||
| ? Mirror( | ||
| reflecting: modifierState! | ||
| .perform(NSSelectorFromString("shared")) | ||
| .takeUnretainedValue() | ||
| ) : nil | ||
|
|
||
| private let internalView: AnyView | ||
|
|
||
| init(wrapped: some View) { | ||
| let rootView = Self.finder?(wrapped) | ||
| internalView = rootView != nil ? AnyView(rootView!) : AnyView(wrapped) | ||
| } | ||
|
|
||
| public var body: some View { | ||
| internalView | ||
| } | ||
|
|
||
| var emergeRenderingMode: EmergeRenderingMode? { | ||
| let renderingMode = | ||
| Self.stateMirror?.descendant("renderingMode") | ||
| as? EmergeRenderingMode.RawValue | ||
| return renderingMode != nil | ||
| ? EmergeRenderingMode(rawValue: renderingMode!) : nil | ||
| } | ||
|
|
||
| var accessibilityEnabled: Bool? { | ||
| Self.stateMirror?.descendant("accessibilityEnabled") as? Bool | ||
| } | ||
|
|
||
| var appStoreSnapshot: Bool? { | ||
| Self.stateMirror?.descendant("appStoreSnapshot") as? Bool | ||
| } | ||
|
|
||
| var precision: Float? { | ||
| Self.stateMirror?.descendant("precision") as? Float | ||
| } | ||
|
|
||
| var supportsExpansion: Bool { | ||
| Self.stateMirror?.descendant("expansionPreference") as? Bool ?? true | ||
| } | ||
| } |
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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,17 @@ | ||
| import XCTest | ||
|
|
||
| @testable import SnapshotPreviewsCore | ||
|
|
||
| final class ConformanceLookupTests: XCTestCase { | ||
| func test_getPreviewTypes() throws { | ||
| let types = getPreviewTypes() | ||
| XCTAssertEqual(types.count, 1) | ||
|
|
||
| let firstType = types.first! | ||
| XCTAssertEqual( | ||
| "SnapshotPreviewsTests.$s21SnapshotPreviewsTests0019TestViewswift_DJEEdfMX15_0_33_B5E96601318DE1EC85533DD88EB53190Ll7PreviewfMf_15PreviewRegistryfMu_", | ||
| firstType.name | ||
| ) | ||
| XCTAssertEqual("PreviewRegistry", firstType.proto) | ||
| } | ||
| } |
This file was deleted.
Oops, something went wrong.
72 changes: 72 additions & 0 deletions
72
Tests/SnapshotPreviewsTests/EmergeModifierStateTests.swift
This file contains hidden or 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,72 @@ | ||
| // | ||
| // EmergeModifierViewTests.swift | ||
| // SnapshotPreviews | ||
| // | ||
| // Created by Trevor Elkins on 4/30/25. | ||
| // | ||
|
|
||
| import SwiftUI | ||
| import XCTest | ||
|
|
||
| @testable import SnapshotPreferences | ||
| @testable import SnapshotSharedModels | ||
| @testable import SnapshotPreviewsCore | ||
|
|
||
| final class EmergeModifierStateTests: XCTestCase { | ||
|
|
||
| override func setUp() { | ||
| super.setUp() | ||
| EmergeModifierState.shared.reset() | ||
| } | ||
|
|
||
| func test_storesRenderingMode() { | ||
| let view = makeBaseText().emergeRenderingMode(.uiView) | ||
| let state = state(for: view) | ||
| XCTAssertEqual(state.renderingMode, EmergeRenderingMode.uiView.rawValue) | ||
| } | ||
|
|
||
| func test_storesPrecision() throws { | ||
| let view = makeBaseText().emergeSnapshotPrecision(0.95) | ||
| let state = state(for: view) | ||
| let precision = try XCTUnwrap(state.precision) | ||
| XCTAssertEqual(precision, 0.95, accuracy: .ulpOfOne) | ||
| } | ||
|
|
||
| func test_storesExpansionPreference() { | ||
| let view = makeBaseText().emergeExpansion(false) | ||
| let state = state(for: view) | ||
| XCTAssertEqual(state.expansionPreference, false) | ||
| } | ||
|
|
||
| func test_storesAccessibilityFlag() { | ||
| let view = makeBaseText().emergeAccessibility(true) | ||
| let state = state(for: view) | ||
| XCTAssertEqual(state.accessibilityEnabled, true) | ||
| } | ||
|
|
||
| func test_storesAppStoreSnapshotFlag() { | ||
| let view = makeBaseText().emergeAppStoreSnapshot(true) | ||
| let state = state(for: view) | ||
| XCTAssertEqual(state.appStoreSnapshot, true) | ||
| } | ||
|
|
||
| private func makeBaseText() -> Text { Text("Hello") } | ||
|
|
||
| private func state( | ||
| for view: some View, | ||
| file: StaticString = #file, | ||
| line: UInt = #line | ||
| ) -> EmergeModifierState { | ||
| let wrapped = EmergeModifierView(wrapped: view) | ||
| let hosting = UIHostingController(rootView: wrapped) | ||
|
|
||
| let window = UIWindow(frame: UIScreen.main.bounds) | ||
| window.rootViewController = hosting | ||
| window.makeKeyAndVisible() | ||
|
|
||
| // Give SwiftUI one tick to propagate preferences | ||
| RunLoop.main.run(until: Date(timeIntervalSinceNow: 0.01)) | ||
|
|
||
| return EmergeModifierState.shared | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I reformatted this file via swiftlint (can revert if you want) and added some dependencies for our
testTarget.