-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
ActivityLogRangesTest.swift
116 lines (83 loc) · 3.88 KB
/
ActivityLogRangesTest.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import XCTest
@testable import WordPress
final class ActivityLogRangesTests: XCTestCase {
let testData = ActivityLogTestData()
override func setUp() {
super.setUp()
}
override func tearDown() {
super.tearDown()
}
func testPostRangeCreatesURL() {
let range = NSRange(location: 0, length: 0)
let postRange = ActivityPostRange(range: range, siteID: testData.testSiteID, postID: testData.testPostID)
XCTAssertEqual(testData.testPostUrl, postRange.url?.absoluteString)
}
func testPluginRangeCreatesURL() {
let range = NSRange(location: 0, length: 0)
let pluginRange = ActivityPluginRange(range: range, pluginSlug: testData.testPluginSlug, siteSlug: testData.testSiteSlug)
XCTAssertEqual(pluginRange.url?.absoluteString, testData.testPluginUrl)
}
func testPluginRangeSavesSlugs() {
let range = NSRange(location: 0, length: 0)
let pluginRange = ActivityPluginRange(range: range, pluginSlug: testData.testPluginSlug, siteSlug: testData.testSiteSlug)
XCTAssertEqual(pluginRange.pluginSlug, testData.testPluginSlug)
XCTAssertEqual(pluginRange.siteSlug, testData.testSiteSlug)
}
func testDefaultRange() {
let range = NSRange(location: 0, length: 0)
let url = URL(string: testData.testPostUrl)!
let defaultRange = ActivityRange(range: range, url: url)
XCTAssertEqual(defaultRange.kind, .default)
XCTAssertEqual(defaultRange.url?.absoluteString, testData.testPostUrl)
XCTAssertEqual(defaultRange.range, range)
}
func testRangeFactoryCreatesCommentRange() throws {
let commentRangeRaw = try testData.getCommentRangeDictionary()
let range = ActivityRangesFactory.contentRange(from: commentRangeRaw)
XCTAssertNotNil(range)
XCTAssertTrue(range is ActivityCommentRange)
let commentRange = range as? ActivityCommentRange
XCTAssertEqual(commentRange?.kind, .comment)
XCTAssertNotNil(commentRange?.url)
}
func testRangeFactoryCreatesThemeRange() throws {
let themeRangeRaw = try testData.getThemeRangeDictionary()
let range = ActivityRangesFactory.contentRange(from: themeRangeRaw)
XCTAssertNotNil(range)
XCTAssertTrue(range is ActivityRange)
let themeRange = range as? ActivityRange
XCTAssertEqual(themeRange?.kind, .theme)
XCTAssertNotNil(themeRange?.url)
}
func testRangeFactoryCreatesPostRange() throws {
let postRangeRaw = try testData.getPostRangeDictionary()
let range = ActivityRangesFactory.contentRange(from: postRangeRaw)
XCTAssertNotNil(range)
XCTAssertEqual(range?.kind, .post)
XCTAssertTrue(range is ActivityPostRange)
let postRange = range as? ActivityPostRange
XCTAssertEqual(postRange?.url?.absoluteString, testData.testPostUrl)
}
func testRangeFactoryCreatesItalicRange() throws {
let italicRangeRaw = try testData.getItalicRangeDictionary()
let range = ActivityRangesFactory.contentRange(from: italicRangeRaw)
XCTAssertNotNil(range)
XCTAssertEqual(range?.kind, .italic)
}
func testRangeFactoryCreatesSiteRange() throws {
let siteRangeRaw = try testData.getSiteRangeDictionary()
let range = ActivityRangesFactory.contentRange(from: siteRangeRaw)
XCTAssertNotNil(range)
XCTAssertEqual(range?.kind, .site)
}
func testRangeFactoryCreatesPluginRange() throws {
let pluginRangeRaw = try testData.getPluginRangeDictionary()
let range = ActivityRangesFactory.contentRange(from: pluginRangeRaw)
XCTAssertNotNil(range)
XCTAssertEqual(range?.kind, .plugin)
XCTAssertTrue(range is ActivityPluginRange)
let pluginRange = range as? ActivityPluginRange
XCTAssertEqual(pluginRange?.url?.absoluteString, testData.testPluginUrl)
}
}