CustomInAppMessageDisplayViewModifierTests.swift 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Copyright 2021 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. import XCTest
  15. @testable import FirebaseInAppMessaging
  16. @testable import FirebaseInAppMessagingSwift
  17. class DelegateBridgeTests: XCTestCase {
  18. var delegateBridge = DelegateBridge()
  19. func testClearsInAppMessageOnDismiss() {
  20. let inAppMessage: InAppMessagingDisplayMessage = InAppMessagingDisplayMessage(
  21. messageID: "messageID",
  22. campaignName: "testCampaign",
  23. renderAsTestMessage: false,
  24. messageType: .card,
  25. triggerType: .onAppForeground
  26. )
  27. delegateBridge.displayMessage(inAppMessage, displayDelegate: TestDelegate())
  28. DispatchQueue.main.async {
  29. XCTAssertNotNil(self.delegateBridge.inAppMessageData)
  30. }
  31. delegateBridge.messageDismissed(inAppMessage, dismissType: .typeUserTapClose)
  32. DispatchQueue.main.async {
  33. XCTAssertNil(self.delegateBridge.inAppMessageData)
  34. }
  35. }
  36. func testClearsInAppMessageOnClick() {
  37. let inAppMessage: InAppMessagingDisplayMessage = InAppMessagingDisplayMessage(
  38. messageID: "messageID",
  39. campaignName: "testCampaign",
  40. renderAsTestMessage: false,
  41. messageType: .card,
  42. triggerType: .onAppForeground
  43. )
  44. delegateBridge.displayMessage(inAppMessage, displayDelegate: TestDelegate())
  45. DispatchQueue.main.async {
  46. XCTAssertNotNil(self.delegateBridge.inAppMessageData)
  47. }
  48. delegateBridge.messageClicked(inAppMessage,
  49. with: InAppMessagingAction(actionText: "test",
  50. actionURL: URL(
  51. string: "http://www.test.com"
  52. )))
  53. DispatchQueue.main.async {
  54. XCTAssertNil(self.delegateBridge.inAppMessageData)
  55. }
  56. }
  57. class TestDelegate: NSObject, InAppMessagingDisplayDelegate {}
  58. }