Skip to content

Commit

Permalink
Merge pull request #997 from DataDog/maxep/RUMM-2432/fix-user-action-…
Browse files Browse the repository at this point in the history
…drop

RUMM-2508 Fix manual User Action dropped if a new view start
  • Loading branch information
maxep authored Sep 16, 2022
2 parents f669620 + b85a965 commit bdcabd2
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Unreleased

- [BUGFIX] Fix manual User Action dropped if a new view start. See [#997][]

# 1.12.0-beta3 / 30-08-2022

### Changes
Expand Down Expand Up @@ -417,6 +419,7 @@
[#950]: https://github.com/DataDog/dd-sdk-ios/issues/950
[#964]: https://github.com/DataDog/dd-sdk-ios/issues/964
[#973]: https://github.com/DataDog/dd-sdk-ios/issues/973
[#997]: https://github.com/DataDog/dd-sdk-ios/issues/997
[@00fa9a]: https://github.com/00FA9A
[@britton-earnin]: https://github.com/Britton-Earnin
[@hengyu]: https://github.com/Hengyu
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ internal class RUMUserActionScope: RUMScope, RUMContextProvider {

lastActivityTime = command.time
switch command {
case is RUMStopViewCommand:
case is RUMStartViewCommand, is RUMStopViewCommand:
sendActionEvent(completionTime: command.time, on: command, context: context, writer: writer)
return false
case let command as RUMStopUserActionCommand:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,48 @@ class RUMUserActionScopeTests: XCTestCase {
XCTAssertEqual(recordedAction.os?.name, "device-os")
}

func testGivenActiveUserAction_whenNewViewStart_itSendsUserActionEvent() throws {
let scope = RUMViewScope.mockWith(
parent: parent,
dependencies: .mockAny(),
identity: mockView,
attributes: [:],
startTime: Date()
)
XCTAssertTrue(
scope.process(
command: RUMStartViewCommand.mockWith(identity: mockView),
context: context,
writer: writer
)
)
let mockUserActionCmd = RUMAddUserActionCommand.mockAny()
XCTAssertTrue(
scope.process(
command: mockUserActionCmd,
context: context,
writer: writer
)
)
XCTAssertFalse(
scope.process(
command: RUMStartViewCommand.mockAny(),
context: context,
writer: writer
)
)

let recordedActionEvents = writer.events(ofType: RUMActionEvent.self)
XCTAssertEqual(recordedActionEvents.count, 1)
let recordedAction = try XCTUnwrap(recordedActionEvents.last)
XCTAssertEqual(recordedAction.action.type.rawValue, String(describing: mockUserActionCmd.actionType))
XCTAssertEqual(recordedAction.dd.session?.plan, .plan1, "All RUM events should use RUM Lite plan")
XCTAssertEqual(recordedAction.source, .ios)
XCTAssertEqual(recordedAction.service, "test-service")
XCTAssertEqual(recordedAction.device?.name, "device-name")
XCTAssertEqual(recordedAction.os?.name, "device-os")
}

func testGivenCustomSource_whenActionIsSent_itSendsCustomSource() throws {
let source = String.mockAnySource()
let customContext: DatadogV1Context = .mockWith(configuration: .mockWith(source: source))
Expand Down

0 comments on commit bdcabd2

Please sign in to comment.