-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathVPNStateTests.swift
84 lines (72 loc) · 2.48 KB
/
VPNStateTests.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
@testable import Coder_Desktop
import SwiftUI
import Testing
import ViewInspector
@MainActor
@Suite(.timeLimit(.minutes(1)))
struct VPNStateTests {
let vpn: MockVPNService
let state: AppState
let sut: VPNState<MockVPNService>
let view: any View
init() {
vpn = MockVPNService()
sut = VPNState<MockVPNService>()
state = AppState(persistent: false)
state.login(baseAccessURL: URL(string: "https://coder.example.com")!, sessionToken: "fake-token")
view = sut.environmentObject(vpn).environmentObject(state)
}
@Test
func testDisabledState() async throws {
vpn.state = .disabled
try await ViewHosting.host(view) {
try await sut.inspection.inspect { view in
#expect(throws: Never.self) {
try view.find(text: "Enable Coder Connect to see workspaces")
}
}
}
}
@Test
func testConnectingState() async throws {
vpn.state = .connecting
try await ViewHosting.host(view) {
try await sut.inspection.inspect { view in
let progressView = try view.find(ViewType.ProgressView.self)
#expect(try progressView.labelView().text().string() == "Starting Coder Connect...")
}
}
}
@Test
func testDisconnectingState() async throws {
vpn.state = .disconnecting
try await ViewHosting.host(view) {
try await sut.inspection.inspect { view in
let progressView = try view.find(ViewType.ProgressView.self)
#expect(try progressView.labelView().text().string() == "Stopping Coder Connect...")
}
}
}
@Test
func testFailedState() async throws {
let errMsg = "Internal error occured!"
vpn.state = .failed(.internalError(errMsg))
try await ViewHosting.host(view.environmentObject(vpn)) {
try await sut.inspection.inspect { view in
let text = try view.find(ViewType.Text.self)
#expect(try text.string() == "Internal Error: \(errMsg)")
}
}
}
@Test
func testDefaultState() async throws {
vpn.state = .connected
try await ViewHosting.host(view.environmentObject(vpn)) {
try await sut.inspection.inspect { view in
#expect(throws: (any Error).self) {
_ = try view.find(ViewType.Text.self)
}
}
}
}
}