Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
quanganhdo committed Apr 12, 2024
1 parent fe192bf commit 14b0d31
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"location" : "https://github.com/duckduckgo/BrowserServicesKit",
"state" : {
"branch" : "anh/netp/screen-improvements",
"revision" : "ae13b6ab3880db92776938ae1be4aceb4a3b4ea1"
"revision" : "3b354a70cdfff5d46d2c8f525748dee63a36ad88"
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import SwiftUI

@MainActor
public final class TunnelControllerViewModel: ObservableObject {
public struct FormattedDataVolume {
public struct FormattedDataVolume: Equatable {
public let dataSent: String
public let dataReceived: String
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ final class TunnelControllerViewModelTests: XCTestCase {
let connectionErrorObserver: ConnectionErrorObserver
let connectivityIssuesObserver: ConnectivityIssueObserver
let controllerErrorMessageObserver: ControllerErrorMesssageObserver
let dataVolumeObserver: DataVolumeObserver

init(status: ConnectionStatus,
isHavingConnectivityIssues: Bool = false,
serverInfo: NetworkProtectionStatusServerInfo = MockStatusReporter.defaultServerInfo,
tunnelErrorMessage: String? = nil,
controllerErrorMessage: String? = nil) {
controllerErrorMessage: String? = nil,
dataVolume: DataVolume = .init()) {

let mockStatusObserver = MockConnectionStatusObserver()
mockStatusObserver.subject.send(status)
Expand All @@ -62,6 +64,10 @@ final class TunnelControllerViewModelTests: XCTestCase {
let mockControllerErrorMessageObserver = MockControllerErrorMesssageObserver()
mockControllerErrorMessageObserver.subject.send(controllerErrorMessage)
controllerErrorMessageObserver = mockControllerErrorMessageObserver

let mockDataVolumeObserver = MockDataVolumeObserver()
mockDataVolumeObserver.subject.send(dataVolume)
dataVolumeObserver = mockDataVolumeObserver
}

func forceRefresh() {
Expand Down Expand Up @@ -189,6 +195,24 @@ final class TunnelControllerViewModelTests: XCTestCase {
XCTAssertFalse(model.showServerDetails)
}

/// We expect the model to properly reflect the data volume.
///
@MainActor
func testProperlyReflectsDataVolume() async throws {
let controller = MockTunnelController()
let statusReporter = MockStatusReporter(status: .connected(connectedDate: Date()),
dataVolume: .init(bytesSent: 512000, bytesReceived: 1024000))
let model = TunnelControllerViewModel(
controller: controller,
onboardingStatusPublisher: Just(OnboardingStatus.completed).eraseToAnyPublisher(),
statusReporter: statusReporter,
vpnSettings: .init(defaults: .standard),
locationFormatter: MockVPNLocationFormatter(),
appLauncher: MockAppLauncher())

XCTAssertEqual(model.formattedDataVolume, .init(dataSent: "512 KB", dataReceived: "1 MB"))
}

/// We expect that setting the model's `isRunning` to `true`, will start the VPN.
///
@MainActor
Expand Down

0 comments on commit 14b0d31

Please sign in to comment.