-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathOSIABSafariViewControllerRouterAdapterTests.swift
More file actions
156 lines (131 loc) · 6.17 KB
/
OSIABSafariViewControllerRouterAdapterTests.swift
File metadata and controls
156 lines (131 loc) · 6.17 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
150
151
152
153
154
155
156
import SafariServices
import XCTest
@testable import OSInAppBrowserLib
final class OSIABSafariVCRouterAdapterTests: XCTestCase {
let validURL = URL(string: "http://outsystems.com")!
func test_handleOpen_validURL_doesReturnSFSafariViewController() {
makeSUT().handleOpen(validURL) { XCTAssertNotNil($0) }
}
// MARK: Dismiss Style Tests
func test_handleOpen_noDismissStyle_doesReturnWithDefaultDismissStyle() {
makeSUT().handleOpen(validURL) {
XCTAssertEqual(
($0 as? SFSafariViewController)?.dismissButtonStyle, OSIABDismissStyle.defaultValue.toSFSafariViewControllerDismissButtonStyle()
)
}
}
func test_handleOpen_withDismissStyle_doesReturnWithSpecifiedDismissStyle() {
let options = OSIABSystemBrowserOptions.init(dismissStyle: .close)
makeSUT(options).handleOpen(validURL) {
XCTAssertEqual(
($0 as? SFSafariViewController)?.dismissButtonStyle, OSIABDismissStyle.close.toSFSafariViewControllerDismissButtonStyle()
)
}
}
// 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 = OSIABSystemBrowserOptions.init(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 = OSIABSystemBrowserOptions.init(animationEffect: .flipHorizontal)
makeSUT(options).handleOpen(validURL) {
XCTAssertEqual(
$0.modalTransitionStyle, OSIABAnimationEffect.flipHorizontal.toModalTransitionStyle()
)
}
}
// MARK: Enable Bars Collapsing Tests
func test_handleOpen_noEnableBarsCollapsingSet_doesReturnWithBarsCollapsing() {
makeSUT().handleOpen(validURL) {
XCTAssertEqual(
($0 as? SFSafariViewController)?.configuration.barCollapsingEnabled, true
)
}
}
func test_handleOpen_disableBarsCollapsing_doesReturnWithoutBarsCollapsing() {
let options = OSIABSystemBrowserOptions.init(enableBarsCollapsing: false)
makeSUT(options).handleOpen(validURL) {
XCTAssertEqual(
($0 as? SFSafariViewController)?.configuration.barCollapsingEnabled, false
)
}
}
// MARK: Enable Readers Mode Tests
func test_handleOpen_noEnableReadersModeSet_doesReturnWithReadersModeDisabled() {
makeSUT().handleOpen(validURL) {
XCTAssertEqual(
($0 as? SFSafariViewController)?.configuration.entersReaderIfAvailable, false
)
}
}
func test_handleOpen_enableReadersMode_doesReturnWithReadersModeEnabled() {
let options = OSIABSystemBrowserOptions.init(enableReadersMode: true)
makeSUT(options).handleOpen(validURL) {
XCTAssertEqual(
($0 as? SFSafariViewController)?.configuration.entersReaderIfAvailable, true
)
}
}
// MARK: onBrowserPageLoad Callback Tests
func test_handleOpen_withBrowserPageLoadConfigured_eventShouldBeTriggeredWhenLoaded() {
let expectation = self.expectation(description: "Trigger onBrowserPageLoad Event")
makeSUT(onBrowserPageLoad: { expectation.fulfill() }).handleOpen(validURL) {
if let safariViewController = $0 as? SFSafariViewController {
safariViewController.delegate?.safariViewController?(safariViewController, didCompleteInitialLoad: true)
}
}
waitForExpectations(timeout: 1)
}
func test_handleOpen_withBrowserPageLoadConfigured_eventShouldNotBeTriggeredWhenNotLoaded() {
let expectation = self.expectation(description: "Trigger onBrowserPageLoad Event")
expectation.isInverted = true
makeSUT(onBrowserPageLoad: { expectation.fulfill() }).handleOpen(validURL) {
if let safariViewController = $0 as? SFSafariViewController {
safariViewController.delegate?.safariViewController?(safariViewController, didCompleteInitialLoad: false)
}
}
waitForExpectations(timeout: 1)
}
// MARK: onBrowserClose Callback Tests
func test_handleOpen_withBrowserClosedConfigured_eventShouldBeTriggeredWhenClosed() {
let expectation = self.expectation(description: "Trigger onBrowserClose Event")
makeSUT(onBrowserClosed: { expectation.fulfill() }).handleOpen(validURL) {
$0.dismiss(animated: false)
}
waitForExpectations(timeout: 1)
}
func test_handleOpen_withBrowserClosedConfigured_eventShouldBeTriggeredWhenDismiss() {
let expectation = self.expectation(description: "Trigger onBrowserClose Event")
makeSUT(onBrowserClosed: { expectation.fulfill() }).handleOpen(validURL) {
if let presentationController = $0.presentationController {
presentationController.delegate?.presentationControllerDidDismiss?(presentationController)
}
}
waitForExpectations(timeout: 1)
}
}
private extension OSIABSafariVCRouterAdapterTests {
func makeSUT(_ options: OSIABSystemBrowserOptions = .init(), onBrowserPageLoad: @escaping () -> Void = {}, onBrowserClosed: @escaping () -> Void = {}) -> OSIABSafariViewControllerRouterAdapter {
.init(options, onBrowserPageLoad: onBrowserPageLoad, onBrowserClosed: onBrowserClosed)
}
}