Skip to content

Commit

Permalink
Merge pull request #474 from DataDog/ncreated/RUMM-1324-fix-test-issu…
Browse files Browse the repository at this point in the history
…es-on-iOS-11-and-12

RUMM-1324 Fix RUM views tracking issue for iOS 11 (and make tests green for 11.x and 12.x)
  • Loading branch information
ncreated authored Apr 27, 2021
2 parents cf630d6 + f5465a3 commit 1cd1a46
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ internal class TSConsentSettingViewController: UIViewController {

@IBOutlet weak var consentValueControl: UISegmentedControl!

override func viewDidLoad() {
super.viewDidLoad()
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)

switch homeViewController.currentConsentValue {
case .granted: consentValueControl.selectedSegmentIndex = 0
Expand Down
5 changes: 4 additions & 1 deletion Sources/Datadog/Utils/UIKitExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@ internal extension UIViewController {
}

internal extension Bundle {
var isUIKit: Bool { bundleURL.lastPathComponent == "UIKitCore.framework" }
var isUIKit: Bool {
return bundleURL.lastPathComponent == "UIKitCore.framework" // on iOS 12+
|| bundleURL.lastPathComponent == "UIKit.framework" // on iOS 11
}
}
20 changes: 11 additions & 9 deletions Tests/DatadogTests/Datadog/Core/FeatureTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ class FeatureStorageTests: XCTestCase {
let currentConsent = consentProvider.currentValue
let nextConsent: TrackingConsent = .mockRandom(otherThan: currentConsent)

let stringValue = "current consent: \(currentConsent), next consent: \(nextConsent)"
storage.writer.write(value: stringValue)
// We write array because prior to iOS 13 the top-level element passed to JSON encoder must be array or object
let data = ["current consent: \(currentConsent), next consent: \(nextConsent)"]
storage.writer.write(value: data)

consentProvider.changeConsent(to: nextConsent)
}
Expand All @@ -46,10 +47,10 @@ class FeatureStorageTests: XCTestCase {

let expectedAuthorizedValues = [
// Data collected with `.granted` consent is allowed no matter of the next consent
"\"current consent: \(TrackingConsent.granted), next consent: \(TrackingConsent.pending)\"",
"\"current consent: \(TrackingConsent.granted), next consent: \(TrackingConsent.notGranted)\"",
"[\"current consent: \(TrackingConsent.granted), next consent: \(TrackingConsent.pending)\"]",
"[\"current consent: \(TrackingConsent.granted), next consent: \(TrackingConsent.notGranted)\"]",
// Data collected with `.pending` consent is allowed only if the next consent was `.granted`
"\"current consent: \(TrackingConsent.pending), next consent: \(TrackingConsent.granted)\"",
"[\"current consent: \(TrackingConsent.pending), next consent: \(TrackingConsent.granted)\"]",
]

XCTAssertEqual(
Expand All @@ -71,8 +72,9 @@ class FeatureStorageTests: XCTestCase {
// swiftlint:disable opening_brace
callConcurrently(
closures: [
{ storage.writer.write(value: "regular write") },
{ storage.arbitraryAuthorizedWriter.write(value: "arbitrary write") }
// We write arrays because prior to iOS 13 the top-level element passed to JSON encoder must be array or object
{ storage.writer.write(value: ["regular write"]) },
{ storage.arbitraryAuthorizedWriter.write(value: ["arbitrary write"]) }
],
iterations: 25
)
Expand All @@ -81,8 +83,8 @@ class FeatureStorageTests: XCTestCase {
// Then
let dataWritten = readAllAuthorizedDataWritten(to: storage, limit: 50)
.map { $0.utf8String }
XCTAssertEqual(dataWritten.filter { $0 == "\"regular write\"" }.count, 25)
XCTAssertEqual(dataWritten.filter { $0 == "\"arbitrary write\"" }.count, 25)
XCTAssertEqual(dataWritten.filter { $0 == "[\"regular write\"]" }.count, 25)
XCTAssertEqual(dataWritten.filter { $0 == "[\"arbitrary write\"]" }.count, 25)
}

// MARK: - Helpers
Expand Down

0 comments on commit 1cd1a46

Please sign in to comment.