Skip to content

Commit

Permalink
Handles action:black action URL correctly without error
Browse files Browse the repository at this point in the history
  • Loading branch information
adam1929 authored Feb 2, 2024
1 parent 71e3b2f commit fc28ff4
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ExponeaSDK/ExponeaSDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@
55391D492953051E001D95B8 /* AppInboxParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55391D482953051E001D95B8 /* AppInboxParser.swift */; };
55391D4B295342C7001D95B8 /* AppInboxManagerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55391D4A295342C7001D95B8 /* AppInboxManagerSpec.swift */; };
55391D4D295497A7001D95B8 /* AppInboxProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55391D4C295497A7001D95B8 /* AppInboxProviderSpec.swift */; };
555A10E82B6CE8D9004D3FB4 /* StaticInAppContentBlockViewSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 555A10E72B6CE8D9004D3FB4 /* StaticInAppContentBlockViewSpec.swift */; };
5567C090290808F600318E68 /* MessageItemContent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5567C08F290808F600318E68 /* MessageItemContent.swift */; };
5567C092290809EB00318E68 /* MessageItemAction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5567C091290809EB00318E68 /* MessageItemAction.swift */; };
5567C0942909196C00318E68 /* AppInboxResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5567C0932909196C00318E68 /* AppInboxResponse.swift */; };
Expand Down Expand Up @@ -759,6 +760,7 @@
55391D482953051E001D95B8 /* AppInboxParser.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppInboxParser.swift; sourceTree = "<group>"; };
55391D4A295342C7001D95B8 /* AppInboxManagerSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppInboxManagerSpec.swift; sourceTree = "<group>"; };
55391D4C295497A7001D95B8 /* AppInboxProviderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppInboxProviderSpec.swift; sourceTree = "<group>"; };
555A10E72B6CE8D9004D3FB4 /* StaticInAppContentBlockViewSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StaticInAppContentBlockViewSpec.swift; sourceTree = "<group>"; };
5567C08F290808F600318E68 /* MessageItemContent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageItemContent.swift; sourceTree = "<group>"; };
5567C091290809EB00318E68 /* MessageItemAction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageItemAction.swift; sourceTree = "<group>"; };
5567C0932909196C00318E68 /* AppInboxResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppInboxResponse.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1572,6 +1574,7 @@
isa = PBXGroup;
children = (
31EBB86A2A6AC3500003AAA5 /* InAppContentBlocksManagerSpec.swift */,
555A10E72B6CE8D9004D3FB4 /* StaticInAppContentBlockViewSpec.swift */,
);
path = InAppContentBlocks;
sourceTree = "<group>";
Expand Down Expand Up @@ -3024,6 +3027,7 @@
0591907123EC573C0037BD88 /* BooleanOperatorsSpec.swift in Sources */,
05AA63BE2342413E00D78452 /* NetworkStubbing.swift in Sources */,
05F3EFEA2382BC4C006E83F4 /* MockTelemetryStorage.swift in Sources */,
555A10E82B6CE8D9004D3FB4 /* StaticInAppContentBlockViewSpec.swift in Sources */,
F04BEA8E21118F4700591950 /* ResultSpec.swift in Sources */,
053EC59F23AA61DC004D1C8B /* InAppMessageDisplayStatusStoreSpec.swift in Sources */,
057F449123995EA00070DF30 /* MockInAppMessagePresenter.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,11 @@ public final class StaticInAppContentBlockView: UIView, WKNavigationDelegate {
Exponea.logger.log(.warning, message: "InAppCB: Unknown action URL: \(String(describing: actionUrl))")
return false
}
if isBlankNav(actionUrl) {
// on first load
// nothing to do, not need to continue loading
return false
}
guard let message = assignedMessage else {
Exponea.logger.log(.error, message: "InAppCB: Placeholder \(placeholder) has invalid state - action or message is invalid")
behaviourCallback.onError(placeholderId: placeholder, contentBlock: nil, errorMessage: "Invalid action definition")
Expand Down Expand Up @@ -271,4 +276,8 @@ public final class StaticInAppContentBlockView: UIView, WKNavigationDelegate {
}
return handled
}

private func isBlankNav(_ url: URL?) -> Bool {
url?.absoluteString == "about:blank"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
//
// StaticInAppContentBlockViewSpec.swift
// ExponeaSDKTests
//
// Created by Adam Mihalik on 02/02/2024.
// Copyright © 2024 Exponea. All rights reserved.
//

import Foundation
import Quick
import Nimble
import WebKit

@testable import ExponeaSDK

class StaticInAppContentBlockViewSpec: QuickSpec {
let configuration = try! Configuration(
projectToken: "token",
authorization: Authorization.none,
baseUrl: "baseUrl"
)
override func spec() {
it("should NOT invoke error event for about:blank action URL") {
let view = StaticInAppContentBlockView(placeholder: "ph_1", deferredLoad: true)
var errorCalled = false
view.behaviourCallback = SimpleBehaviourCallback(
onErrorAction: { _, _, _ in
errorCalled = true
}
)
let action = SimpleNavigationAction(url: URL(string: "about:blank")!)
var actionHasBeenHandled: Bool?
view.webView(WKWebView(), decidePolicyFor: action) { decision in
// canceled action means that action has been handled internaly, WebView is not allowed to continue
actionHasBeenHandled = decision == .cancel
}
expect(actionHasBeenHandled).toNot(beNil())
guard let actionHasBeenHandled = actionHasBeenHandled else {
return
}
expect(actionHasBeenHandled).to(beFalse())
expect(errorCalled).to(beFalse())
}
}
}

class SimpleBehaviourCallback: InAppContentBlockCallbackType {
private var onMessageShownAction: ((String, ExponeaSDK.InAppContentBlockResponse) -> Void)?
private var onNoMessageFoundAction: ((String) -> Void)?
private var onErrorAction: ((String, ExponeaSDK.InAppContentBlockResponse?, String) -> Void)?
private var onCloseClickedAction: ((String, ExponeaSDK.InAppContentBlockResponse) -> Void)?
private var onActionClickedAction: ((String, ExponeaSDK.InAppContentBlockResponse, ExponeaSDK.InAppContentBlockAction) -> Void)?
init(
onMessageShownAction: ((String, ExponeaSDK.InAppContentBlockResponse) -> Void)? = nil,
onNoMessageFoundAction: ((String) -> Void)? = nil,
onErrorAction: ((String, ExponeaSDK.InAppContentBlockResponse?, String) -> Void)? = nil,
onCloseClickedAction: ((String, ExponeaSDK.InAppContentBlockResponse) -> Void)? = nil,
onActionClickedAction: ((String, ExponeaSDK.InAppContentBlockResponse, ExponeaSDK.InAppContentBlockAction) -> Void)? = nil
) {
self.onMessageShownAction = onMessageShownAction
self.onNoMessageFoundAction = onNoMessageFoundAction
self.onErrorAction = onErrorAction
self.onCloseClickedAction = onCloseClickedAction
self.onActionClickedAction = onActionClickedAction
}
func onMessageShown(placeholderId: String, contentBlock: ExponeaSDK.InAppContentBlockResponse) {
onMessageShownAction?(placeholderId, contentBlock)
}
func onNoMessageFound(placeholderId: String) {
onNoMessageFoundAction?(placeholderId)
}
func onError(placeholderId: String, contentBlock: ExponeaSDK.InAppContentBlockResponse?, errorMessage: String) {
onErrorAction?(placeholderId, contentBlock, errorMessage)
}
func onCloseClicked(placeholderId: String, contentBlock: ExponeaSDK.InAppContentBlockResponse) {
onCloseClickedAction?(placeholderId, contentBlock)
}

func onActionClicked(placeholderId: String, contentBlock: ExponeaSDK.InAppContentBlockResponse, action: ExponeaSDK.InAppContentBlockAction) {
onActionClickedAction?(placeholderId, contentBlock, action)
}
}

final class SimpleNavigationAction: WKNavigationAction {
let urlRequest: URLRequest
var receivedPolicy: WKNavigationActionPolicy?
override var request: URLRequest { urlRequest }
init(
urlRequest: URLRequest
) {
self.urlRequest = urlRequest
super.init()
}
convenience init(url: URL) {
self.init(urlRequest: URLRequest(url: url))
}
func decisionHandler(_ policy: WKNavigationActionPolicy) { self.receivedPolicy = policy }
}

0 comments on commit fc28ff4

Please sign in to comment.