Skip to content

Commit f623968

Browse files
committed
fix tests by ignoring test activityNames
1 parent 9d85cd5 commit f623968

File tree

2 files changed

+59
-30
lines changed

2 files changed

+59
-30
lines changed

apps/example/ios/Tests/FamilySelectionIdTests.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ class FamilySelectionIdTests: XCTestCase {
9191
let activitySelectionPrefixedConfigKey = tryGetActivitySelectionIdConfigKey(
9292
keyPrefix: SHIELD_CONFIGURATION_FOR_SELECTION_PREFIX,
9393
categoryToken: token.categoryTokens.first,
94+
onlyFamilySelectionIdsContainingMonitoredActivityNames: false
9495
)
9596

9697
XCTAssertEqual(
@@ -143,7 +144,8 @@ class FamilySelectionIdTests: XCTestCase {
143144
))
144145

145146
let matches = getPossibleFamilyActivitySelectionIds(
146-
categoryToken: tokenWithSocial.categoryTokens.first
147+
categoryToken: tokenWithSocial.categoryTokens.first,
148+
onlyFamilySelectionIdsContainingMonitoredActivityNames: false
147149
)
148150

149151
XCTAssertEqual(
@@ -169,7 +171,8 @@ class FamilySelectionIdTests: XCTestCase {
169171
setFamilyActivitySelectionById(id: "games", activitySelection: tokenWithGames)
170172

171173
let matches = getPossibleFamilyActivitySelectionIds(
172-
categoryToken: tokenWithGames.categoryTokens.first
174+
categoryToken: tokenWithGames.categoryTokens.first,
175+
onlyFamilySelectionIdsContainingMonitoredActivityNames: false
173176
)
174177

175178
XCTAssertEqual(
@@ -204,7 +207,8 @@ class FamilySelectionIdTests: XCTestCase {
204207
)
205208

206209
let matches = getPossibleFamilyActivitySelectionIds(
207-
categoryToken: tokenWithGames.categoryTokens.first
210+
categoryToken: tokenWithGames.categoryTokens.first,
211+
onlyFamilySelectionIdsContainingMonitoredActivityNames: false
208212
)
209213

210214
XCTAssertEqual(

packages/react-native-device-activity/ios/Shared.swift

Lines changed: 52 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ func updateShield(shieldId: String?, triggeredBy: String?, activitySelectionId:
3737
let shieldId = shieldId ?? "default"
3838

3939
if var shieldConfiguration = userDefaults?.dictionary(
40-
forKey: "shieldConfiguration_\(shieldId)") {
40+
forKey: "shieldConfiguration_\(shieldId)")
41+
{
4142

4243
shieldConfiguration["shieldId"] = shieldId
4344
shieldConfiguration["triggeredBy"] = triggeredBy
@@ -53,7 +54,8 @@ func updateShield(shieldId: String?, triggeredBy: String?, activitySelectionId:
5354
}
5455

5556
if var shieldActions = userDefaults?.dictionary(
56-
forKey: "shieldActions_\(shieldId)") {
57+
forKey: "shieldActions_\(shieldId)")
58+
{
5759

5860
shieldActions["shieldId"] = shieldId
5961
shieldActions["triggeredBy"] = triggeredBy
@@ -175,7 +177,8 @@ func sendNotification(contents: [String: Any], placeholders: [String: String?])
175177

176178
// dataRequest which sends request to given URL and convert to Decodable Object
177179
func sendHttpRequest(with url: String, config: [String: Any], placeholders: [String: String?])
178-
-> URLSessionDataTask {
180+
-> URLSessionDataTask
181+
{
179182
// create the URL
180183
let url = URL(string: url)! // change the URL
181184

@@ -218,7 +221,8 @@ func sendHttpRequest(with url: String, config: [String: Any], placeholders: [Str
218221
do {
219222
// create json object from data
220223
if let json = try JSONSerialization.jsonObject(with: data, options: .mutableContainers)
221-
as? [String: Any] {
224+
as? [String: Any]
225+
{
222226
print(json)
223227
}
224228
} catch let error {
@@ -280,9 +284,11 @@ struct TextToReplaceWithOptionalSpecialTreatment {
280284
}
281285

282286
func getTextToReplaceWithOptionalSpecialTreatment(_ stringToReplace: String)
283-
-> TextToReplaceWithOptionalSpecialTreatment {
287+
-> TextToReplaceWithOptionalSpecialTreatment
288+
{
284289
if stringToReplace.starts(with: "{") && stringToReplace.hasSuffix("}")
285-
&& stringToReplace.contains(":") {
290+
&& stringToReplace.contains(":")
291+
{
286292
// remove prefix and suffix
287293
let trimmed = String(stringToReplace.dropFirst().dropLast())
288294
// split on : and return first part
@@ -309,15 +315,17 @@ func replacePlaceholdersInObject<T: Any>(
309315
if let specialTreatment = textToReplaceWithOptionalSpecialTreatment.specialTreatment {
310316
if specialTreatment == "asNumber" {
311317
if let placeholderValue = placeholders[
312-
textToReplaceWithOptionalSpecialTreatment.textToReplace] as? String {
318+
textToReplaceWithOptionalSpecialTreatment.textToReplace] as? String
319+
{
313320
if let numberValue = Double(placeholderValue) {
314321
retVal[key] = numberValue as? T
315322
}
316323
}
317324
}
318325
if specialTreatment == "userDefaults" {
319326
if let value = userDefaults?.string(
320-
forKey: textToReplaceWithOptionalSpecialTreatment.textToReplace) {
327+
forKey: textToReplaceWithOptionalSpecialTreatment.textToReplace)
328+
{
321329
retVal[key] = value as? T
322330
}
323331
}
@@ -355,7 +363,8 @@ func clearAllManagedSettingsStoreSettings() {
355363
@available(iOS 15.0, *)
356364
func getFamilyActivitySelectionIds() -> [FamilyActivitySelectionWithId] {
357365
if let familyActivitySelectionIds = userDefaults?.dictionary(
358-
forKey: "familyActivitySelectionIds") {
366+
forKey: "familyActivitySelectionIds")
367+
{
359368
return familyActivitySelectionIds.compactMap { (key: String, value: Any) in
360369
if let familyActivitySelectionStr = value as? String {
361370
let activitySelection = deserializeFamilyActivitySelection(
@@ -372,7 +381,8 @@ func getFamilyActivitySelectionIds() -> [FamilyActivitySelectionWithId] {
372381
@available(iOS 15.0, *)
373382
func getFamilyActivitySelectionById(id: String) -> FamilyActivitySelection? {
374383
if let familyActivitySelectionIds = userDefaults?.dictionary(
375-
forKey: FAMILY_ACTIVITY_SELECTION_ID_KEY) {
384+
forKey: FAMILY_ACTIVITY_SELECTION_ID_KEY)
385+
{
376386
if let familyActivitySelectionStr = familyActivitySelectionIds[id] as? String {
377387
let activitySelection = deserializeFamilyActivitySelection(
378388
familyActivitySelectionStr: familyActivitySelectionStr
@@ -385,7 +395,8 @@ func getFamilyActivitySelectionById(id: String) -> FamilyActivitySelection? {
385395

386396
func removeFamilyActivitySelectionById(id: String) {
387397
if var familyActivitySelectionIds = userDefaults?.dictionary(
388-
forKey: FAMILY_ACTIVITY_SELECTION_ID_KEY) {
398+
forKey: FAMILY_ACTIVITY_SELECTION_ID_KEY)
399+
{
389400
familyActivitySelectionIds.removeValue(forKey: id)
390401

391402
userDefaults?
@@ -400,7 +411,8 @@ func setFamilyActivitySelectionById(id: String, activitySelection: FamilyActivit
400411
)
401412

402413
if var familyActivitySelectionIds = userDefaults?.dictionary(
403-
forKey: FAMILY_ACTIVITY_SELECTION_ID_KEY) {
414+
forKey: FAMILY_ACTIVITY_SELECTION_ID_KEY)
415+
{
404416
familyActivitySelectionIds[id] = serialized
405417

406418
userDefaults?
@@ -416,7 +428,8 @@ func setFamilyActivitySelectionById(id: String, activitySelection: FamilyActivit
416428
@available(iOS 15.0, *)
417429
func renameFamilyActivitySelectionId(previousId: String, newId: String) {
418430
if var familyActivitySelectionIds = userDefaults?.dictionary(
419-
forKey: FAMILY_ACTIVITY_SELECTION_ID_KEY) {
431+
forKey: FAMILY_ACTIVITY_SELECTION_ID_KEY)
432+
{
420433
familyActivitySelectionIds[newId] = familyActivitySelectionIds[previousId]
421434
familyActivitySelectionIds.removeValue(forKey: previousId)
422435

@@ -430,14 +443,16 @@ func tryGetActivitySelectionIdConfigKey(
430443
keyPrefix: String,
431444
applicationToken: ApplicationToken? = nil,
432445
webDomainToken: WebDomainToken? = nil,
433-
categoryToken: ActivityCategoryToken? = nil
446+
categoryToken: ActivityCategoryToken? = nil,
447+
onlyFamilySelectionIdsContainingMonitoredActivityNames: Bool = true
434448
) -> String? {
435449
let familyActivitySelectionIds = getPossibleFamilyActivitySelectionIds(
436450
applicationToken: applicationToken,
437451
webDomainToken: webDomainToken,
438452
categoryToken: categoryToken,
439-
onlyFamilySelectionIdsContainingMonitoredActivityNames: true,
440-
sortByGranularity: true
453+
onlyFamilySelectionIdsContainingMonitoredActivityNames:
454+
onlyFamilySelectionIdsContainingMonitoredActivityNames,
455+
sortByGranularity: true,
441456
)
442457

443458
let activitySelection = familyActivitySelectionIds.first {
@@ -558,7 +573,8 @@ func getPossibleFamilyActivitySelectionIds(
558573

559574
@available(iOS 15.0, *)
560575
func deserializeFamilyActivitySelection(familyActivitySelectionStr: String)
561-
-> FamilyActivitySelection {
576+
-> FamilyActivitySelection
577+
{
562578
var activitySelection = FamilyActivitySelection()
563579

564580
let decoder = JSONDecoder()
@@ -604,7 +620,8 @@ func disableBlockAllMode(triggeredBy: String) {
604620
func setsIncludesEntireCategory(
605621
_ selection1: FamilyActivitySelection, _ selection2: FamilyActivitySelection
606622
)
607-
-> Bool {
623+
-> Bool
624+
{
608625
if #available(iOS 15.2, *) {
609626
let selection1Safe = selection1.includeEntireCategory || selection1.categoryTokens.count == 0
610627

@@ -618,7 +635,8 @@ func setsIncludesEntireCategory(
618635

619636
@available(iOS 15.0, *)
620637
func intersection(_ selection1: FamilyActivitySelection, _ selection2: FamilyActivitySelection)
621-
-> FamilyActivitySelection {
638+
-> FamilyActivitySelection
639+
{
622640
let applicationTokens = selection1.applicationTokens.intersection(
623641
selection2.applicationTokens
624642
)
@@ -681,7 +699,8 @@ func symmetricDifference(
681699

682700
@available(iOS 15.0, *)
683701
func difference(_ selection1: FamilyActivitySelection, _ selection2: FamilyActivitySelection)
684-
-> FamilyActivitySelection {
702+
-> FamilyActivitySelection
703+
{
685704
let applicationTokens = selection1.applicationTokens.subtracting(
686705
selection2.applicationTokens
687706
)
@@ -712,7 +731,8 @@ func difference(_ selection1: FamilyActivitySelection, _ selection2: FamilyActiv
712731

713732
@available(iOS 15.0, *)
714733
func union(_ selection1: FamilyActivitySelection, _ selection2: FamilyActivitySelection)
715-
-> FamilyActivitySelection {
734+
-> FamilyActivitySelection
735+
{
716736
let applicationTokens = selection1.applicationTokens.union(
717737
selection2.applicationTokens
718738
)
@@ -926,7 +946,7 @@ func updateBlock(triggeredBy: String) {
926946
"blocklistCategoryCount": currentBlocklist.categoryTokens.count,
927947
"whitelistAppCount": currentWhitelist.applicationTokens.count,
928948
"whitelistWebDomainCount": currentWhitelist.webDomainTokens.count,
929-
"whitelistCategoryCount": currentWhitelist.categoryTokens.count
949+
"whitelistCategoryCount": currentWhitelist.categoryTokens.count,
930950
], forKey: "lastBlockUpdate")
931951

932952
updateBlockInternal(
@@ -1010,7 +1030,8 @@ func getColor(color: [String: Double]?) -> UIColor? {
10101030
}
10111031

10121032
func userDefaultKeyForEvent(activityName: String, callbackName: String, eventName: String? = nil)
1013-
-> String {
1033+
-> String
1034+
{
10141035

10151036
let fullEventName =
10161037
eventName == nil
@@ -1131,7 +1152,8 @@ func shouldExecuteAction(
11311152
eventName: eventName
11321153
) {
11331154
if lastTriggeredAt >= skipIfAlreadyTriggeredBetweenFromDate
1134-
&& lastTriggeredAt <= skipIfAlreadyTriggeredBetweenToDate {
1155+
&& lastTriggeredAt <= skipIfAlreadyTriggeredBetweenToDate
1156+
{
11351157
logger.log(
11361158
"skipping executing actions for \(callbackName)\(eventName ?? "") because the last triggered time is between \(skipIfAlreadyTriggeredBetweenFromDate) and \(skipIfAlreadyTriggeredBetweenToDate)"
11371159
)
@@ -1155,7 +1177,8 @@ func shouldExecuteAction(
11551177
}
11561178
}
11571179

1158-
if let skipIfLargerEventRecordedAfter = skipIfLargerEventRecordedAfter, let eventName = eventName {
1180+
if let skipIfLargerEventRecordedAfter = skipIfLargerEventRecordedAfter, let eventName = eventName
1181+
{
11591182
if hasHigherTriggeredEvent(
11601183
activityName: activityName,
11611184
callbackName: callbackName,
@@ -1187,7 +1210,8 @@ func shouldExecuteAction(
11871210
}
11881211

11891212
if let skipIfLargerEventRecordedWithinMS = skipIfLargerEventRecordedWithinMS,
1190-
let eventName = eventName {
1213+
let eventName = eventName
1214+
{
11911215
let skipIfLargerEventRecordedAfter =
11921216
Date().timeIntervalSince1970 * 1000 - skipIfLargerEventRecordedWithinMS
11931217
if hasHigherTriggeredEvent(
@@ -1204,7 +1228,8 @@ func shouldExecuteAction(
12041228
}
12051229

12061230
if let skipIfLargerEventRecordedSinceIntervalStarted =
1207-
skipIfLargerEventRecordedSinceIntervalStarted, let eventName = eventName {
1231+
skipIfLargerEventRecordedSinceIntervalStarted, let eventName = eventName
1232+
{
12081233
if skipIfLargerEventRecordedSinceIntervalStarted {
12091234
if let skipIfLargerEventRecordedAfter = getLastTriggeredTimeFromUserDefaults(
12101235
activityName: activityName,

0 commit comments

Comments
 (0)