test(ios): unit tests for the three extracted iOS view models#1173
Merged
test(ios): unit tests for the three extracted iOS view models#1173
Conversation
e4fe564 to
d9c72fc
Compare
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes the original audit backlog by adding Swift Testing coverage for the three view models extracted in PR #1164, #1165, #1166. Each VM now has tests against an in-memory
DatabaseDriverandSecureStoremock, which lock in the refactor surface so future regressions surface in CI rather than at runtime.Coverage
DataBrowserViewModelTests(8 tests):loadwithout session setsloadErrorloadwith session populatescolumns,legacyRows,columnDetails,hasPrimaryKeysapplySearch/clearSearchtogglehasActiveSearchandactiveSearchTextgoToPreviousPageclamps at 0 (no underflow)primaryKeyValues(for:)extracts only PK columns from a rowdeleteRowreturnstrueon success and runs DELETE SQL through the driverdeleteRowreturnsfalseand setsoperationErroron driver failurechangePageSizeresetscurrentPageandtotalRowsConnectionFormViewModelTests(7 tests):init()reads default safe mode fromAppPreferencesinit(editing:)hydrates name, type, host, port, username, database, SSL, safe mode from a stored connectiontypeupdatesportto the type's default (didSet)canSaverequires database for SQLite, host for server typesloadStoredCredentials(secureStore:)populates password and SSH password from the seeded mock storeclearSelectedFile()resets URL and databasecreateNewDatabase()builds a.dbURL in Documents and primes the connection nameRowDetailViewModelTests(8 tests):canEditrequires session, table, primary key, and not safe-mode-blockedstartEditingpopulateseditedValuesfrom the current rowcancelEditingclears edited valuestoggleNullflips between empty string and nilsaveChangeswith no changes early-returns true and exits edit mode without firing UPDATEsaveChangeswith changes runs UPDATE with primary keys and modified columnssaveChangesreturns false and setsoperationErrorwhen no primary key value is presentloadFullValuepopulates the per-cell override and clearsloadingCellMocks
MockDatabaseDriveris@unchecked Sendable(state mutated only from@MainActortest scope), implements allDatabaseDriverprotocol requirements, and exposesscriptedExecuteResults: [Result<QueryResult, Error>]for sequenced responsesMockSecureStoreis an in-memory[String: String]backing theSecureStoreprotocol, withseed(_:_:)for test setup andfailNextStorefor forcing keychain write failuresSignature change
ConnectionFormViewModel.loadStoredCredentials(secureStore:),.testConnection(appState:secureStore:), and.save(appState:secureStore:)now acceptany SecureStoreinstead of the concreteKeychainSecureStore.KeychainSecureStore: SecureStore, so all existing call sites (ConnectionFormView) continue to work unchanged.Required one-time Xcode setup
The test target is not in
TableProMobile.xcodeprojyet. Before the tests can run:TableProMobile.xcodeprojin XcodeTableProMobileTests, Target to Test:TableProMobile, Testing System: Swift TestingTableProMobileTests.swiftXcode generated; the existing files inTableProMobileTests/will be picked up via synchronized groupsInstructions are also in
TableProMobile/TableProMobileTests/README.md.Test plan
xcodebuild ... -only-testing:TableProMobileTests/DataBrowserViewModelTeststo confirm filterable