Skip to content

Commit

Permalink
Add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
yoanarios committed Jan 21, 2025
1 parent 50d8b58 commit f43dc26
Showing 1 changed file with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ final class BookmarksTelemetryTests: XCTestCase {
super.tearDown()
}

func testRecordBookmark_WhenAddedFolder_ThenGleanIsCalled() throws {
subject?.addBookmarkFolder()
func testRecordBookmark_WhenAddedBookmark_ThenGleanIsCalled() throws {
subject?.addBookmark(eventLabel: .bookmarksPanel)

let savedMetric = try XCTUnwrap(gleanWrapper.savedEvent as? EventMetricType<NoExtras>)
let expectedMetricType = type(of: GleanMetrics.Bookmarks.folderAdd)
let savedMetric = try XCTUnwrap(gleanWrapper.savedEvent as? LabeledMetricType<CounterMetricType>)
let expectedMetricType = type(of: GleanMetrics.Bookmarks.add)
let resultMetricType = type(of: savedMetric)
let debugMessage = TelemetryDebugMessage(expectedMetric: expectedMetricType, resultMetric: resultMetricType)
XCTAssert(resultMetricType == expectedMetricType, debugMessage.text)
XCTAssertEqual(gleanWrapper.recordEventNoExtraCalled, 1)
XCTAssertEqual(gleanWrapper.recordLabelCalled, 1)
}

func testRecordBookmark_WhenDeletedBookmark_ThenGleanIsCalled() throws {
subject?.deleteBookmark()
subject?.deleteBookmark(eventLabel: .bookmarksPanel)

let savedMetric = try XCTUnwrap(gleanWrapper.savedEvent as? LabeledMetricType<CounterMetricType>)
let expectedMetricType = type(of: GleanMetrics.Bookmarks.delete)
Expand Down Expand Up @@ -66,4 +66,15 @@ final class BookmarksTelemetryTests: XCTestCase {
XCTAssert(resultMetricType == expectedMetricType, debugMessage.text)
XCTAssertEqual(gleanWrapper.recordLabelCalled, 1)
}

func testRecordBookmark_WhenAddedFolder_ThenGleanIsCalled() throws {
subject?.addBookmarkFolder()

let savedMetric = try XCTUnwrap(gleanWrapper.savedEvent as? EventMetricType<NoExtras>)
let expectedMetricType = type(of: GleanMetrics.Bookmarks.folderAdd)
let resultMetricType = type(of: savedMetric)
let debugMessage = TelemetryDebugMessage(expectedMetric: expectedMetricType, resultMetric: resultMetricType)
XCTAssert(resultMetricType == expectedMetricType, debugMessage.text)
XCTAssertEqual(gleanWrapper.recordEventNoExtraCalled, 1)
}
}

0 comments on commit f43dc26

Please sign in to comment.