-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
ActivityContentRouterTests.swift
63 lines (48 loc) · 2.03 KB
/
ActivityContentRouterTests.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import XCTest
@testable import WordPress
final class ActivityContentRouterTests: XCTestCase {
let testData = ActivityLogTestData()
var testCoordinator: MockContentCoordinator!
override func setUp() {
super.setUp()
testCoordinator = MockContentCoordinator()
}
override func tearDown() {
super.tearDown()
}
func testRouteToComment() throws {
let commentActivity = try getCommentActivity()
let router = ActivityContentRouter(activity: commentActivity, coordinator: testCoordinator)
router.routeTo(commentURL)
XCTAssertTrue(testCoordinator.commentsWasDisplayed)
XCTAssertEqual(testCoordinator.commentPostID?.intValue, testData.testPostID)
XCTAssertEqual(testCoordinator.commentSiteID?.intValue, testData.testSiteID)
}
func testRouteToPost() throws {
let activity = try getPostActivity()
let router = ActivityContentRouter(activity: activity, coordinator: testCoordinator)
router.routeTo(postURL)
XCTAssertTrue(testCoordinator.readerWasDisplayed)
XCTAssertEqual(testCoordinator.readerPostID?.intValue, testData.testPostID)
XCTAssertEqual(testCoordinator.readerSiteID?.intValue, testData.testSiteID)
}
}
// MARK: - Helpers
extension ActivityContentRouterTests {
var postURL: URL {
return URL(string: testData.testPostUrl)!
}
var commentURL: URL {
return URL(string: testData.testCommentURL)!
}
func getCommentActivity() throws -> FormattableActivity {
let data = try JSONSerialization.data(withJSONObject: testData.getCommentEventDictionary())
let activity = try JSONDecoder().decode(Activity.self, from: data)
return FormattableActivity(with: activity)
}
func getPostActivity() throws -> FormattableActivity {
let data = try JSONSerialization.data(withJSONObject: testData.getPostEventDictionary())
let activity = try JSONDecoder().decode(Activity.self, from: data)
return FormattableActivity(with: activity)
}
}