Skip to content
This repository was archived by the owner on Sep 20, 2023. It is now read-only.

Commit 75003f3

Browse files
committed
Fix for "Mentioned issues are not sorted by date" (#2649)
1 parent f0a62aa commit 75003f3

File tree

3 files changed

+64
-2
lines changed

3 files changed

+64
-2
lines changed

Diff for: Classes/Notifications/NotificationModelController.swift

+11-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ extension NotificationViewModel {
2424
}
2525
}
2626

27+
// sorting Array<InboxDashboardModel> by date for mentioned filter type
28+
extension Array where Element == InboxDashboardModel {
29+
func sortedMentionedByDate(filter: V3IssuesRequest.FilterType) -> [Element] {
30+
if filter == .mentioned { return self.sorted(by: { $0.date > $1.date }) }
31+
return self
32+
}
33+
}
34+
2735
final class NotificationModelController {
2836

2937
let githubClient: GithubClient
@@ -273,8 +281,9 @@ final class NotificationModelController {
273281
state: state
274282
)
275283
}
276-
cache.set(values: parsed)
277-
completion(.success((parsed, data.next)))
284+
let sorted = parsed.sortedMentionedByDate(filter: mapped)
285+
cache.set(values: sorted)
286+
completion(.success((sorted, data.next)))
278287
}
279288
})
280289
}

Diff for: Freetime.xcodeproj/project.pbxproj

+4
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,7 @@
525525
D8C2AEF51F9AA94600A95945 /* DotListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8C2AEF41F9AA94600A95945 /* DotListView.swift */; };
526526
D8D876F81FB6083200A57E2B /* UIPopoverPresentationController+SourceView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8D876F71FB6083200A57E2B /* UIPopoverPresentationController+SourceView.swift */; };
527527
D8D876FA1FB6084F00A57E2B /* UIBarButtonItem+TightSpacing.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8D876F91FB6084F00A57E2B /* UIBarButtonItem+TightSpacing.swift */; };
528+
DA3A743F2233EC6E0011C3BA /* SortingMentionedByDayTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA3A743E2233EC6E0011C3BA /* SortingMentionedByDayTests.swift */; };
528529
DC3238911F9B9E1A007DD924 /* SearchRecentViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC3238901F9B9E1A007DD924 /* SearchRecentViewModel.swift */; };
529530
DC3238931F9BA29D007DD924 /* SearchQuery.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC3238921F9BA29D007DD924 /* SearchQuery.swift */; };
530531
DC5C02C31F9C6D0B00E80B9F /* SearchRecentStoreTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC5C02C21F9C6D0A00E80B9F /* SearchRecentStoreTests.swift */; };
@@ -1134,6 +1135,7 @@
11341135
D8C2AEF41F9AA94600A95945 /* DotListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DotListView.swift; sourceTree = "<group>"; };
11351136
D8D876F71FB6083200A57E2B /* UIPopoverPresentationController+SourceView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIPopoverPresentationController+SourceView.swift"; sourceTree = "<group>"; };
11361137
D8D876F91FB6084F00A57E2B /* UIBarButtonItem+TightSpacing.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIBarButtonItem+TightSpacing.swift"; sourceTree = "<group>"; };
1138+
DA3A743E2233EC6E0011C3BA /* SortingMentionedByDayTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SortingMentionedByDayTests.swift; sourceTree = "<group>"; };
11371139
DC3238901F9B9E1A007DD924 /* SearchRecentViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchRecentViewModel.swift; sourceTree = "<group>"; };
11381140
DC3238921F9BA29D007DD924 /* SearchQuery.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchQuery.swift; sourceTree = "<group>"; };
11391141
DC5C02C21F9C6D0A00E80B9F /* SearchRecentStoreTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SearchRecentStoreTests.swift; sourceTree = "<group>"; };
@@ -1752,6 +1754,7 @@
17521754
29827D7321AA5DA300A1B293 /* ViewControllerTestUtil.swift */,
17531755
03E8D825221D358000EB792A /* GithubURLTests.swift */,
17541756
03C127B7220993300062F7C9 /* InboxZeroLoaderTests.swift */,
1757+
DA3A743E2233EC6E0011C3BA /* SortingMentionedByDayTests.swift */,
17551758
);
17561759
path = FreetimeTests;
17571760
sourceTree = "<group>";
@@ -3433,6 +3436,7 @@
34333436
BDB6AA762165B8EA009BB73C /* SwitchBranches.swift in Sources */,
34343437
DC5C02C71F9C71C400E80B9F /* SearchRecentViewModelTests.swift in Sources */,
34353438
DC60C6D31F983BB900241271 /* SignatureTests.swift in Sources */,
3439+
DA3A743F2233EC6E0011C3BA /* SortingMentionedByDayTests.swift in Sources */,
34363440
DC60C6D51F983DF800241271 /* IssueLabelCellTests.swift in Sources */,
34373441
49FE18FF204B6508001681E8 /* SequenceTests.swift in Sources */,
34383442
DC5C02C31F9C6D0B00E80B9F /* SearchRecentStoreTests.swift in Sources */,

Diff for: FreetimeTests/SortingMentionedByDayTests.swift

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
//
2+
// SortingMentionedByDayTests.swift
3+
// FreetimeTests
4+
//
5+
// Created by Alexey Karataev on 09.03.2019.
6+
// Copyright © 2019 Ryan Nystrom. All rights reserved.
7+
//
8+
9+
import XCTest
10+
@testable import Freetime
11+
@testable import StyledTextKit
12+
@testable import GitHubAPI
13+
14+
class SortingMentionedByDayTests: XCTestCase {
15+
func testSortingMentionedByDay() {
16+
// MARK: - given
17+
let models = 5
18+
let parsed = InboxDashboardModelBuilder.provide(number: models)
19+
let mentioned = V3IssuesRequest.FilterType.mentioned
20+
let created = V3IssuesRequest.FilterType.created
21+
let assigned = V3IssuesRequest.FilterType.assigned
22+
// MARK: - when
23+
let mentionedSorted = parsed.sortedMentionedByDate(filter: mentioned)
24+
let createdSorted = parsed.sortedMentionedByDate(filter: created)
25+
let assignedSorted = parsed.sortedMentionedByDate(filter: assigned)
26+
// MARK: - then
27+
XCTAssert(zip(mentionedSorted,
28+
parsed.sorted(by: {$0.date > $1.date}))
29+
.allSatisfy { $0.date == $1.date }, "Mentioned is not sorted by day")
30+
XCTAssert(zip(createdSorted, parsed)
31+
.allSatisfy { $0.date == $1.date }, "Sorting affect created feed")
32+
XCTAssert(zip(assignedSorted, parsed)
33+
.allSatisfy { $0.date == $1.date }, "Sorting affect assigned feed")
34+
}
35+
}
36+
37+
class InboxDashboardModelBuilder {
38+
let model: InboxDashboardModel
39+
private init(date: Date) {
40+
self.model = InboxDashboardModel(owner: "", name: "", number: 0, date: date,
41+
text: StyledTextRenderer(string: StyledTextString(styledTexts: []),
42+
contentSizeCategory: UIContentSizeCategory(rawValue: "")),
43+
isPullRequest: false, state: .open
44+
)
45+
}
46+
static func provide(number: Int, with interval: TimeInterval = TimeInterval(86400)) -> [InboxDashboardModel] {
47+
return (1...number).map { InboxDashboardModelBuilder(date: Date() + interval * Double($0)).model }
48+
}
49+
}

0 commit comments

Comments
 (0)