-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathOSIABWebViewRouterAdapterTests.swift
More file actions
149 lines (121 loc) · 5.61 KB
/
OSIABWebViewRouterAdapterTests.swift
File metadata and controls
149 lines (121 loc) · 5.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import XCTest
@testable import OSInAppBrowserLib
final class OSIABWebViewRouterAdapterTests: XCTestCase {
let validURL = URL(string: "http://outsystems.com")!
func test_handleOpen_validURL_doesReturnHostingViewController() {
makeSUT().handleOpen(validURL) { XCTAssertNotNil($0) }
}
// MARK: Clear Cache Tests
func test_handleOpen_defaultClearCacheValue_cacheIsCleared() {
let cacheManager = OSIABCacheManagerStub(cacheWasCleared: false)
XCTAssertFalse(cacheManager.cacheWasCleared)
makeSUT(cacheManager: cacheManager).handleOpen(validURL) { _ in }
XCTAssertTrue(cacheManager.cacheWasCleared)
}
func test_handleOpen_disableClearCache_cacheIsNotCleared() {
let cacheManager = OSIABCacheManagerStub(cacheWasCleared: false)
XCTAssertFalse(cacheManager.cacheWasCleared)
let options = OSIABWebViewOptions(clearCache: false)
makeSUT(options, cacheManager: cacheManager).handleOpen(validURL) { _ in }
XCTAssertFalse(cacheManager.cacheWasCleared)
}
// MARK: Clear Session Cache Tests
func test_handleOpen_defaultClearSessionCacheValue_andDisableClearCache_sessionCacheIsNotCleared() {
let cacheManager = OSIABCacheManagerStub(sessionCacheWasCleared: false)
XCTAssertFalse(cacheManager.sessionCacheWasCleared)
let options = OSIABWebViewOptions(clearCache: false)
makeSUT(options, cacheManager: cacheManager).handleOpen(validURL) { _ in }
XCTAssertTrue(cacheManager.sessionCacheWasCleared)
}
func test_handleOpen_defaultClearSessionCacheValue_butEnableClearCache_sessionCacheIsNotCleared() {
let cacheManager = OSIABCacheManagerStub(sessionCacheWasCleared: false)
XCTAssertFalse(cacheManager.sessionCacheWasCleared)
makeSUT(cacheManager: cacheManager).handleOpen(validURL) { _ in }
XCTAssertFalse(cacheManager.sessionCacheWasCleared)
}
func test_handleOpen_disableClearSessionCache_sessionCacheIsNotCleared() {
let cacheManager = OSIABCacheManagerStub(sessionCacheWasCleared: false)
XCTAssertFalse(cacheManager.sessionCacheWasCleared)
let options = OSIABWebViewOptions(clearSessionCache: false)
makeSUT(options, cacheManager: cacheManager).handleOpen(validURL) { _ in }
XCTAssertFalse(cacheManager.sessionCacheWasCleared)
}
// MARK: View Style Tests
func test_handleOpen_noViewStyle_doesReturnWithDefaultViewStyle() {
makeSUT().handleOpen(validURL) {
XCTAssertEqual(
$0.modalPresentationStyle, OSIABViewStyle.defaultValue.toModalPresentationStyle()
)
}
}
func test_handleOpen_withViewStyle_doesReturnWithSpecifiedViewStyle() {
let options = OSIABWebViewOptions(viewStyle: .pageSheet)
makeSUT(options).handleOpen(validURL) {
XCTAssertEqual(
$0.modalPresentationStyle, OSIABViewStyle.pageSheet.toModalPresentationStyle()
)
}
}
// MARK: Animation Effect Tests
func test_handleOpen_noAnimationEffect_doesReturnWithDefaultAnimationEffect() {
makeSUT().handleOpen(validURL) {
XCTAssertEqual(
$0.modalTransitionStyle, OSIABAnimationEffect.defaultValue.toModalTransitionStyle()
)
}
}
func test_handleOpen_withAnimationEffect_doesReturnWithSpecifiedAnimationEffect() {
let options = OSIABWebViewOptions(animationEffect: .flipHorizontal)
makeSUT(options).handleOpen(validURL) {
XCTAssertEqual(
$0.modalTransitionStyle, OSIABAnimationEffect.flipHorizontal.toModalTransitionStyle()
)
}
}
// MARK: onBrowserClose Callback Tests
func test_handleOpen_withBrowserClosedConfigured_eventShouldBeTriggeredWhenDismissed() {
var isBrowserAlreadyClosed = false
let expectation = self.expectation(description: "Trigger onBrowserClose Event")
makeSUT(onBrowserClosed: { param in
isBrowserAlreadyClosed = param
expectation.fulfill()
}).handleOpen(validURL) {
if let presentationController = $0.presentationController {
presentationController.delegate?.presentationControllerDidDismiss?(presentationController)
}
}
waitForExpectations(timeout: 1)
XCTAssertTrue(isBrowserAlreadyClosed)
}
func test_handleOpen_whenDismissingViewController_eventShouldBeTriggered() {
var isBrowserAlreadyClosed = false
let expectation = self.expectation(description: "Trigger onBrowserClose Event")
makeSUT { param in
isBrowserAlreadyClosed = param
expectation.fulfill()
}.handleOpen(validURL) {
$0.dismiss(animated: false)
}
waitForExpectations(timeout: 1)
XCTAssertTrue(isBrowserAlreadyClosed)
}
}
private extension OSIABWebViewRouterAdapterTests {
func makeSUT(
_ options: OSIABWebViewOptions = .init(),
cacheManager: OSIABCacheManager = OSIABCacheManagerStub(),
onBrowserClosed: @escaping (Bool) -> Void = { _ in }
) -> OSIABWebViewRouterAdapter {
.init(
options: options,
cacheManager: cacheManager,
callbackHandler: .init(
onDelegateURL: { _ in },
onDelegateAlertController: { _ in },
onBrowserPageLoad: {},
onBrowserClosed: onBrowserClosed,
onBrowserPageNavigationCompleted: { _ in }
)
)
}
}