Skip to content

Commit

Permalink
Added Unit Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyome22 committed Jan 13, 2025
1 parent 8e6c93d commit f463a51
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Tests/WebUITests/WeakReference.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
final class WeakReference<T> where T : AnyObject {
weak var value: T?

func bypass(_ value: T) -> T {
self.value = value
return value
}
}
28 changes: 28 additions & 0 deletions Tests/WebUITests/WebViewTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
import XCTest

final class WebViewTests: XCTestCase {
@MainActor
func test_configuration_is_weakly_referenced() {
var configuration = WebViewConfigurationMock?.some(.init())
let sut = WebView(configuration: configuration)
configuration = nil
XCTAssertNil(sut.configuration)
}

@MainActor
func test_applyModifiers_uiDelegate() {
let uiDelegateMock = UIDelegateMock()
Expand All @@ -11,6 +19,16 @@ final class WebViewTests: XCTestCase {
XCTAssertTrue(uiDelegateMock === webViewMock.uiDelegate)
}

@MainActor
func test_uiDelegate_is_weakly_referenced() {
let actual = WeakReference<UIDelegateMock>()
let sut = WebView().uiDelegate(actual.bypass(.init()))
var webViewMock = EnhancedWKWebViewMock?.some(.init())
sut.applyModifiers(to: webViewMock!)
webViewMock = nil
XCTAssertNil(actual.value)
}

@MainActor
func test_applyModifiers_navigationDelegate() {
let navigationDelegateMock = NavigationDelegateMock()
Expand All @@ -20,6 +38,16 @@ final class WebViewTests: XCTestCase {
XCTAssertTrue(navigationDelegateMock === webViewMock.navigationDelegateProxy.delegate)
}

@MainActor
func test_navigationDelegate_is_weakly_referenced() {
let actual = WeakReference<NavigationDelegateMock>()
let sut = WebView().navigationDelegate(actual.bypass(.init()))
var webViewMock = EnhancedWKWebViewMock?.some(.init())
sut.applyModifiers(to: webViewMock!)
webViewMock = nil
XCTAssertNil(actual.value)
}

@MainActor
func test_applyModifiers_isInspectable() {
let sut = WebView().allowsInspectable(true)
Expand Down

0 comments on commit f463a51

Please sign in to comment.