-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[quick_actions_ios] UIScene Migration #11047
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
5f64c02
0d2444f
fd058e5
495e311
b823134
6eaa5a3
bab8b38
3df0547
1728c3b
4aa4cf8
ea3650e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -223,4 +223,108 @@ struct QuickActionsPluginTests { | |
| plugin.applicationDidBecomeActive(UIApplication.shared) | ||
| } | ||
| } | ||
|
|
||
| // MARK: - Scene lifecycle tests | ||
|
|
||
| @Test func windowScenePerformActionForShortcutItem() async { | ||
| let flutterApi: MockFlutterApi = MockFlutterApi() | ||
| let mockShortcutItemProvider = MockShortcutItemProvider() | ||
|
|
||
| let plugin = QuickActionsPlugin( | ||
| flutterApi: flutterApi, | ||
| shortcutItemProvider: mockShortcutItemProvider) | ||
|
|
||
| let item = UIApplicationShortcutItem( | ||
| type: "SearchTheThing", | ||
| localizedTitle: "Search the thing", | ||
| localizedSubtitle: nil, | ||
| icon: UIApplicationShortcutIcon(templateImageName: "search_the_thing.png"), | ||
| userInfo: nil) | ||
|
|
||
| await confirmation("shortcut should be handled via windowScene") { confirmed in | ||
| flutterApi.launchActionCallback = { aString in | ||
| #expect(aString == item.type) | ||
| confirmed() | ||
| } | ||
|
|
||
| let windowScene = UIApplication.shared.connectedScenes.first as! UIWindowScene | ||
| var completionSuccess: Bool? | ||
| let actionResult = plugin.windowScene( | ||
| windowScene, | ||
| performActionFor: item | ||
| ) { success in | ||
| completionSuccess = success | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this closure called synchronously? (is
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, it is called synchronously, during the function call and assigned before the |
||
| } | ||
|
|
||
| #expect(actionResult, "windowScene performActionFor must return true.") | ||
| #expect(completionSuccess == true) | ||
| } | ||
| } | ||
|
|
||
| @Test func sceneWillConnectToWithoutShortcut() { | ||
| let flutterApi: MockFlutterApi = MockFlutterApi() | ||
| let mockShortcutItemProvider = MockShortcutItemProvider() | ||
|
|
||
| let plugin = QuickActionsPlugin( | ||
| flutterApi: flutterApi, | ||
| shortcutItemProvider: mockShortcutItemProvider) | ||
|
|
||
| let connectResult = plugin.scene( | ||
| UIApplication.shared.connectedScenes.first!, | ||
| willConnectTo: UIApplication.shared.connectedScenes.first!.session, | ||
| options: nil) | ||
| #expect( | ||
| !connectResult, | ||
| "scene willConnectTo must return false if not launched from shortcut.") | ||
| } | ||
|
|
||
| @Test func sceneDidBecomeActiveLaunchWithoutShortcut() async { | ||
| let flutterApi: MockFlutterApi = MockFlutterApi() | ||
| let mockShortcutItemProvider = MockShortcutItemProvider() | ||
|
|
||
| let plugin = QuickActionsPlugin( | ||
| flutterApi: flutterApi, | ||
| shortcutItemProvider: mockShortcutItemProvider) | ||
|
|
||
| let connectResult = plugin.scene( | ||
| UIApplication.shared.connectedScenes.first!, | ||
| willConnectTo: UIApplication.shared.connectedScenes.first!.session, | ||
| options: nil) | ||
| #expect(!connectResult) | ||
|
|
||
| await confirmation("launchAction should not be called", expectedCount: 0) { confirmed in | ||
| flutterApi.launchActionCallback = { _ in | ||
| confirmed() | ||
| } | ||
| plugin.sceneDidBecomeActive(UIApplication.shared.connectedScenes.first!) | ||
| } | ||
| } | ||
|
|
||
| @Test func sceneDidBecomeActiveLaunchWithShortcut() async { | ||
| let item = UIApplicationShortcutItem( | ||
| type: "SearchTheThing", | ||
| localizedTitle: "Search the thing", | ||
| localizedSubtitle: nil, | ||
| icon: UIApplicationShortcutIcon(templateImageName: "search_the_thing.png"), | ||
| userInfo: nil) | ||
|
|
||
| let flutterApi: MockFlutterApi = MockFlutterApi() | ||
| let mockShortcutItemProvider = MockShortcutItemProvider() | ||
|
|
||
| let plugin = QuickActionsPlugin( | ||
| flutterApi: flutterApi, | ||
| shortcutItemProvider: mockShortcutItemProvider) | ||
|
|
||
| await confirmation("shortcut should be handled when scene becomes active") { confirmed in | ||
| flutterApi.launchActionCallback = { aString in | ||
| #expect(aString == item.type) | ||
| confirmed() | ||
| } | ||
|
|
||
| let connectResult = plugin.handleSceneWillConnectTo(shortcutItem: item) | ||
| #expect(connectResult, "scene willConnectTo must return true when shortcut is provided.") | ||
|
|
||
| plugin.sceneDidBecomeActive(UIApplication.shared.connectedScenes.first!) | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.