-
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: test coverage for log list / details view models (#2308)
- Loading branch information
Showing
9 changed files
with
481 additions
and
8 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
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
67 changes: 67 additions & 0 deletions
67
ios/PolkadotVaultTests/Models+Generate/MLog+Generate.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,67 @@ | ||
// | ||
// MLog+Generate.swift | ||
// PolkadotVaultTests | ||
// | ||
// Created by Krzysztof Rodak on 22/01/2024. | ||
// | ||
|
||
import Foundation | ||
@testable import PolkadotVault | ||
|
||
extension MLog { | ||
static func generate( | ||
log: [History] = [History.generate()] | ||
) -> MLog { | ||
MLog( | ||
log: log | ||
) | ||
} | ||
} | ||
|
||
extension History { | ||
static func generate( | ||
order: UInt32 = 0, | ||
timestamp: String = "2021-01-01T00:00:00Z", | ||
events: [Event] = [Event.generate()] | ||
) -> History { | ||
History( | ||
order: order, | ||
timestamp: timestamp, | ||
events: events | ||
) | ||
} | ||
} | ||
|
||
extension Event { | ||
static func generate() -> Event { | ||
.identitiesWiped | ||
} | ||
} | ||
|
||
extension MLogDetails { | ||
static func generate( | ||
timestamp: String = "2021-01-01T00:00:00Z", | ||
events: [MEventMaybeDecoded] = [MEventMaybeDecoded.generate()] | ||
) -> MLogDetails { | ||
MLogDetails( | ||
timestamp: timestamp, | ||
events: events | ||
) | ||
} | ||
} | ||
|
||
extension MEventMaybeDecoded { | ||
static func generate( | ||
event: Event = Event.generate(), | ||
signedBy: MAddressCard? = .generate(), | ||
decoded: TransactionCardSet? = .generate(), | ||
verifierDetails: MVerifierDetails? = .generate() | ||
) -> MEventMaybeDecoded { | ||
MEventMaybeDecoded( | ||
event: event, | ||
signedBy: signedBy, | ||
decoded: decoded, | ||
verifierDetails: verifierDetails | ||
) | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
ios/PolkadotVaultTests/Models+Generate/MTransactionCardSet+Generate.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,59 @@ | ||
// | ||
// MTransactionCardSet+Generate.swift | ||
// PolkadotVaultTests | ||
// | ||
// Created by Krzysztof Rodak on 22/01/2024. | ||
// | ||
|
||
import Foundation | ||
@testable import PolkadotVault | ||
|
||
extension TransactionCardSet { | ||
static func generate( | ||
author: [TransactionCard]? = [TransactionCard.generate()], | ||
error: [TransactionCard]? = [TransactionCard.generate()], | ||
extensions: [TransactionCard]? = [TransactionCard.generate()], | ||
importingDerivations: [TransactionCard]? = [TransactionCard.generate()], | ||
message: [TransactionCard]? = [TransactionCard.generate()], | ||
meta: [TransactionCard]? = [TransactionCard.generate()], | ||
method: [TransactionCard]? = [TransactionCard.generate()], | ||
newSpecs: [TransactionCard]? = [TransactionCard.generate()], | ||
verifier: [TransactionCard]? = [TransactionCard.generate()], | ||
warning: [TransactionCard]? = [TransactionCard.generate()], | ||
typesInfo: [TransactionCard]? = [TransactionCard.generate()] | ||
) -> TransactionCardSet { | ||
TransactionCardSet( | ||
author: author, | ||
error: error, | ||
extensions: extensions, | ||
importingDerivations: importingDerivations, | ||
message: message, | ||
meta: meta, | ||
method: method, | ||
newSpecs: newSpecs, | ||
verifier: verifier, | ||
warning: warning, | ||
typesInfo: typesInfo | ||
) | ||
} | ||
} | ||
|
||
extension TransactionCard { | ||
static func generate( | ||
index: UInt32 = 0, | ||
indent: UInt32 = 0, | ||
card: Card = Card.generate() | ||
) -> TransactionCard { | ||
TransactionCard( | ||
index: index, | ||
indent: indent, | ||
card: card | ||
) | ||
} | ||
} | ||
|
||
extension Card { | ||
static func generate() -> Card { | ||
.eraImmortalCard | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
ios/PolkadotVaultTests/Screens/Logs/LogNoteModalViewModelTests.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,85 @@ | ||
// | ||
// LogNoteModalViewModelTests.swift | ||
// PolkadotVaultTests | ||
// | ||
// Created by Krzysztof Rodak on 22/01/2024. | ||
// | ||
|
||
import Combine | ||
import Foundation | ||
@testable import PolkadotVault | ||
import SwiftUI | ||
import XCTest | ||
|
||
final class LogNoteModalViewModelTests: XCTestCase { | ||
private var viewModel: LogNoteModal.ViewModel! | ||
private var logsServiceMock: LogsServicingMock! | ||
private var cancelBag: Set<AnyCancellable>! | ||
private var isPresented: Bool = false | ||
|
||
override func setUp() { | ||
super.setUp() | ||
logsServiceMock = LogsServicingMock() | ||
isPresented = false | ||
viewModel = LogNoteModal.ViewModel( | ||
isPresented: Binding(get: { self.isPresented }, set: { self.isPresented = $0 }), | ||
logsService: logsServiceMock | ||
) | ||
cancelBag = [] | ||
} | ||
|
||
override func tearDown() { | ||
viewModel = nil | ||
logsServiceMock = nil | ||
cancelBag = nil | ||
super.tearDown() | ||
} | ||
|
||
func testInit_SetsIsActionDisabledToTrue() { | ||
// Then | ||
XCTAssertTrue(viewModel.isActionDisabled) | ||
} | ||
|
||
func testNoteChange_UpdatesIsActionDisabled() { | ||
// When | ||
viewModel.note = "new note" | ||
|
||
// Then | ||
XCTAssertFalse(viewModel.isActionDisabled) | ||
} | ||
|
||
func testOnCancelTap_SetsIsPresentedToFalse() { | ||
// When | ||
viewModel.onCancelTap() | ||
|
||
// Then | ||
XCTAssertFalse(isPresented) | ||
} | ||
|
||
func testOnDoneTap_WithSuccess() { | ||
// Given | ||
viewModel.note = "new note" | ||
|
||
// When | ||
viewModel.onDoneTap() | ||
logsServiceMock.addCommentToLogsReceivedCompletion.first?(.success(())) | ||
|
||
// Then | ||
XCTAssertFalse(isPresented) | ||
} | ||
|
||
func testOnDoneTap_WithFailure() { | ||
// Given | ||
viewModel.note = "new note" | ||
let error = ServiceError(message: "Error") | ||
let presentableError: ErrorBottomModalViewModel = .alertError(message: error.localizedDescription) | ||
|
||
// When | ||
viewModel.onDoneTap() | ||
logsServiceMock.addCommentToLogsReceivedCompletion.first?(.failure(error)) | ||
|
||
// Then | ||
XCTAssertEqual(viewModel.presentableError, presentableError) | ||
XCTAssertTrue(viewModel.isPresentingError) | ||
} | ||
} |
Oops, something went wrong.