diff --git a/LocalPackages/DataBrokerProtection/Sources/DataBrokerProtection/UI/UIMapper.swift b/LocalPackages/DataBrokerProtection/Sources/DataBrokerProtection/UI/UIMapper.swift index 68e7c8671d..04001ca81e 100644 --- a/LocalPackages/DataBrokerProtection/Sources/DataBrokerProtection/UI/UIMapper.swift +++ b/LocalPackages/DataBrokerProtection/Sources/DataBrokerProtection/UI/UIMapper.swift @@ -373,7 +373,14 @@ private extension Array where Element == [BrokerProfileQueryData] { /// - Returns: An array of `[BrokerProfileQueryData]` values sorted by the first `lastRunDate` of each element func sortedByLastRunDate() -> Self { self.sorted { lhs, rhs in - lhs.first?.scanJobData.lastRunDate < rhs.first?.scanJobData.lastRunDate + let lhsDate = lhs.first?.scanJobData.lastRunDate + let rhsDate = rhs.first?.scanJobData.lastRunDate + + if lhsDate == rhsDate { + return lhs.first?.dataBroker.name ?? "" < rhs.first?.dataBroker.name ?? "" + } else { + return lhsDate < rhsDate + } } } } diff --git a/LocalPackages/DataBrokerProtection/Tests/DataBrokerProtectionTests/MapperToUITests.swift b/LocalPackages/DataBrokerProtection/Tests/DataBrokerProtectionTests/MapperToUITests.swift index 02a1efb852..a47d13d87a 100644 --- a/LocalPackages/DataBrokerProtection/Tests/DataBrokerProtectionTests/MapperToUITests.swift +++ b/LocalPackages/DataBrokerProtection/Tests/DataBrokerProtectionTests/MapperToUITests.swift @@ -362,26 +362,28 @@ final class MapperToUITests: XCTestCase { func testBrokersWithMixedScanProgress_areOrderedByLastRunDate_andHaveCorrectStatus() { // Given + let minusTwoHours = Date.minusTwoHours + let minusThreeHours = Date.minusThreeHours let brokerProfileQueryData: [BrokerProfileQueryData] = [ .mock(dataBrokerName: "Broker #1", lastRunDate: Date()), .mock(dataBrokerName: "Broker #1", lastRunDate: Date()), - .mock(dataBrokerName: "Broker #1", lastRunDate: .minusTwoHours), + .mock(dataBrokerName: "Broker #1", lastRunDate: minusTwoHours), .mock(dataBrokerName: "Broker #2"), .mock(dataBrokerName: "Broker #2", lastRunDate: .minusOneHour), - .mock(dataBrokerName: "Broker #2", lastRunDate: .minusThreeHours), - .mock(dataBrokerName: "Broker #3", lastRunDate: .minusTwoHours), + .mock(dataBrokerName: "Broker #2", lastRunDate: minusThreeHours), + .mock(dataBrokerName: "Broker #3", lastRunDate: minusTwoHours), .mock(dataBrokerName: "Broker #3"), .mock(dataBrokerName: "Broker #3", lastRunDate: Date()), .mock(dataBrokerName: "Broker #4"), .mock(dataBrokerName: "Broker #5"), - .mock(dataBrokerName: "Broker #7", lastRunDate: .minusThreeHours), - .mock(dataBrokerName: "Broker #6", lastRunDate: .minusThreeHours) + .mock(dataBrokerName: "Broker #7", lastRunDate: minusThreeHours), + .mock(dataBrokerName: "Broker #6", lastRunDate: minusThreeHours) ] let expected: [DBPUIScanProgress.ScannedBroker] = [ .mock("Broker #2", status: .inProgress), - .mock("Broker #7", status: .completed), .mock("Broker #6", status: .completed), + .mock("Broker #7", status: .completed), .mock("Broker #1", status: .completed), .mock("Broker #3", status: .inProgress) ]