Revision control

1
/* This Source Code Form is subject to the terms of the Mozilla Public
2
* License, v. 2.0. If a copy of the MPL was not distributed with this
3
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5
@testable import Client
6
@testable import Sync
7
8
import Shared
9
import Storage
10
import XCTest
11
12
private class RandomError: MaybeErrorType {
13
var description = "random_error"
14
}
15
16
class SyncStatusResolverTests: XCTestCase {
17
18
private func mockStatsForCollection(collection: String) -> SyncEngineStatsSession {
19
return SyncEngineStatsSession(collection: collection)
20
}
21
22
func testAllCompleted() {
23
let results: EngineResults = [
24
("tabs", .completed(mockStatsForCollection(collection: "tabs"))),
25
("clients", .completed(mockStatsForCollection(collection: "clients")))
26
]
27
let maybeResults = Maybe(success: results)
28
29
let resolver = SyncStatusResolver(engineResults: maybeResults)
30
XCTAssertTrue(resolver.resolveResults() == SyncDisplayState.good)
31
}
32
33
func testAllCompletedExceptOneDisabledRemotely() {
34
let results: EngineResults = [
35
("tabs", .completed(mockStatsForCollection(collection: "tabs"))),
36
("clients", .notStarted(.engineRemotelyNotEnabled(collection: "clients")))
37
]
38
let maybeResults = Maybe(success: results)
39
40
let resolver = SyncStatusResolver(engineResults: maybeResults)
41
XCTAssertTrue(resolver.resolveResults() == SyncDisplayState.good)
42
}
43
44
func testAllCompletedExceptNotStartedBecauseNoAccount() {
45
let results: EngineResults = [
46
("tabs", .completed(mockStatsForCollection(collection: "tabs"))),
47
("clients", .notStarted(.noAccount))
48
]
49
let maybeResults = Maybe(success: results)
50
51
let resolver = SyncStatusResolver(engineResults: maybeResults)
52
XCTAssertTrue(resolver.resolveResults() == SyncDisplayState.warning(message: Strings.FirefoxSyncOfflineTitle))
53
}
54
55
func testAllCompletedExceptNotStartedBecauseOffline() {
56
let results: EngineResults = [
57
("tabs", .completed(mockStatsForCollection(collection: "tabs"))),
58
("clients", .notStarted(.offline))
59
]
60
let maybeResults = Maybe(success: results)
61
62
let resolver = SyncStatusResolver(engineResults: maybeResults)
63
XCTAssertTrue(resolver.resolveResults() == SyncDisplayState.bad(message: Strings.FirefoxSyncOfflineTitle))
64
}
65
66
func testOfflineAndNoAccount() {
67
let results: EngineResults = [
68
("tabs", .notStarted(.noAccount)),
69
("clients", .notStarted(.offline))
70
]
71
72
let maybeResults = Maybe(success: results)
73
74
let resolver = SyncStatusResolver(engineResults: maybeResults)
75
XCTAssertTrue(resolver.resolveResults() == SyncDisplayState.bad(message: Strings.FirefoxSyncOfflineTitle))
76
}
77
78
func testAllPartial() {
79
let results: EngineResults = [
80
("tabs", .partial(SyncEngineStatsSession(collection: "tabs"))),
81
("clients", .partial(SyncEngineStatsSession(collection: "clients")))
82
]
83
let maybeResults = Maybe(success: results)
84
85
let resolver = SyncStatusResolver(engineResults: maybeResults)
86
XCTAssertTrue(resolver.resolveResults() == SyncDisplayState.good)
87
}
88
89
func testRandomFailure() {
90
let maybeResults: Maybe<EngineResults> = Maybe(failure: RandomError())
91
let resolver = SyncStatusResolver(engineResults: maybeResults)
92
let expected = SyncDisplayState.bad(message: nil)
93
XCTAssertTrue(resolver.resolveResults() == expected)
94
}
95
}