Skip to content

Commit

Permalink
Fix for Autofill sections not sorting correctly (#1677)
Browse files Browse the repository at this point in the history
Task/Issue URL: https://app.asana.com/0/1200930669568058/1205563071647976/f
Tech Design URL:
CC:

Description:
Fixes an issue where Autofill sections were not sorting correctly when sorted by date as the year was not being taken into account
  • Loading branch information
amddg44 authored Sep 29, 2023
1 parent d020765 commit 5782e9b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ struct PasswordManagementListSection {

struct DateMetadata: Equatable, Hashable, Comparable {
static func < (lhs: PasswordManagementListSection.DateMetadata, rhs: PasswordManagementListSection.DateMetadata) -> Bool {
return (lhs.month, lhs.year) < (rhs.month, rhs.year)
if lhs.year != rhs.year {
return lhs.year < rhs.year
} else {
return (lhs.month, lhs.year) < (rhs.month, rhs.year)
}
}

static let unknown = DateMetadata(title: "#", month: 0, year: 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ final class PasswordManagementListSectionTests: XCTestCase {
}
}

func testWhenSortingItemsByDate_AndMonthsAreDifferent_AndThereAreMultipleYears_ThenMultipleSectionsAreReturned() {
func testWhenSortingItemsByDate_AndMonthsAreDifferent_AndThereAreMultipleYears_ThenMultipleSectionsAreReturnedSortedAscending() {
let months = 1...12
let firstYearAccounts = months.map { login(named: "Login", month: $0, year: 2000) }
let secondYearAccounts = months.map { login(named: "Login", month: $0, year: 2001) }
Expand All @@ -124,6 +124,10 @@ final class PasswordManagementListSectionTests: XCTestCase {
for section in sections {
XCTAssertEqual(section.items.count, 1)
}

let expectedTitles = ["Dec 2001", "Nov 2001", "Oct 2001", "Sep 2001", "Aug 2001", "Jul 2001", "Jun 2001", "May 2001", "Apr 2001", "Mar 2001", "Feb 2001", "Jan 2001", "Dec 2000", "Nov 2000", "Oct 2000", "Sep 2000", "Aug 2000", "Jul 2000", "Jun 2000", "May 2000", "Apr 2000", "Mar 2000", "Feb 2000", "Jan 2000"]
let actualTitles = sections.map(\.title)
XCTAssertEqual(actualTitles, expectedTitles)
}

private func login(named name: String, month: Int = 1, year: Int = 2000) -> SecureVaultItem {
Expand Down

0 comments on commit 5782e9b

Please sign in to comment.