Skip to content

Commit dad4233

Browse files
unit test added and updated
1 parent dc111f3 commit dad4233

File tree

4 files changed

+37
-6
lines changed

4 files changed

+37
-6
lines changed

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

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

1315
init(timestamp: Instana.Types.Milliseconds = Date().millisecondsSince1970,

Sources/InstanaAgent/Beacons/CoreBeacon/CoreBeaconFactory.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ 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
112113
if !beacon.viewInternalCPMetaMap.isEmpty {
113114
for (key, value) in beacon.viewInternalCPMetaMap {
114115
im![key] = value

Tests/InstanaAgentTests/Beacons/Beacon Types/ViewChangeBeaconTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,14 @@ class ViewChangeBeaconTests: InstanaTestCase {
117117

118118
func test_init_viewInternalMetaMap() {
119119
let vcBeacon = ViewChange(timestamp: testTimestamp, viewName: testViewName,
120-
accessibilityLabel: nil, navigationItemTitle: nil, className: nil,viewInternalMetaMap: testViewInternalMetaMap)
121-
XCTAssertEqual(vcBeacon.viewInternalMetaMap,testViewInternalMetaMap)
120+
accessibilityLabel: nil, navigationItemTitle: nil, className: nil,viewInternalCPMetaMap: testViewInternalMetaMap)
121+
XCTAssertEqual(vcBeacon.viewInternalCPMetaMap,testViewInternalMetaMap)
122122
}
123123

124124
func test_init_viewInternalMetaMap_empty() {
125125
let vcBeacon = ViewChange(timestamp: testTimestamp, viewName: testViewName,
126126
accessibilityLabel: nil, navigationItemTitle: nil, className: nil)
127-
XCTAssertEqual(vcBeacon.viewInternalMetaMap,[:])
127+
XCTAssertEqual(vcBeacon.viewInternalCPMetaMap,[:])
128128
}
129129

130130

Tests/InstanaAgentTests/InstanaTests.swift

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -828,23 +828,51 @@ class InstanaTests: InstanaTestCase {
828828
AssertFalse(Instana.collectionEnabled)
829829
}
830830

831-
func test_setViewMetaCPInternal_called(){
831+
func test_setViewMetaCPInternal_called_negative(){
832832
// Given
833833
let session = InstanaSession.mock(configuration: .mock())
834834

835835
var viewChangeBeaconCount = 0
836836
var capturedViewInternalMetaMap: [String: String]? = nil
837837
let reporter = MockReporter {
838838
if let viewChange = $0 as? ViewChange {
839-
capturedViewInternalMetaMap = viewChange.viewInternalMetaMap
839+
capturedViewInternalMetaMap = viewChange.viewInternalCPMetaMap
840840
viewChangeBeaconCount += 1
841841
}
842842
}
843843
Instana.current = Instana(session: session, monitors: Monitors(session, reporter: reporter))
844844

845845
let testViewInternalMetaMap = ["key1": "value1", "key2": "value2"]
846846
// When
847-
Instana.setViewMetaCPInternal(name: "ScreenName", viewInternalMetaMap:testViewInternalMetaMap)
847+
Instana.setViewMetaCPInternal(name: "ScreenName", viewInternalCPMetaMap:testViewInternalMetaMap)
848+
849+
Instana.current?.setViewInternal(name: nil) // nil view name should not trigger ViewChange beacon
850+
Thread.sleep(forTimeInterval: 1)
851+
852+
// Then
853+
AssertEqualAndNotNil(viewChangeBeaconCount, 0)
854+
AssertEqualAndNotNil(capturedViewInternalMetaMap, nil)
855+
}
856+
857+
func test_setViewMetaCPInternal_called_positive(){
858+
// Given
859+
let session = InstanaSession.mock(configuration: .mock())
860+
861+
var viewChangeBeaconCount = 0
862+
var capturedViewInternalMetaMap: [String: String]? = nil
863+
let reporter = MockReporter {
864+
if let viewChange = $0 as? ViewChange {
865+
capturedViewInternalMetaMap = viewChange.viewInternalCPMetaMap
866+
viewChangeBeaconCount += 1
867+
}
868+
}
869+
Instana.current = Instana(session: session, monitors: Monitors(session, reporter: reporter))
870+
871+
let testViewInternalMetaMap = ["settings.route.name": "value1", "widget.name": "value2"]
872+
873+
874+
// When
875+
Instana.setViewMetaCPInternal(name: "ScreenName", viewInternalCPMetaMap:testViewInternalMetaMap)
848876

849877
Instana.current?.setViewInternal(name: nil) // nil view name should not trigger ViewChange beacon
850878
Thread.sleep(forTimeInterval: 1)

0 commit comments

Comments
 (0)