Skip to content

Commit d8afd70

Browse files
committed
test: parse a posts card with only drafts
1 parent e59528c commit d8afd70

3 files changed

Lines changed: 57 additions & 1 deletion

File tree

WordPress/WordPress.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,6 +1408,7 @@
14081408
8B36256625A60CCA00D7CCE3 /* BackupListViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8B36256525A60CCA00D7CCE3 /* BackupListViewController.swift */; };
14091409
8B3626F925A665E500D7CCE3 /* UIApplication+mainWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8B3626F825A665E500D7CCE3 /* UIApplication+mainWindow.swift */; };
14101410
8B3DECAB2388506400A459C2 /* SentryStartupEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8B3DECAA2388506400A459C2 /* SentryStartupEvent.swift */; };
1411+
8B45C12627B2A27400EA3257 /* dashboard-200-with-drafts-only.json in Resources */ = {isa = PBXBuildFile; fileRef = 8B45C12527B2A27400EA3257 /* dashboard-200-with-drafts-only.json */; };
14111412
8B4DDF25278F44CC0022494D /* BlogDashboardViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA73D7D5278D9E5D00DF24B3 /* BlogDashboardViewController.swift */; };
14121413
8B4DDF26278F45180022494D /* HostCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA73D7D8278DDD4B00DF24B3 /* HostCollectionViewCell.swift */; };
14131414
8B4DDF27278F451E0022494D /* QuickLinksView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA73D7DC278DDE0E00DF24B3 /* QuickLinksView.swift */; };
@@ -6084,6 +6085,7 @@
60846085
8B36256525A60CCA00D7CCE3 /* BackupListViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BackupListViewController.swift; sourceTree = "<group>"; };
60856086
8B3626F825A665E500D7CCE3 /* UIApplication+mainWindow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIApplication+mainWindow.swift"; sourceTree = "<group>"; };
60866087
8B3DECAA2388506400A459C2 /* SentryStartupEvent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryStartupEvent.swift; sourceTree = "<group>"; };
6088+
8B45C12527B2A27400EA3257 /* dashboard-200-with-drafts-only.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = "dashboard-200-with-drafts-only.json"; sourceTree = "<group>"; };
60876089
8B51844425893F140085488D /* FilterBarView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FilterBarView.swift; sourceTree = "<group>"; };
60886090
8B6214DF27B1AD9D001DF7B6 /* DashboardStatsCardCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DashboardStatsCardCell.swift; sourceTree = "<group>"; };
60896091
8B6214E227B1B2F3001DF7B6 /* BlogDashboardService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BlogDashboardService.swift; sourceTree = "<group>"; };
@@ -11515,6 +11517,7 @@
1151511517
isa = PBXGroup;
1151611518
children = (
1151711519
8BEE845927B1DC9D0001A93C /* dashboard-200-with-drafts-and-scheduled.json */,
11520+
8B45C12527B2A27400EA3257 /* dashboard-200-with-drafts-only.json */,
1151811521
);
1151911522
path = Dashboard;
1152011523
sourceTree = "<group>";
@@ -15979,6 +15982,7 @@
1597915982
32110569250C0E960048446F /* 100x100-png in Resources */,
1598015983
D848CC1320FF31BB00A9038F /* notifications-blockquote-range.json in Resources */,
1598115984
D848CC0D20FF2D7C00A9038F /* notifications-post-range.json in Resources */,
15985+
8B45C12627B2A27400EA3257 /* dashboard-200-with-drafts-only.json in Resources */,
1598215986
32110561250C027D0048446F /* 100x100.jpg in Resources */,
1598315987
748437F11F1D4ECC00E8DDAF /* notifications-last-seen.json in Resources */,
1598415988
74585B9D1F0D591D00E7E667 /* domain-service-all-domain-types.json in Resources */,

WordPress/WordPressTest/Dashboard/BlogDashboardServiceTests.swift

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class BlogDashboardServiceTests: XCTestCase {
2828

2929
func testCreateSectionForDraftsAndScheduled() {
3030
let expect = expectation(description: "Parse drafts and scheduled")
31+
remoteServiceMock.respondWith = .withDraftAndSchedulePosts
3132

3233
service.fetch(wpComID: 123456) { snapshot in
3334
// Drafts and Scheduled section exists
@@ -49,17 +50,48 @@ class BlogDashboardServiceTests: XCTestCase {
4950

5051
waitForExpectations(timeout: 3, handler: nil)
5152
}
53+
54+
func testCreateSectionForDraftOnly() {
55+
let expect = expectation(description: "Parse drafts and scheduled")
56+
remoteServiceMock.respondWith = .withDraftsOnly
57+
58+
service.fetch(wpComID: 123456) { snapshot in
59+
// Drafts and Scheduled section exists
60+
let draftsSection = snapshot.sectionIdentifiers.filter { $0.id == "posts" && $0.subtype == nil }
61+
XCTAssertEqual(draftsSection.count, 1)
62+
63+
// The item identifier id is posts
64+
XCTAssertEqual(snapshot.itemIdentifiers(inSection: draftsSection.first!).first?.id, .posts)
65+
66+
// For Drafts section, scheduled has 0 posts
67+
XCTAssertEqual((snapshot.itemIdentifiers(inSection: draftsSection.first!).first?.cellViewModel?["scheduled"] as? [Any])?.count, 0)
68+
69+
// For Drafts section, scheduled has 1 post
70+
XCTAssertEqual((snapshot.itemIdentifiers(inSection: draftsSection.first!).first?.cellViewModel?["draft"] as? [Any])?.count, 1)
71+
72+
expect.fulfill()
73+
}
74+
75+
waitForExpectations(timeout: 3, handler: nil)
76+
}
5277
}
5378

5479
class DashboardServiceRemoteMock: DashboardServiceRemote {
80+
enum Response: String {
81+
case withDraftAndSchedulePosts = "dashboard-200-with-drafts-and-scheduled.json"
82+
case withDraftsOnly = "dashboard-200-with-drafts-only.json"
83+
}
84+
85+
var respondWith: Response = .withDraftAndSchedulePosts
86+
5587
var didCallWithBlogID: Int?
5688
var didRequestCards: [String]?
5789

5890
override func fetch(cards: [String], forBlogID blogID: Int, success: @escaping (NSDictionary) -> Void, failure: @escaping (Error) -> Void) {
5991
didCallWithBlogID = blogID
6092
didRequestCards = cards
6193

62-
if let fileURL: URL = Bundle(for: BlogDashboardServiceTests.self).url(forResource: "dashboard-200-with-drafts-and-scheduled.json", withExtension: nil),
94+
if let fileURL: URL = Bundle(for: BlogDashboardServiceTests.self).url(forResource: respondWith.rawValue, withExtension: nil),
6395
let data: Data = try? Data(contentsOf: fileURL),
6496
let jsonObject = try? JSONSerialization.jsonObject(with: data, options: []) as AnyObject {
6597
success(jsonObject as! NSDictionary)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"posts": {
3+
"has_published": true,
4+
"draft": [{
5+
"id": 3246,
6+
"title": "Foo",
7+
"content": "",
8+
"featured_image": null,
9+
"date": "2022-01-13 00:30:56"
10+
}],
11+
"scheduled": []
12+
},
13+
"todays_stats": {
14+
"views": 0,
15+
"visitors": 0,
16+
"likes": 0,
17+
"comments": 0
18+
}
19+
}
20+

0 commit comments

Comments
 (0)