@@ -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
5479class 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 )
0 commit comments