Skip to content

Commit 6329f6a

Browse files
added ut for max count, added max count logic
1 parent ad98be9 commit 6329f6a

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

Sources/InstanaAgent/Beacons/Beacons Types/ViewChange.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class ViewChange: Beacon {
88
var accessibilityLabel: String?
99
var navigationItemTitle: String?
1010
var className: String?
11-
11+
1212
// Internal Meta only to be consumed by Flutter/React agents
1313
var viewInternalCPMetaMap: [String: String]
1414

@@ -37,7 +37,7 @@ class ViewChange: Beacon {
3737
}
3838
}
3939
for (key, value) in viewInternalCPMetaMap {
40-
self.viewInternalCPMetaMap[key] = value
40+
self.viewInternalCPMetaMap[key] = ViewChange.validate(viewName: value)
4141
}
4242
super.init(timestamp: timestamp, viewName: canonicalName)
4343
}

Sources/InstanaAgent/Beacons/CoreBeacon/CoreBeaconFactory.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ extension CoreBeacon {
109109
if beacon.className != nil {
110110
im![internalMetaDataKeyView_className] = beacon.className!
111111
}
112-
// Only when there is view meta available from crossplatfrom agents(Flutter/React-Native) thats added with every view change
113112
if !beacon.viewInternalCPMetaMap.isEmpty {
114113
for (key, value) in beacon.viewInternalCPMetaMap {
115114
im![key] = value

Tests/InstanaAgentTests/InstanaTests.swift

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -881,4 +881,37 @@ class InstanaTests: InstanaTestCase {
881881
AssertEqualAndNotNil(viewChangeBeaconCount, 1)
882882
AssertEqualAndNotNil(capturedViewInternalMetaMap, testViewInternalMetaMap)
883883
}
884+
885+
func test_setViewMetaCPInternal_called_with_max_value_length(){
886+
// Given
887+
let session = InstanaSession.mock(configuration: .mock())
888+
889+
var viewChangeBeaconCount = 0
890+
var capturedViewInternalMetaMap: [String: String]? = nil
891+
let reporter = MockReporter {
892+
if let viewChange = $0 as? ViewChange {
893+
capturedViewInternalMetaMap = viewChange.viewInternalCPMetaMap
894+
viewChangeBeaconCount += 1
895+
}
896+
}
897+
Instana.current = Instana(session: session, monitors: Monitors(session, reporter: reporter))
898+
var randomString = ""
899+
for _ in 0..<InstanaProperties.viewMaxLength+3 {
900+
let randomCharacter = Character(UnicodeScalar(UInt32.random(in: 65...90)) ?? "A") // A-Z
901+
randomString.append(randomCharacter)
902+
}
903+
904+
let testViewInternalMetaMap = ["settings.route.name": randomString, "widget.name": "value2"]
905+
906+
907+
// When
908+
Instana.setViewMetaCPInternal(name: "ScreenName", viewInternalCPMetaMap:testViewInternalMetaMap)
909+
910+
Instana.current?.setViewInternal(name: nil) // nil view name should not trigger ViewChange beacon
911+
Thread.sleep(forTimeInterval: 1)
912+
913+
// Then
914+
AssertEqualAndNotNil(viewChangeBeaconCount, 1)
915+
AssertEqualAndNotNil(capturedViewInternalMetaMap?["settings.route.name"]?.count, InstanaProperties.viewMaxLength)
916+
}
884917
}

0 commit comments

Comments
 (0)