From e69b5d91defe39e9da970b2583b8f2f38918646c Mon Sep 17 00:00:00 2001 From: Philemon Merlet Date: Thu, 16 Jan 2025 16:50:35 +0100 Subject: [PATCH] Fix crash when calling showPreferences --- ios/RNDidomi.swift | 4 +-- test/ios/DidomiUITests/DidomiUITests.swift | 30 ++++++++-------------- 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/ios/RNDidomi.swift b/ios/RNDidomi.swift index 25984951..c7d238ba 100644 --- a/ios/RNDidomi.swift +++ b/ios/RNDidomi.swift @@ -274,8 +274,8 @@ class RNDidomi: RCTEventEmitter { @objc(showPreferences:resolve:reject:) dynamic func showPreferences(view: String?, resolve:RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) { - if let containerController = RCTPresentedViewController() { - DispatchQueue.main.async { + DispatchQueue.main.async { + if let containerController = RCTPresentedViewController() { if let view = view { let preferencesView: Didomi.Views = view.lowercased() == "vendors" ? .vendors : .purposes Didomi.shared.showPreferences(controller: containerController, view: preferencesView) diff --git a/test/ios/DidomiUITests/DidomiUITests.swift b/test/ios/DidomiUITests/DidomiUITests.swift index 6bfa73d7..67bb81a0 100644 --- a/test/ios/DidomiUITests/DidomiUITests.swift +++ b/test/ios/DidomiUITests/DidomiUITests.swift @@ -155,17 +155,13 @@ class DidomiUITests: XCTestCase { tapButton(in: app, name: "reset") tapButton(in: app, name: "showPreferences Purposes") - let dismissButton = app.staticTexts["Dismiss"] - dismissButton.wait() - dismissButton.tap() - // Check opening of preferences - // let preferencesButton = app.staticTexts["Agree to all"] - // preferencesButton.wait() - // testLastEvent(app: app, name:"on_show_preferences") + let preferencesButton = app.staticTexts["Agree to all"] + preferencesButton.wait() + testLastEvent(app: app, name:"on_show_preferences") // Close notice - // preferencesButton.tap() + preferencesButton.tap() assertResult(in: app, name: "showPreferences Purposes", expected: "showPreferences Purposes-OK") testLastEvent(app: app, name:"on_hide_notice") @@ -177,22 +173,18 @@ class DidomiUITests: XCTestCase { tapButton(in: app, name: "reset") tapButton(in: app, name: "showPreferences Vendors") - let dismissButton = app.staticTexts["Dismiss"] - dismissButton.wait() - dismissButton.tap() - // Check opening of vendors - // let vendorsButton = app.staticTexts["Save"] - // vendorsButton.wait() - // testLastEvent(app: app, name:"on_show_preferences") + let vendorsButton = app.staticTexts["Save"] + vendorsButton.wait() + testLastEvent(app: app, name:"on_show_preferences") // Close notice - // vendorsButton.tap() + vendorsButton.tap() // Close preferences - // let preferencesButton = app.staticTexts["Agree to all"] - // preferencesButton.wait() - // preferencesButton.tap() + let preferencesButton = app.staticTexts["Agree to all"] + preferencesButton.wait() + preferencesButton.tap() assertResult(in: app, name: "showPreferences Vendors", expected: "showPreferences Vendors-OK") testLastEvent(app: app, name:"on_hide_notice")