-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: ios: Add unit tests for Sign Specs and Settings Backup Modal (#…
…2303) Co-authored-by: Pavel Rybalko <pavel@parity.io>
- Loading branch information
Showing
6 changed files
with
307 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
...olkadotVaultTests/Screens/Settings/Subview/Backup/SettingsBackupModalViewModelTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// | ||
// SettingsBackupModalViewModelTests.swift | ||
// PolkadotVaultTests | ||
// | ||
// Created by Krzysztof Rodak on 22/01/2024. | ||
// | ||
|
||
import Combine | ||
import Foundation | ||
@testable import PolkadotVault | ||
import SwiftUI | ||
import XCTest | ||
|
||
final class SettingsBackupModalViewModelTests: XCTestCase { | ||
private var viewModel: SettingsBackupModal.ViewModel! | ||
private var isPresented: Bool! | ||
|
||
override func setUp() { | ||
super.setUp() | ||
isPresented = false | ||
viewModel = SettingsBackupModal.ViewModel( | ||
isPresented: Binding(get: { self.isPresented }, set: { self.isPresented = $0 }), | ||
viewModel: SettingsBackupViewModel( | ||
keyName: "Test Key", | ||
seedPhrase: SeedPhraseViewModel( | ||
seedPhrase: "Test Phrase" | ||
) | ||
) | ||
) | ||
} | ||
|
||
override func tearDown() { | ||
viewModel = nil | ||
super.tearDown() | ||
} | ||
|
||
func testInit_SetsAnimateBackgroundToFalse() { | ||
// Then | ||
XCTAssertFalse(viewModel.animateBackground) | ||
} | ||
|
||
func testOnAppear_SetsSnackbar() { | ||
// When | ||
viewModel.onAppear() | ||
|
||
// Then | ||
XCTAssertEqual(viewModel.snackbar.viewModel.title, Localizable.Settings.BackupModal.Label.snackbar.string) | ||
XCTAssertTrue(viewModel.snackbar.viewModel.tapToDismiss == false) | ||
XCTAssertTrue(viewModel.snackbar.isSnackbarPresented) | ||
} | ||
|
||
func testDismissModal_TogglesAnimateBackground() { | ||
// Given | ||
viewModel.animateBackground = false | ||
|
||
// When | ||
viewModel.dismissModal() | ||
|
||
// Then | ||
XCTAssertTrue(viewModel.animateBackground) | ||
} | ||
|
||
func testDismissModal_HidesModal() { | ||
// Given | ||
let expectation = XCTestExpectation() | ||
viewModel.animateBackground = false | ||
viewModel.dismissModal() | ||
|
||
DispatchQueue.main.asyncAfter(deadline: .now() + 1) { | ||
// Then | ||
XCTAssertFalse(self.isPresented) | ||
expectation.fulfill() | ||
} | ||
|
||
// When | ||
wait(for: [expectation], timeout: 2) | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
...PolkadotVaultTests/Screens/Settings/Subview/SignSpecs/SignSpecDetailsViewModelTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// | ||
// SignSpecDetailsViewModelTests.swift | ||
// PolkadotVaultTests | ||
// | ||
// Created by Krzysztof Rodak on 19/01/2024. | ||
// | ||
|
||
import Combine | ||
import Foundation | ||
@testable import PolkadotVault | ||
import XCTest | ||
|
||
final class SignSpecDetailsViewModelTests: XCTestCase { | ||
private var viewModel: SignSpecDetails.ViewModel! | ||
private var cancelBag: CancelBag! | ||
private var metadataSpecsVersion: String! | ||
|
||
override func setUp() { | ||
super.setUp() | ||
metadataSpecsVersion = "version" | ||
viewModel = SignSpecDetails.ViewModel(content: .generate(), type: .metadata(metadataSpecsVersion: "")) | ||
cancelBag = CancelBag() | ||
} | ||
|
||
override func tearDown() { | ||
viewModel = nil | ||
cancelBag.cancel() | ||
cancelBag = nil | ||
super.tearDown() | ||
} | ||
|
||
func testOnBackTap_SendsDismissRequest() { | ||
// Given | ||
let dismissRequestExpectation = expectation(description: "Dismiss request sent") | ||
|
||
viewModel.dismissViewRequest | ||
.sink { _ in | ||
// Then | ||
dismissRequestExpectation.fulfill() | ||
} | ||
.store(in: cancelBag) | ||
|
||
// When | ||
viewModel.onBackTap() | ||
|
||
wait(for: [dismissRequestExpectation], timeout: 1.0) | ||
} | ||
|
||
func testTitle_ForMetadataType() { | ||
// Given | ||
viewModel = SignSpecDetails.ViewModel(content: .generate(), type: .metadata(metadataSpecsVersion: "")) | ||
|
||
// Then | ||
XCTAssertEqual(viewModel.title, Localizable.SignSpecsDetails.Label.Title.metadata.string) | ||
} | ||
|
||
func testTitle_ForNetworkType() { | ||
// Given | ||
viewModel = SignSpecDetails.ViewModel(content: .generate(), type: .network) | ||
|
||
// Then | ||
XCTAssertEqual(viewModel.title, Localizable.SignSpecsDetails.Label.Title.specs.string) | ||
} | ||
|
||
func testQRCodeSectionTitle_ForMetadataType() { | ||
// Given | ||
viewModel = SignSpecDetails.ViewModel(content: .generate(), type: .metadata(metadataSpecsVersion: "")) | ||
|
||
// Then | ||
XCTAssertEqual(viewModel.qrCodeSectionTitle, Localizable.SignSpecsDetails.Label.ScanQRCode.metadata.string) | ||
} | ||
|
||
func testQRCodeSectionTitle_ForNetworkType() { | ||
// Given | ||
viewModel = SignSpecDetails.ViewModel(content: .generate(), type: .network) | ||
|
||
// Then | ||
XCTAssertEqual(viewModel.qrCodeSectionTitle, Localizable.SignSpecsDetails.Label.ScanQRCode.specs.string) | ||
} | ||
} |
Oops, something went wrong.