Skip to content

Commit

Permalink
Fix for "Mentioned issues are not sorted by date" (GitHawkApp#2649)
Browse files Browse the repository at this point in the history
  • Loading branch information
akarataev committed Mar 10, 2019
1 parent f0a62aa commit 75003f3
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 2 deletions.
13 changes: 11 additions & 2 deletions Classes/Notifications/NotificationModelController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ extension NotificationViewModel {
}
}

// sorting Array<InboxDashboardModel> by date for mentioned filter type
extension Array where Element == InboxDashboardModel {
func sortedMentionedByDate(filter: V3IssuesRequest.FilterType) -> [Element] {
if filter == .mentioned { return self.sorted(by: { $0.date > $1.date }) }
return self
}
}

final class NotificationModelController {

let githubClient: GithubClient
Expand Down Expand Up @@ -273,8 +281,9 @@ final class NotificationModelController {
state: state
)
}
cache.set(values: parsed)
completion(.success((parsed, data.next)))
let sorted = parsed.sortedMentionedByDate(filter: mapped)
cache.set(values: sorted)
completion(.success((sorted, data.next)))
}
})
}
Expand Down
4 changes: 4 additions & 0 deletions Freetime.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@
D8C2AEF51F9AA94600A95945 /* DotListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8C2AEF41F9AA94600A95945 /* DotListView.swift */; };
D8D876F81FB6083200A57E2B /* UIPopoverPresentationController+SourceView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8D876F71FB6083200A57E2B /* UIPopoverPresentationController+SourceView.swift */; };
D8D876FA1FB6084F00A57E2B /* UIBarButtonItem+TightSpacing.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8D876F91FB6084F00A57E2B /* UIBarButtonItem+TightSpacing.swift */; };
DA3A743F2233EC6E0011C3BA /* SortingMentionedByDayTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA3A743E2233EC6E0011C3BA /* SortingMentionedByDayTests.swift */; };
DC3238911F9B9E1A007DD924 /* SearchRecentViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC3238901F9B9E1A007DD924 /* SearchRecentViewModel.swift */; };
DC3238931F9BA29D007DD924 /* SearchQuery.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC3238921F9BA29D007DD924 /* SearchQuery.swift */; };
DC5C02C31F9C6D0B00E80B9F /* SearchRecentStoreTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC5C02C21F9C6D0A00E80B9F /* SearchRecentStoreTests.swift */; };
Expand Down Expand Up @@ -1134,6 +1135,7 @@
D8C2AEF41F9AA94600A95945 /* DotListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DotListView.swift; sourceTree = "<group>"; };
D8D876F71FB6083200A57E2B /* UIPopoverPresentationController+SourceView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIPopoverPresentationController+SourceView.swift"; sourceTree = "<group>"; };
D8D876F91FB6084F00A57E2B /* UIBarButtonItem+TightSpacing.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIBarButtonItem+TightSpacing.swift"; sourceTree = "<group>"; };
DA3A743E2233EC6E0011C3BA /* SortingMentionedByDayTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SortingMentionedByDayTests.swift; sourceTree = "<group>"; };
DC3238901F9B9E1A007DD924 /* SearchRecentViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchRecentViewModel.swift; sourceTree = "<group>"; };
DC3238921F9BA29D007DD924 /* SearchQuery.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchQuery.swift; sourceTree = "<group>"; };
DC5C02C21F9C6D0A00E80B9F /* SearchRecentStoreTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SearchRecentStoreTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1752,6 +1754,7 @@
29827D7321AA5DA300A1B293 /* ViewControllerTestUtil.swift */,
03E8D825221D358000EB792A /* GithubURLTests.swift */,
03C127B7220993300062F7C9 /* InboxZeroLoaderTests.swift */,
DA3A743E2233EC6E0011C3BA /* SortingMentionedByDayTests.swift */,
);
path = FreetimeTests;
sourceTree = "<group>";
Expand Down Expand Up @@ -3433,6 +3436,7 @@
BDB6AA762165B8EA009BB73C /* SwitchBranches.swift in Sources */,
DC5C02C71F9C71C400E80B9F /* SearchRecentViewModelTests.swift in Sources */,
DC60C6D31F983BB900241271 /* SignatureTests.swift in Sources */,
DA3A743F2233EC6E0011C3BA /* SortingMentionedByDayTests.swift in Sources */,
DC60C6D51F983DF800241271 /* IssueLabelCellTests.swift in Sources */,
49FE18FF204B6508001681E8 /* SequenceTests.swift in Sources */,
DC5C02C31F9C6D0B00E80B9F /* SearchRecentStoreTests.swift in Sources */,
Expand Down
49 changes: 49 additions & 0 deletions FreetimeTests/SortingMentionedByDayTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//
// SortingMentionedByDayTests.swift
// FreetimeTests
//
// Created by Alexey Karataev on 09.03.2019.
// Copyright © 2019 Ryan Nystrom. All rights reserved.
//

import XCTest
@testable import Freetime
@testable import StyledTextKit
@testable import GitHubAPI

class SortingMentionedByDayTests: XCTestCase {
func testSortingMentionedByDay() {
// MARK: - given
let models = 5
let parsed = InboxDashboardModelBuilder.provide(number: models)
let mentioned = V3IssuesRequest.FilterType.mentioned
let created = V3IssuesRequest.FilterType.created
let assigned = V3IssuesRequest.FilterType.assigned
// MARK: - when
let mentionedSorted = parsed.sortedMentionedByDate(filter: mentioned)
let createdSorted = parsed.sortedMentionedByDate(filter: created)
let assignedSorted = parsed.sortedMentionedByDate(filter: assigned)
// MARK: - then
XCTAssert(zip(mentionedSorted,
parsed.sorted(by: {$0.date > $1.date}))
.allSatisfy { $0.date == $1.date }, "Mentioned is not sorted by day")
XCTAssert(zip(createdSorted, parsed)
.allSatisfy { $0.date == $1.date }, "Sorting affect created feed")
XCTAssert(zip(assignedSorted, parsed)
.allSatisfy { $0.date == $1.date }, "Sorting affect assigned feed")
}
}

class InboxDashboardModelBuilder {
let model: InboxDashboardModel
private init(date: Date) {
self.model = InboxDashboardModel(owner: "", name: "", number: 0, date: date,
text: StyledTextRenderer(string: StyledTextString(styledTexts: []),
contentSizeCategory: UIContentSizeCategory(rawValue: "")),
isPullRequest: false, state: .open
)
}
static func provide(number: Int, with interval: TimeInterval = TimeInterval(86400)) -> [InboxDashboardModel] {
return (1...number).map { InboxDashboardModelBuilder(date: Date() + interval * Double($0)).model }
}
}

0 comments on commit 75003f3

Please sign in to comment.