-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: ios: Unit tests for recover key set and no key sets (#2317)
- Loading branch information
Showing
5 changed files
with
470 additions
and
40 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
117 changes: 117 additions & 0 deletions
117
ios/PolkadotVaultTests/Screens/CreateKey/RecoverKeySet/RecoverKeySetNameViewModelTests.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,117 @@ | ||
// | ||
// RecoverKeySetNameViewModelTests.swift | ||
// PolkadotVaultTests | ||
// | ||
// Created by Krzysztof Rodak on 29/01/2024. | ||
// | ||
|
||
import Foundation | ||
@testable import PolkadotVault | ||
import SwiftUI | ||
import XCTest | ||
|
||
final class RecoverKeySetNameViewModelTests: XCTestCase { | ||
private var viewModel: RecoverKeySetNameView.ViewModel! | ||
private var seedsMediatorMock: SeedsMediatingMock! | ||
private var isPresented: Bool = false | ||
private var onCompletionExecuted: Bool = false | ||
|
||
override func setUp() { | ||
super.setUp() | ||
seedsMediatorMock = SeedsMediatingMock() | ||
isPresented = false | ||
onCompletionExecuted = false | ||
viewModel = RecoverKeySetNameView.ViewModel( | ||
seedsMediator: seedsMediatorMock, | ||
isPresented: Binding(get: { self.isPresented }, set: { self.isPresented = $0 }), | ||
onCompletion: { _ in self.onCompletionExecuted = true } | ||
) | ||
} | ||
|
||
override func tearDown() { | ||
viewModel = nil | ||
seedsMediatorMock = nil | ||
super.tearDown() | ||
} | ||
|
||
func testInitialSetup() { | ||
// Then | ||
XCTAssertTrue(viewModel.seedName.isEmpty) | ||
XCTAssertFalse(viewModel.isPresentingDetails) | ||
} | ||
|
||
func testOnBackTap() { | ||
// When | ||
viewModel.onBackTap() | ||
|
||
// Then | ||
XCTAssertFalse(isPresented) | ||
} | ||
|
||
func testOnNextTap() { | ||
// When | ||
viewModel.onNextTap() | ||
|
||
// Then | ||
XCTAssertTrue(viewModel.isPresentingDetails) | ||
} | ||
|
||
func testIsActionAvailable() { | ||
// Given | ||
viewModel.seedName = "ValidSeedName" | ||
seedsMediatorMock.checkSeedCollisionSeedNameReturnValue = false | ||
|
||
// When | ||
let result = viewModel.isActionAvailable() | ||
|
||
// Then | ||
XCTAssertTrue(result) | ||
} | ||
|
||
func testIsActionNotAvailableDueToEmptySeedName() { | ||
// Given | ||
viewModel.seedName = "" | ||
|
||
// When | ||
let result = viewModel.isActionAvailable() | ||
|
||
// Then | ||
XCTAssertFalse(result) | ||
} | ||
|
||
func testIsActionNotAvailableDueToSeedNameCollision() { | ||
// Given | ||
viewModel.seedName = "CollidingSeedName" | ||
seedsMediatorMock.checkSeedCollisionSeedNameReturnValue = true | ||
|
||
// When | ||
let result = viewModel.isActionAvailable() | ||
|
||
// Then | ||
XCTAssertFalse(result) | ||
} | ||
|
||
func testOnSubmitTap_ActionAvailable() { | ||
// Given | ||
viewModel.seedName = "ValidSeedName" | ||
seedsMediatorMock.checkSeedCollisionSeedNameReturnValue = false | ||
|
||
// When | ||
viewModel.onSubmitTap() | ||
|
||
// Then | ||
XCTAssertTrue(viewModel.isPresentingDetails) | ||
} | ||
|
||
func testOnSubmitTap_ActionNotAvailable() { | ||
// Given | ||
viewModel.seedName = "CollidingSeedName" | ||
seedsMediatorMock.checkSeedCollisionSeedNameReturnValue = true | ||
|
||
// When | ||
viewModel.onSubmitTap() | ||
|
||
// Then | ||
XCTAssertFalse(viewModel.isPresentingDetails) | ||
} | ||
} |
Oops, something went wrong.