Skip to content

Commit e16b8ea

Browse files
committed
add: parse the remaining remote cards
1 parent d8afd70 commit e16b8ea

2 files changed

Lines changed: 45 additions & 5 deletions

File tree

WordPress/Classes/ViewRelated/Blog/Blog Dashboard/Service/BlogDashboardService.swift

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,31 @@ class BlogDashboardService {
1717

1818
var snapshot = DashboardSnapshot()
1919

20-
if let posts = cards["posts"] as? NSDictionary,
21-
let (sections, items) = self?.parsePostCard(posts) {
22-
snapshot.appendSections(sections)
23-
sections.enumerated().forEach { key, section in
24-
snapshot.appendItems([items[key]], toSection: section)
20+
DashboardCard.allCases.forEach { card in
21+
22+
if card.isRemote {
23+
24+
if card == .posts,
25+
let posts = cards[DashboardCard.posts.rawValue] as? NSDictionary,
26+
let (sections, items) = self?.parsePostCard(posts) {
27+
snapshot.appendSections(sections)
28+
sections.enumerated().forEach { key, section in
29+
snapshot.appendItems([items[key]], toSection: section)
30+
}
31+
} else {
32+
33+
if let viewModel = cards[card.rawValue] {
34+
let section = DashboardCardSection(id: card.rawValue)
35+
let item = DashboardCardModel(id: card, cellViewModel: viewModel as? NSDictionary)
36+
37+
snapshot.appendSections([section])
38+
snapshot.appendItems([item], toSection: section)
39+
}
40+
41+
}
42+
2543
}
44+
2645
}
2746

2847
completion(snapshot)

WordPress/WordPressTest/Dashboard/BlogDashboardServiceTests.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,27 @@ class BlogDashboardServiceTests: XCTestCase {
7474

7575
waitForExpectations(timeout: 3, handler: nil)
7676
}
77+
78+
func testTodaysStats() {
79+
let expect = expectation(description: "Parse todays stats")
80+
remoteServiceMock.respondWith = .withDraftAndSchedulePosts
81+
82+
service.fetch(wpComID: 123456) { snapshot in
83+
// Drafts and Scheduled section exists
84+
let todaysStatsSection = snapshot.sectionIdentifiers.filter { $0.id == "todays_stats" }
85+
XCTAssertEqual(todaysStatsSection.count, 1)
86+
87+
// The item identifier id is todaysStats
88+
XCTAssertEqual(snapshot.itemIdentifiers(inSection: todaysStatsSection.first!).first?.id, .todaysStats)
89+
90+
// Todays Stats has the correct data source
91+
XCTAssertEqual(snapshot.itemIdentifiers(inSection: todaysStatsSection.first!).first?.cellViewModel, ["views": 0, "visitors": 0, "likes": 0, "comments": 0])
92+
93+
expect.fulfill()
94+
}
95+
96+
waitForExpectations(timeout: 3, handler: nil)
97+
}
7798
}
7899

79100
class DashboardServiceRemoteMock: DashboardServiceRemote {

0 commit comments

Comments
 (0)