expo-targets 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +2 -0
- package/README.md +244 -0
- package/android/build.gradle +22 -0
- package/android/src/main/java/expo/modules/targets/ExpoTargetsLogger.kt +98 -0
- package/android/src/main/java/expo/modules/targets/ExpoTargetsReceiver.kt +136 -0
- package/android/src/main/java/expo/modules/targets/ExpoTargetsRemoteViewsProvider.kt +72 -0
- package/android/src/main/java/expo/modules/targets/ExpoTargetsWidgetProvider.kt +47 -0
- package/android/src/main/java/expo/modules/targets/ExpoTargetsWidgetSync.kt +78 -0
- package/android/src/main/java/expo/modules/targets/ExpoTargetsWidgetUpdateReceiver.kt +30 -0
- package/android/src/main/java/expo/modules/targets/extension/ExpoTargetsExtensionModule.kt +27 -0
- package/android/src/main/java/expo/modules/targets/messages/ExpoTargetsMessagesModule.kt +40 -0
- package/android/src/main/java/expo/modules/targets/storage/ExpoTargetsStorageModule.kt +119 -0
- package/app.plugin.js +1 -0
- package/build/metro/src/index.d.ts +2 -0
- package/build/metro/src/index.d.ts.map +1 -0
- package/build/metro/src/index.js +6 -0
- package/build/metro/src/index.js.map +1 -0
- package/build/metro/src/withTargetsMetro.d.ts +6 -0
- package/build/metro/src/withTargetsMetro.d.ts.map +1 -0
- package/build/metro/src/withTargetsMetro.js +171 -0
- package/build/metro/src/withTargetsMetro.js.map +1 -0
- package/build/plugin/src/android/config-plugins/withAndroidColors.d.ts +7 -0
- package/build/plugin/src/android/config-plugins/withAndroidColors.d.ts.map +1 -0
- package/build/plugin/src/android/config-plugins/withAndroidColors.js +56 -0
- package/build/plugin/src/android/config-plugins/withAndroidColors.js.map +1 -0
- package/build/plugin/src/android/config-plugins/withAndroidManifest.d.ts +7 -0
- package/build/plugin/src/android/config-plugins/withAndroidManifest.d.ts.map +1 -0
- package/build/plugin/src/android/config-plugins/withAndroidManifest.js +70 -0
- package/build/plugin/src/android/config-plugins/withAndroidManifest.js.map +1 -0
- package/build/plugin/src/android/config-plugins/withAndroidModule.d.ts +7 -0
- package/build/plugin/src/android/config-plugins/withAndroidModule.d.ts.map +1 -0
- package/build/plugin/src/android/config-plugins/withAndroidModule.js +41 -0
- package/build/plugin/src/android/config-plugins/withAndroidModule.js.map +1 -0
- package/build/plugin/src/android/config-plugins/withAndroidResources.d.ts +7 -0
- package/build/plugin/src/android/config-plugins/withAndroidResources.d.ts.map +1 -0
- package/build/plugin/src/android/config-plugins/withAndroidResources.js +75 -0
- package/build/plugin/src/android/config-plugins/withAndroidResources.js.map +1 -0
- package/build/plugin/src/android/config-plugins/withAndroidTarget.d.ts +28 -0
- package/build/plugin/src/android/config-plugins/withAndroidTarget.d.ts.map +1 -0
- package/build/plugin/src/android/config-plugins/withAndroidTarget.js +28 -0
- package/build/plugin/src/android/config-plugins/withAndroidTarget.js.map +1 -0
- package/build/plugin/src/android/config-plugins/withGradleModule.d.ts +7 -0
- package/build/plugin/src/android/config-plugins/withGradleModule.d.ts.map +1 -0
- package/build/plugin/src/android/config-plugins/withGradleModule.js +86 -0
- package/build/plugin/src/android/config-plugins/withGradleModule.js.map +1 -0
- package/build/plugin/src/android/config-plugins/withGradleSettings.d.ts +7 -0
- package/build/plugin/src/android/config-plugins/withGradleSettings.d.ts.map +1 -0
- package/build/plugin/src/android/config-plugins/withGradleSettings.js +23 -0
- package/build/plugin/src/android/config-plugins/withGradleSettings.js.map +1 -0
- package/build/plugin/src/android/withAndroidAppBuildGradle.d.ts +7 -0
- package/build/plugin/src/android/withAndroidAppBuildGradle.d.ts.map +1 -0
- package/build/plugin/src/android/withAndroidAppBuildGradle.js +31 -0
- package/build/plugin/src/android/withAndroidAppBuildGradle.js.map +1 -0
- package/build/plugin/src/android/withAndroidKotlinGradleProperty.d.ts +3 -0
- package/build/plugin/src/android/withAndroidKotlinGradleProperty.d.ts.map +1 -0
- package/build/plugin/src/android/withAndroidKotlinGradleProperty.js +24 -0
- package/build/plugin/src/android/withAndroidKotlinGradleProperty.js.map +1 -0
- package/build/plugin/src/android/withAndroidProjectKotlinVersion.d.ts +3 -0
- package/build/plugin/src/android/withAndroidProjectKotlinVersion.d.ts.map +1 -0
- package/build/plugin/src/android/withAndroidProjectKotlinVersion.js +27 -0
- package/build/plugin/src/android/withAndroidProjectKotlinVersion.js.map +1 -0
- package/build/plugin/src/android/withAndroidTarget.d.ts +10 -0
- package/build/plugin/src/android/withAndroidTarget.d.ts.map +1 -0
- package/build/plugin/src/android/withAndroidTarget.js +22 -0
- package/build/plugin/src/android/withAndroidTarget.js.map +1 -0
- package/build/plugin/src/android/withAndroidWidget.d.ts +13 -0
- package/build/plugin/src/android/withAndroidWidget.d.ts.map +1 -0
- package/build/plugin/src/android/withAndroidWidget.js +564 -0
- package/build/plugin/src/android/withAndroidWidget.js.map +1 -0
- package/build/plugin/src/config.d.ts +141 -0
- package/build/plugin/src/config.d.ts.map +1 -0
- package/build/plugin/src/config.js +54 -0
- package/build/plugin/src/config.js.map +1 -0
- package/build/plugin/src/index.d.ts +9 -0
- package/build/plugin/src/index.d.ts.map +1 -0
- package/build/plugin/src/index.js +11 -0
- package/build/plugin/src/index.js.map +1 -0
- package/build/plugin/src/ios/config-plugins/withEntitlements.d.ts +11 -0
- package/build/plugin/src/ios/config-plugins/withEntitlements.d.ts.map +1 -0
- package/build/plugin/src/ios/config-plugins/withEntitlements.js +49 -0
- package/build/plugin/src/ios/config-plugins/withEntitlements.js.map +1 -0
- package/build/plugin/src/ios/config-plugins/withIOSTarget.d.ts +17 -0
- package/build/plugin/src/ios/config-plugins/withIOSTarget.d.ts.map +1 -0
- package/build/plugin/src/ios/config-plugins/withIOSTarget.js +152 -0
- package/build/plugin/src/ios/config-plugins/withIOSTarget.js.map +1 -0
- package/build/plugin/src/ios/config-plugins/withIosColorset.d.ts +8 -0
- package/build/plugin/src/ios/config-plugins/withIosColorset.d.ts.map +1 -0
- package/build/plugin/src/ios/config-plugins/withIosColorset.js +25 -0
- package/build/plugin/src/ios/config-plugins/withIosColorset.js.map +1 -0
- package/build/plugin/src/ios/config-plugins/withIosStickerPack.d.ts +8 -0
- package/build/plugin/src/ios/config-plugins/withIosStickerPack.d.ts.map +1 -0
- package/build/plugin/src/ios/config-plugins/withIosStickerPack.js +52 -0
- package/build/plugin/src/ios/config-plugins/withIosStickerPack.js.map +1 -0
- package/build/plugin/src/ios/config-plugins/withPodfile.d.ts +12 -0
- package/build/plugin/src/ios/config-plugins/withPodfile.d.ts.map +1 -0
- package/build/plugin/src/ios/config-plugins/withPodfile.js +162 -0
- package/build/plugin/src/ios/config-plugins/withPodfile.js.map +1 -0
- package/build/plugin/src/ios/config-plugins/withXcodeChanges.d.ts +15 -0
- package/build/plugin/src/ios/config-plugins/withXcodeChanges.d.ts.map +1 -0
- package/build/plugin/src/ios/config-plugins/withXcodeChanges.js +646 -0
- package/build/plugin/src/ios/config-plugins/withXcodeChanges.js.map +1 -0
- package/build/plugin/src/ios/target.d.ts +41 -0
- package/build/plugin/src/ios/target.d.ts.map +1 -0
- package/build/plugin/src/ios/target.js +574 -0
- package/build/plugin/src/ios/target.js.map +1 -0
- package/build/plugin/src/ios/utils/asset.d.ts +60 -0
- package/build/plugin/src/ios/utils/asset.d.ts.map +1 -0
- package/build/plugin/src/ios/utils/asset.js +375 -0
- package/build/plugin/src/ios/utils/asset.js.map +1 -0
- package/build/plugin/src/ios/utils/file.d.ts +33 -0
- package/build/plugin/src/ios/utils/file.d.ts.map +1 -0
- package/build/plugin/src/ios/utils/file.js +88 -0
- package/build/plugin/src/ios/utils/file.js.map +1 -0
- package/build/plugin/src/ios/utils/index.d.ts +12 -0
- package/build/plugin/src/ios/utils/index.d.ts.map +1 -0
- package/build/plugin/src/ios/utils/index.js +38 -0
- package/build/plugin/src/ios/utils/index.js.map +1 -0
- package/build/plugin/src/ios/utils/paths.d.ts +128 -0
- package/build/plugin/src/ios/utils/paths.d.ts.map +1 -0
- package/build/plugin/src/ios/utils/paths.js +141 -0
- package/build/plugin/src/ios/utils/paths.js.map +1 -0
- package/build/plugin/src/ios/utils/plist.d.ts +29 -0
- package/build/plugin/src/ios/utils/plist.d.ts.map +1 -0
- package/build/plugin/src/ios/utils/plist.js +114 -0
- package/build/plugin/src/ios/utils/plist.js.map +1 -0
- package/build/plugin/src/ios/utils/podfile.d.ts +82 -0
- package/build/plugin/src/ios/utils/podfile.d.ts.map +1 -0
- package/build/plugin/src/ios/utils/podfile.js +408 -0
- package/build/plugin/src/ios/utils/podfile.js.map +1 -0
- package/build/plugin/src/ios/utils/reactNativeSwift.d.ts +11 -0
- package/build/plugin/src/ios/utils/reactNativeSwift.d.ts.map +1 -0
- package/build/plugin/src/ios/utils/reactNativeSwift.js +263 -0
- package/build/plugin/src/ios/utils/reactNativeSwift.js.map +1 -0
- package/build/plugin/src/ios/utils/xcode.d.ts +185 -0
- package/build/plugin/src/ios/utils/xcode.d.ts.map +1 -0
- package/build/plugin/src/ios/utils/xcode.js +706 -0
- package/build/plugin/src/ios/utils/xcode.js.map +1 -0
- package/build/plugin/src/logger.d.ts +10 -0
- package/build/plugin/src/logger.d.ts.map +1 -0
- package/build/plugin/src/logger.js +62 -0
- package/build/plugin/src/logger.js.map +1 -0
- package/build/plugin/src/parseTargetConfig.d.ts +3 -0
- package/build/plugin/src/parseTargetConfig.d.ts.map +1 -0
- package/build/plugin/src/parseTargetConfig.js +113 -0
- package/build/plugin/src/parseTargetConfig.js.map +1 -0
- package/build/plugin/src/withTargetsDir.d.ts +6 -0
- package/build/plugin/src/withTargetsDir.d.ts.map +1 -0
- package/build/plugin/src/withTargetsDir.js +90 -0
- package/build/plugin/src/withTargetsDir.js.map +1 -0
- package/build/src/Target.d.ts +43 -0
- package/build/src/Target.d.ts.map +1 -0
- package/build/src/Target.js +128 -0
- package/build/src/Target.js.map +1 -0
- package/build/src/index.d.ts +9 -0
- package/build/src/index.d.ts.map +1 -0
- package/build/src/index.js +27 -0
- package/build/src/index.js.map +1 -0
- package/build/src/modules/extension/index.d.ts +18 -0
- package/build/src/modules/extension/index.d.ts.map +1 -0
- package/build/src/modules/extension/index.js +44 -0
- package/build/src/modules/extension/index.js.map +1 -0
- package/build/src/modules/messages/index.d.ts +40 -0
- package/build/src/modules/messages/index.d.ts.map +1 -0
- package/build/src/modules/messages/index.js +94 -0
- package/build/src/modules/messages/index.js.map +1 -0
- package/build/src/modules/storage/index.d.ts +16 -0
- package/build/src/modules/storage/index.d.ts.map +1 -0
- package/build/src/modules/storage/index.js +122 -0
- package/build/src/modules/storage/index.js.map +1 -0
- package/expo-module.config.json +17 -0
- package/ios/ExpoTargetsExtension.podspec +23 -0
- package/ios/ExpoTargetsExtensionModule.swift +181 -0
- package/ios/ExpoTargetsMessages.podspec +23 -0
- package/ios/ExpoTargetsMessagesModule.swift +267 -0
- package/ios/ExpoTargetsStorage.podspec +23 -0
- package/ios/ExpoTargetsStorageModule.swift +91 -0
- package/ios/Tests/.swiftlint.yml +52 -0
- package/ios/Tests/Helpers/MockExtensionContext.swift +58 -0
- package/ios/Tests/Helpers/MockUserDefaults.swift +70 -0
- package/ios/Tests/Helpers/MockWidgetCenter.swift +71 -0
- package/ios/Tests/Helpers/TestHelpers.swift +90 -0
- package/ios/Tests/Integration/TargetIntegrationTests.swift +478 -0
- package/ios/Tests/Main/AllTests.swift +80 -0
- package/ios/Tests/Package.swift +66 -0
- package/ios/Tests/Performance/StoragePerformanceTests.swift +461 -0
- package/ios/Tests/Unit/Extension/ExpoTargetsExtensionModuleTests.swift +501 -0
- package/ios/Tests/Unit/Storage/ExpoTargetsStorageModuleTests.swift +578 -0
- package/ios/Tests/Unit/Template/ShareExtensionTemplateTests.swift +421 -0
- package/ios/Tests/XCTestPlan.xctestplan +87 -0
- package/metro/src/index.ts +1 -0
- package/metro/src/withTargetsMetro.ts +247 -0
- package/metro/tsconfig.build.json +9 -0
- package/package.json +74 -0
- package/plugin/src/android/withAndroidAppBuildGradle.ts +34 -0
- package/plugin/src/android/withAndroidTarget.ts +26 -0
- package/plugin/src/android/withAndroidWidget.ts +778 -0
- package/plugin/src/config.ts +255 -0
- package/plugin/src/index.ts +19 -0
- package/plugin/src/ios/config-plugins/withEntitlements.ts +69 -0
- package/plugin/src/ios/config-plugins/withIOSTarget.ts +179 -0
- package/plugin/src/ios/config-plugins/withIosColorset.ts +29 -0
- package/plugin/src/ios/config-plugins/withIosStickerPack.ts +65 -0
- package/plugin/src/ios/config-plugins/withPodfile.ts +238 -0
- package/plugin/src/ios/config-plugins/withXcodeChanges.ts +891 -0
- package/plugin/src/ios/target.ts +668 -0
- package/plugin/src/ios/templates/MessagesViewController.swift +120 -0
- package/plugin/src/ios/templates/ReactNativeViewController.swift +240 -0
- package/plugin/src/ios/templates/action-extension-data.swift +106 -0
- package/plugin/src/ios/templates/clip-extension-data.swift +28 -0
- package/plugin/src/ios/templates/messages-extension-data.swift +28 -0
- package/plugin/src/ios/templates/share-extension-data.swift +113 -0
- package/plugin/src/ios/utils/asset.ts +490 -0
- package/plugin/src/ios/utils/file.ts +80 -0
- package/plugin/src/ios/utils/index.ts +12 -0
- package/plugin/src/ios/utils/paths.ts +253 -0
- package/plugin/src/ios/utils/plist.ts +101 -0
- package/plugin/src/ios/utils/podfile.ts +534 -0
- package/plugin/src/ios/utils/reactNativeSwift.ts +283 -0
- package/plugin/src/ios/utils/xcode.ts +989 -0
- package/plugin/src/logger.ts +63 -0
- package/plugin/src/parseTargetConfig.ts +115 -0
- package/plugin/src/types/normalize-colors.d.ts +3 -0
- package/plugin/src/withTargetsDir.ts +120 -0
- package/plugin/tsconfig.build.json +9 -0
- package/plugin/tsconfig.json +9 -0
- package/src/Target.ts +239 -0
- package/src/index.ts +52 -0
- package/src/modules/extension/index.ts +54 -0
- package/src/modules/messages/index.ts +124 -0
- package/src/modules/storage/index.ts +126 -0
- package/tsconfig.json +8 -0
|
@@ -0,0 +1,501 @@
|
|
|
1
|
+
import XCTest
|
|
2
|
+
import Foundation
|
|
3
|
+
import UIKit
|
|
4
|
+
@testable import ExpoTargetsExtension
|
|
5
|
+
|
|
6
|
+
/// Comprehensive unit tests for ExpoTargetsExtensionModule
|
|
7
|
+
/// Tests extension context operations, data retrieval, and host app communication
|
|
8
|
+
class ExpoTargetsExtensionModuleTests: XCTestCase {
|
|
9
|
+
|
|
10
|
+
var mockContext: MockExtensionContext!
|
|
11
|
+
|
|
12
|
+
// MARK: - Setup & Teardown
|
|
13
|
+
|
|
14
|
+
override func setUp() {
|
|
15
|
+
super.setUp()
|
|
16
|
+
mockContext = MockExtensionContext()
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
override func tearDown() {
|
|
20
|
+
mockContext.reset()
|
|
21
|
+
mockContext = nil
|
|
22
|
+
super.tearDown()
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// MARK: - Close Extension Tests
|
|
26
|
+
|
|
27
|
+
func testCloseExtension_CompletesRequest() {
|
|
28
|
+
// When
|
|
29
|
+
mockContext.completeRequest(returningItems: nil, completionHandler: nil)
|
|
30
|
+
|
|
31
|
+
// Then
|
|
32
|
+
XCTAssertTrue(mockContext.completeRequestCalled)
|
|
33
|
+
XCTAssertNil(mockContext.completionItems)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
func testCloseExtension_WithItems() {
|
|
37
|
+
// Given
|
|
38
|
+
let items = ["item1", "item2"]
|
|
39
|
+
|
|
40
|
+
// When
|
|
41
|
+
mockContext.completeRequest(returningItems: items, completionHandler: nil)
|
|
42
|
+
|
|
43
|
+
// Then
|
|
44
|
+
XCTAssertTrue(mockContext.completeRequestCalled)
|
|
45
|
+
XCTAssertNotNil(mockContext.completionItems)
|
|
46
|
+
XCTAssertEqual(mockContext.completionItems?.count, 2)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
func testCloseExtension_CallsCompletionHandler() {
|
|
50
|
+
// Given
|
|
51
|
+
let expectation = XCTestExpectation(description: "Completion handler called")
|
|
52
|
+
|
|
53
|
+
// When
|
|
54
|
+
mockContext.completeRequest(returningItems: nil) { success in
|
|
55
|
+
XCTAssertTrue(success)
|
|
56
|
+
expectation.fulfill()
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Then
|
|
60
|
+
wait(for: [expectation], timeout: 1.0)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
func testCancelRequest_WithError() {
|
|
64
|
+
// Given
|
|
65
|
+
let error = NSError(domain: "test", code: 123, userInfo: nil)
|
|
66
|
+
|
|
67
|
+
// When
|
|
68
|
+
mockContext.cancelRequest(withError: error)
|
|
69
|
+
|
|
70
|
+
// Then
|
|
71
|
+
XCTAssertTrue(mockContext.cancelRequestCalled)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// MARK: - Get Shared Data - Text Tests
|
|
75
|
+
|
|
76
|
+
func testGetSharedData_ReturnsNilWhenNoItems() {
|
|
77
|
+
// Given - mockContext has no input items
|
|
78
|
+
|
|
79
|
+
// When
|
|
80
|
+
let data = extractSharedData(from: mockContext)
|
|
81
|
+
|
|
82
|
+
// Then
|
|
83
|
+
XCTAssertNil(data)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
func testGetSharedData_ExtractsPlainText() {
|
|
87
|
+
// Given
|
|
88
|
+
let testText = "Hello, World!"
|
|
89
|
+
mockContext.addMockTextItem(testText)
|
|
90
|
+
|
|
91
|
+
// When
|
|
92
|
+
let data = extractSharedData(from: mockContext)
|
|
93
|
+
|
|
94
|
+
// Then
|
|
95
|
+
XCTAssertNotNil(data)
|
|
96
|
+
XCTAssertEqual(data?["text"] as? String, testText)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
func testGetSharedData_ExtractsMultilineText() {
|
|
100
|
+
// Given
|
|
101
|
+
let multilineText = """
|
|
102
|
+
Line 1
|
|
103
|
+
Line 2
|
|
104
|
+
Line 3
|
|
105
|
+
"""
|
|
106
|
+
mockContext.addMockTextItem(multilineText)
|
|
107
|
+
|
|
108
|
+
// When
|
|
109
|
+
let data = extractSharedData(from: mockContext)
|
|
110
|
+
|
|
111
|
+
// Then
|
|
112
|
+
XCTAssertNotNil(data)
|
|
113
|
+
XCTAssertEqual(data?["text"] as? String, multilineText)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
func testGetSharedData_ExtractsTextWithSpecialCharacters() {
|
|
117
|
+
// Given
|
|
118
|
+
let specialText = "Hello! 👋 @#$%^&*() \n\t"
|
|
119
|
+
mockContext.addMockTextItem(specialText)
|
|
120
|
+
|
|
121
|
+
// When
|
|
122
|
+
let data = extractSharedData(from: mockContext)
|
|
123
|
+
|
|
124
|
+
// Then
|
|
125
|
+
XCTAssertNotNil(data)
|
|
126
|
+
XCTAssertEqual(data?["text"] as? String, specialText)
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
func testGetSharedData_ExtractsUnicodeText() {
|
|
130
|
+
// Given
|
|
131
|
+
let unicodeText = "Hello 世界 🌍 مرحبا Привет"
|
|
132
|
+
mockContext.addMockTextItem(unicodeText)
|
|
133
|
+
|
|
134
|
+
// When
|
|
135
|
+
let data = extractSharedData(from: mockContext)
|
|
136
|
+
|
|
137
|
+
// Then
|
|
138
|
+
XCTAssertNotNil(data)
|
|
139
|
+
XCTAssertEqual(data?["text"] as? String, unicodeText)
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// MARK: - Get Shared Data - URL Tests
|
|
143
|
+
|
|
144
|
+
func testGetSharedData_ExtractsURL() {
|
|
145
|
+
// Given
|
|
146
|
+
let testURL = URL(string: "https://example.com")!
|
|
147
|
+
mockContext.addMockURLItem(testURL)
|
|
148
|
+
|
|
149
|
+
// When
|
|
150
|
+
let data = extractSharedData(from: mockContext)
|
|
151
|
+
|
|
152
|
+
// Then
|
|
153
|
+
XCTAssertNotNil(data)
|
|
154
|
+
XCTAssertEqual(data?["url"] as? String, testURL.absoluteString)
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
func testGetSharedData_ExtractsURLWithQueryParameters() {
|
|
158
|
+
// Given
|
|
159
|
+
let testURL = URL(string: "https://example.com/path?key1=value1&key2=value2")!
|
|
160
|
+
mockContext.addMockURLItem(testURL)
|
|
161
|
+
|
|
162
|
+
// When
|
|
163
|
+
let data = extractSharedData(from: mockContext)
|
|
164
|
+
|
|
165
|
+
// Then
|
|
166
|
+
XCTAssertNotNil(data)
|
|
167
|
+
XCTAssertEqual(data?["url"] as? String, testURL.absoluteString)
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
func testGetSharedData_ExtractsURLWithFragment() {
|
|
171
|
+
// Given
|
|
172
|
+
let testURL = URL(string: "https://example.com/page#section")!
|
|
173
|
+
mockContext.addMockURLItem(testURL)
|
|
174
|
+
|
|
175
|
+
// When
|
|
176
|
+
let data = extractSharedData(from: mockContext)
|
|
177
|
+
|
|
178
|
+
// Then
|
|
179
|
+
XCTAssertNotNil(data)
|
|
180
|
+
XCTAssertEqual(data?["url"] as? String, testURL.absoluteString)
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
func testGetSharedData_ExtractsCustomSchemeURL() {
|
|
184
|
+
// Given
|
|
185
|
+
let testURL = URL(string: "myapp://open/path")!
|
|
186
|
+
mockContext.addMockURLItem(testURL)
|
|
187
|
+
|
|
188
|
+
// When
|
|
189
|
+
let data = extractSharedData(from: mockContext)
|
|
190
|
+
|
|
191
|
+
// Then
|
|
192
|
+
XCTAssertNotNil(data)
|
|
193
|
+
XCTAssertEqual(data?["url"] as? String, testURL.absoluteString)
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// MARK: - Get Shared Data - Image Tests
|
|
197
|
+
|
|
198
|
+
func testGetSharedData_ExtractsSingleImage() {
|
|
199
|
+
// Given
|
|
200
|
+
let testImage = createTestImage()
|
|
201
|
+
mockContext.addMockImageItem(testImage)
|
|
202
|
+
|
|
203
|
+
// When
|
|
204
|
+
let data = extractSharedData(from: mockContext)
|
|
205
|
+
|
|
206
|
+
// Then
|
|
207
|
+
XCTAssertNotNil(data)
|
|
208
|
+
let images = data?["images"] as? [String]
|
|
209
|
+
XCTAssertNotNil(images)
|
|
210
|
+
XCTAssertEqual(images?.count, 1)
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
func testGetSharedData_ExtractsMultipleImages() {
|
|
214
|
+
// Given
|
|
215
|
+
mockContext.addMockImageItem(createTestImage())
|
|
216
|
+
mockContext.addMockImageItem(createTestImage())
|
|
217
|
+
mockContext.addMockImageItem(createTestImage())
|
|
218
|
+
|
|
219
|
+
// When
|
|
220
|
+
let data = extractSharedData(from: mockContext)
|
|
221
|
+
|
|
222
|
+
// Then
|
|
223
|
+
XCTAssertNotNil(data)
|
|
224
|
+
let images = data?["images"] as? [String]
|
|
225
|
+
XCTAssertNotNil(images)
|
|
226
|
+
XCTAssertEqual(images?.count, 3)
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// MARK: - Get Shared Data - Mixed Content Tests
|
|
230
|
+
|
|
231
|
+
func testGetSharedData_ExtractsMixedContent() {
|
|
232
|
+
// Given
|
|
233
|
+
mockContext.addMockTextItem("Sample text")
|
|
234
|
+
mockContext.addMockURLItem(URL(string: "https://example.com")!)
|
|
235
|
+
mockContext.addMockImageItem(createTestImage())
|
|
236
|
+
|
|
237
|
+
// When
|
|
238
|
+
let data = extractSharedData(from: mockContext)
|
|
239
|
+
|
|
240
|
+
// Then
|
|
241
|
+
XCTAssertNotNil(data)
|
|
242
|
+
XCTAssertEqual(data?["text"] as? String, "Sample text")
|
|
243
|
+
XCTAssertEqual(data?["url"] as? String, "https://example.com")
|
|
244
|
+
let images = data?["images"] as? [String]
|
|
245
|
+
XCTAssertNotNil(images)
|
|
246
|
+
XCTAssertEqual(images?.count, 1)
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
func testGetSharedData_HandlesEmptyAttachments() {
|
|
250
|
+
// Given
|
|
251
|
+
let item = NSExtensionItem()
|
|
252
|
+
item.attachments = []
|
|
253
|
+
mockContext.mockInputItems = [item]
|
|
254
|
+
|
|
255
|
+
// When
|
|
256
|
+
let data = extractSharedData(from: mockContext)
|
|
257
|
+
|
|
258
|
+
// Then
|
|
259
|
+
XCTAssertNil(data)
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// MARK: - Open Host App Tests
|
|
263
|
+
|
|
264
|
+
func testOpenHostApp_CreatesCorrectURL() {
|
|
265
|
+
// Given
|
|
266
|
+
let path = "home/profile"
|
|
267
|
+
let expectedScheme = "com.example.app"
|
|
268
|
+
|
|
269
|
+
// When/Then
|
|
270
|
+
let url = createHostAppURL(bundleId: expectedScheme, path: path)
|
|
271
|
+
XCTAssertEqual(url?.scheme, expectedScheme)
|
|
272
|
+
XCTAssertTrue(url?.absoluteString.contains(path) ?? false)
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
func testOpenHostApp_RemovesShareExtensionSuffix() {
|
|
276
|
+
// Given
|
|
277
|
+
let extensionBundleId = "com.example.app.ShareExtension"
|
|
278
|
+
let expectedAppBundleId = "com.example.app"
|
|
279
|
+
|
|
280
|
+
// When
|
|
281
|
+
let appBundleId = removeExtensionSuffix(from: extensionBundleId)
|
|
282
|
+
|
|
283
|
+
// Then
|
|
284
|
+
XCTAssertEqual(appBundleId, expectedAppBundleId)
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
func testOpenHostApp_RemovesShareSuffix() {
|
|
288
|
+
// Given
|
|
289
|
+
let extensionBundleId = "com.example.app.share"
|
|
290
|
+
let expectedAppBundleId = "com.example.app"
|
|
291
|
+
|
|
292
|
+
// When
|
|
293
|
+
let appBundleId = removeExtensionSuffix(from: extensionBundleId)
|
|
294
|
+
|
|
295
|
+
// Then
|
|
296
|
+
XCTAssertEqual(appBundleId, expectedAppBundleId)
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
func testOpenHostApp_RemovesActionSuffix() {
|
|
300
|
+
// Given
|
|
301
|
+
let extensionBundleId = "com.example.app.action"
|
|
302
|
+
let expectedAppBundleId = "com.example.app"
|
|
303
|
+
|
|
304
|
+
// When
|
|
305
|
+
let appBundleId = removeExtensionSuffix(from: extensionBundleId)
|
|
306
|
+
|
|
307
|
+
// Then
|
|
308
|
+
XCTAssertEqual(appBundleId, expectedAppBundleId)
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
func testOpenHostApp_RemovesClipSuffix() {
|
|
312
|
+
// Given
|
|
313
|
+
let extensionBundleId = "com.example.app.clip"
|
|
314
|
+
let expectedAppBundleId = "com.example.app"
|
|
315
|
+
|
|
316
|
+
// When
|
|
317
|
+
let appBundleId = removeExtensionSuffix(from: extensionBundleId)
|
|
318
|
+
|
|
319
|
+
// Then
|
|
320
|
+
XCTAssertEqual(appBundleId, expectedAppBundleId)
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
func testOpenHostApp_HandlesNoBundleIdentifier() {
|
|
324
|
+
// This is an edge case - should handle gracefully
|
|
325
|
+
let appBundleId = removeExtensionSuffix(from: "")
|
|
326
|
+
XCTAssertEqual(appBundleId, "")
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
func testOpenHostApp_WithEmptyPath() {
|
|
330
|
+
// Given
|
|
331
|
+
let path = ""
|
|
332
|
+
let bundleId = "com.example.app"
|
|
333
|
+
|
|
334
|
+
// When
|
|
335
|
+
let url = createHostAppURL(bundleId: bundleId, path: path)
|
|
336
|
+
|
|
337
|
+
// Then
|
|
338
|
+
XCTAssertNotNil(url)
|
|
339
|
+
XCTAssertEqual(url?.scheme, bundleId)
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
func testOpenHostApp_WithDeepLinkPath() {
|
|
343
|
+
// Given
|
|
344
|
+
let path = "product/123/details"
|
|
345
|
+
let bundleId = "com.example.app"
|
|
346
|
+
|
|
347
|
+
// When
|
|
348
|
+
let url = createHostAppURL(bundleId: bundleId, path: path)
|
|
349
|
+
|
|
350
|
+
// Then
|
|
351
|
+
XCTAssertNotNil(url)
|
|
352
|
+
XCTAssertTrue(url?.absoluteString.contains(path) ?? false)
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
func testOpenHostApp_WithSpecialCharactersInPath() {
|
|
356
|
+
// Given
|
|
357
|
+
let path = "search?query=test&filter=all"
|
|
358
|
+
let bundleId = "com.example.app"
|
|
359
|
+
|
|
360
|
+
// When
|
|
361
|
+
let url = createHostAppURL(bundleId: bundleId, path: path)
|
|
362
|
+
|
|
363
|
+
// Then
|
|
364
|
+
XCTAssertNotNil(url)
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
// MARK: - Edge Cases Tests
|
|
368
|
+
|
|
369
|
+
func testMultipleExtensionItemsProcessing() {
|
|
370
|
+
// Given
|
|
371
|
+
let item1 = NSExtensionItem()
|
|
372
|
+
let itemProvider1 = NSItemProvider(item: "text1" as NSString, typeIdentifier: "public.plain-text")
|
|
373
|
+
item1.attachments = [itemProvider1]
|
|
374
|
+
|
|
375
|
+
let item2 = NSExtensionItem()
|
|
376
|
+
let itemProvider2 = NSItemProvider(item: "text2" as NSString, typeIdentifier: "public.plain-text")
|
|
377
|
+
item2.attachments = [itemProvider2]
|
|
378
|
+
|
|
379
|
+
mockContext.mockInputItems = [item1, item2]
|
|
380
|
+
|
|
381
|
+
// When
|
|
382
|
+
let data = extractSharedData(from: mockContext)
|
|
383
|
+
|
|
384
|
+
// Then
|
|
385
|
+
XCTAssertNotNil(data)
|
|
386
|
+
// Should extract from first item with text
|
|
387
|
+
XCTAssertNotNil(data?["text"] as? String)
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
func testExtensionContext_NilAttachments() {
|
|
391
|
+
// Given
|
|
392
|
+
let item = NSExtensionItem()
|
|
393
|
+
item.attachments = nil
|
|
394
|
+
mockContext.mockInputItems = [item]
|
|
395
|
+
|
|
396
|
+
// When
|
|
397
|
+
let data = extractSharedData(from: mockContext)
|
|
398
|
+
|
|
399
|
+
// Then
|
|
400
|
+
XCTAssertNil(data)
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
// MARK: - Performance Tests
|
|
404
|
+
|
|
405
|
+
func testPerformance_ExtractLargeText() {
|
|
406
|
+
// Given
|
|
407
|
+
let largeText = String(repeating: "Lorem ipsum dolor sit amet. ", count: 1000)
|
|
408
|
+
mockContext.addMockTextItem(largeText)
|
|
409
|
+
|
|
410
|
+
measure {
|
|
411
|
+
_ = extractSharedData(from: mockContext)
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
func testPerformance_ExtractMultipleImages() {
|
|
416
|
+
// Given
|
|
417
|
+
for _ in 0..<10 {
|
|
418
|
+
mockContext.addMockImageItem(createTestImage())
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
measure {
|
|
422
|
+
_ = extractSharedData(from: mockContext)
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
// MARK: - Helper Methods
|
|
427
|
+
|
|
428
|
+
private func extractSharedData(from context: MockExtensionContext) -> [String: Any]? {
|
|
429
|
+
guard let extensionItem = context.inputItems.first as? NSExtensionItem,
|
|
430
|
+
let attachments = extensionItem.attachments else {
|
|
431
|
+
return nil
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
var result: [String: Any] = [:]
|
|
435
|
+
|
|
436
|
+
for attachment in attachments {
|
|
437
|
+
if attachment.hasItemConformingToTypeIdentifier("public.plain-text") {
|
|
438
|
+
let expectation = XCTestExpectation(description: "Load text")
|
|
439
|
+
attachment.loadItem(forTypeIdentifier: "public.plain-text", options: nil) { data, error in
|
|
440
|
+
if let text = data as? String {
|
|
441
|
+
result["text"] = text
|
|
442
|
+
}
|
|
443
|
+
expectation.fulfill()
|
|
444
|
+
}
|
|
445
|
+
wait(for: [expectation], timeout: 2.0)
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
if attachment.hasItemConformingToTypeIdentifier("public.url") {
|
|
449
|
+
let expectation = XCTestExpectation(description: "Load URL")
|
|
450
|
+
attachment.loadItem(forTypeIdentifier: "public.url", options: nil) { data, error in
|
|
451
|
+
if let url = data as? URL {
|
|
452
|
+
result["url"] = url.absoluteString
|
|
453
|
+
}
|
|
454
|
+
expectation.fulfill()
|
|
455
|
+
}
|
|
456
|
+
wait(for: [expectation], timeout: 2.0)
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
if attachment.hasItemConformingToTypeIdentifier("public.image") {
|
|
460
|
+
let expectation = XCTestExpectation(description: "Load image")
|
|
461
|
+
attachment.loadItem(forTypeIdentifier: "public.image", options: nil) { data, error in
|
|
462
|
+
if let url = data as? URL {
|
|
463
|
+
var images = result["images"] as? [String] ?? []
|
|
464
|
+
images.append(url.absoluteString)
|
|
465
|
+
result["images"] = images
|
|
466
|
+
}
|
|
467
|
+
expectation.fulfill()
|
|
468
|
+
}
|
|
469
|
+
wait(for: [expectation], timeout: 2.0)
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
return result.isEmpty ? nil : result
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
private func removeExtensionSuffix(from bundleId: String) -> String {
|
|
477
|
+
let extensionSuffixes = [".ShareExtension", ".share", ".action", ".clip"]
|
|
478
|
+
var result = bundleId
|
|
479
|
+
|
|
480
|
+
for suffix in extensionSuffixes {
|
|
481
|
+
result = result.replacingOccurrences(of: suffix, with: "")
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
return result
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
private func createHostAppURL(bundleId: String, path: String) -> URL? {
|
|
488
|
+
return URL(string: "\(bundleId)://\(path)")
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
private func createTestImage(size: CGSize = CGSize(width: 100, height: 100)) -> UIImage {
|
|
492
|
+
UIGraphicsBeginImageContextWithOptions(size, false, 1.0)
|
|
493
|
+
defer { UIGraphicsEndImageContext() }
|
|
494
|
+
|
|
495
|
+
let context = UIGraphicsGetCurrentContext()
|
|
496
|
+
context?.setFillColor(UIColor.blue.cgColor)
|
|
497
|
+
context?.fill(CGRect(origin: .zero, size: size))
|
|
498
|
+
|
|
499
|
+
return UIGraphicsGetImageFromCurrentImageContext() ?? UIImage()
|
|
500
|
+
}
|
|
501
|
+
}
|