forked from p0deje/Maccy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSorterTests.swift
67 lines (55 loc) · 2.13 KB
/
SorterTests.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
import XCTest
@testable import Maccy
class SorterTests: XCTestCase {
let savedPinTo = UserDefaults.standard.pinTo
var item1: HistoryItem!
var item2: HistoryItem!
var item3: HistoryItem!
override func setUp() {
CoreDataManager.inMemory = true
super.setUp()
item1 = historyItem(value: "foo", firstCopiedAt: -300, lastCopiedAt: -100, numberOfCopies: 3)
item2 = historyItem(value: "bar", firstCopiedAt: -400, lastCopiedAt: -300, numberOfCopies: 2)
item3 = historyItem(value: "bar", firstCopiedAt: -200, lastCopiedAt: -200, numberOfCopies: 1)
}
override func tearDown() {
super.tearDown()
CoreDataManager.inMemory = false
UserDefaults.standard.pinTo = savedPinTo
}
func testSortByLastCopiedAt() {
let sorter = Sorter(by: "lastCopiedAt")
XCTAssertEqual(sorter.sort([item1, item2, item3]), [item1, item3, item2])
}
func testSortByFirstCopiedAt() {
let sorter = Sorter(by: "firstCopiedAt")
XCTAssertEqual(sorter.sort([item1, item2, item3]), [item3, item1, item2])
}
func testSortByNumberOfCopies() {
let sorter = Sorter(by: "numberOfCopies")
XCTAssertEqual(sorter.sort([item1, item2, item3]), [item1, item2, item3])
}
func testSortByPinToTop() {
UserDefaults.standard.pinTo = "top"
item1.pin = "a"
item3.pin = "b"
let sorter = Sorter(by: "lastCopiedAt")
XCTAssertEqual(sorter.sort([item1, item2, item3]), [item1, item3, item2])
}
func testSortByPinToBottom() {
UserDefaults.standard.pinTo = "bottom"
item1.pin = "a"
item3.pin = "b"
let sorter = Sorter(by: "lastCopiedAt")
XCTAssertEqual(sorter.sort([item1, item2, item3]), [item2, item1, item3])
}
private func historyItem(value: String, firstCopiedAt: Int,
lastCopiedAt: Int, numberOfCopies: Int) -> HistoryItem {
let content = HistoryItemContent(type: "", value: value.data(using: .utf8)!)
let item = HistoryItem(contents: [content])
item.firstCopiedAt = Date(timeIntervalSinceNow: TimeInterval(firstCopiedAt))
item.lastCopiedAt = Date(timeIntervalSinceNow: TimeInterval(lastCopiedAt))
item.numberOfCopies = numberOfCopies
return item
}
}