-
-
Notifications
You must be signed in to change notification settings - Fork 297
fix(welcome): show new database groups without restart (#1704) #1709
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+158
−11
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| // | ||
| // WelcomeViewModelTests.swift | ||
| // TableProTests | ||
| // | ||
|
|
||
| @testable import TablePro | ||
| import TableProPluginKit | ||
| import XCTest | ||
|
|
||
| @MainActor | ||
| final class WelcomeViewModelTests: XCTestCase { | ||
| private var suiteName: String! | ||
| private var defaults: UserDefaults! | ||
| private var syncSuiteName: String! | ||
| private var syncDefaults: UserDefaults! | ||
| private var connectionFileURL: URL! | ||
| private var groupStorage: GroupStorage! | ||
| private var connectionStorage: ConnectionStorage! | ||
| private var viewModel: WelcomeViewModel! | ||
|
|
||
| override func setUp() { | ||
| super.setUp() | ||
| let unique = UUID().uuidString | ||
| suiteName = "com.TablePro.tests.WelcomeViewModel.\(unique)" | ||
| syncSuiteName = "com.TablePro.tests.WelcomeViewModel.sync.\(unique)" | ||
| guard let defaults = UserDefaults(suiteName: suiteName), | ||
| let syncDefaults = UserDefaults(suiteName: syncSuiteName) else { | ||
| XCTFail("Could not create isolated UserDefaults suites") | ||
| return | ||
| } | ||
| self.defaults = defaults | ||
| self.syncDefaults = syncDefaults | ||
| let tracker = SyncChangeTracker(metadataStorage: SyncMetadataStorage(userDefaults: syncDefaults)) | ||
| connectionFileURL = FileManager.default.temporaryDirectory | ||
| .appendingPathComponent("tablepro-tests") | ||
| .appendingPathComponent("welcome-connections_\(unique).json") | ||
| try? FileManager.default.createDirectory( | ||
| at: connectionFileURL.deletingLastPathComponent(), | ||
| withIntermediateDirectories: true | ||
| ) | ||
| connectionStorage = ConnectionStorage( | ||
| fileURL: connectionFileURL, | ||
| userDefaults: defaults, | ||
| syncTracker: tracker | ||
| ) | ||
| groupStorage = GroupStorage( | ||
| userDefaults: defaults, | ||
| syncTracker: tracker, | ||
| connectionStorage: self.connectionStorage | ||
| ) | ||
| viewModel = WelcomeViewModel(services: makeServices()) | ||
| } | ||
|
|
||
| override func tearDown() { | ||
| defaults.removePersistentDomain(forName: suiteName) | ||
| syncDefaults.removePersistentDomain(forName: syncSuiteName) | ||
| try? FileManager.default.removeItem(at: connectionFileURL) | ||
| viewModel = nil | ||
| groupStorage = nil | ||
| connectionStorage = nil | ||
| defaults = nil | ||
| syncDefaults = nil | ||
| suiteName = nil | ||
| syncSuiteName = nil | ||
| connectionFileURL = nil | ||
| super.tearDown() | ||
| } | ||
|
|
||
| private func makeServices() -> AppServices { | ||
| let live = AppServices.live | ||
| return AppServices( | ||
| appEvents: live.appEvents, | ||
| appSettings: live.appSettings, | ||
| appSettingsStorage: live.appSettingsStorage, | ||
| connectionStorage: connectionStorage, | ||
| databaseManager: live.databaseManager, | ||
| pluginManager: live.pluginManager, | ||
| schemaService: live.schemaService, | ||
| schemaProviderRegistry: live.schemaProviderRegistry, | ||
| sqlFavoriteManager: live.sqlFavoriteManager, | ||
| favoriteTablesStorage: live.favoriteTablesStorage, | ||
| aiChatStorage: live.aiChatStorage, | ||
| aiKeyStorage: live.aiKeyStorage, | ||
| groupStorage: groupStorage, | ||
| tagStorage: live.tagStorage, | ||
| sshProfileStorage: live.sshProfileStorage, | ||
| licenseManager: live.licenseManager, | ||
| conflictResolver: live.conflictResolver, | ||
| syncMetadataStorage: live.syncMetadataStorage, | ||
| favoritesExpansionState: live.favoritesExpansionState, | ||
| linkedFolderWatcher: live.linkedFolderWatcher, | ||
| queryHistoryManager: live.queryHistoryManager, | ||
| dateFormattingService: live.dateFormattingService, | ||
| copilotService: live.copilotService, | ||
| mcpServerManager: live.mcpServerManager, | ||
| syncTracker: live.syncTracker, | ||
| themeEngine: live.themeEngine | ||
| ) | ||
| } | ||
|
|
||
| private func groupIds(in nodes: [ConnectionGroupTreeNode]) -> [UUID] { | ||
| nodes.flatMap { node -> [UUID] in | ||
| guard case .group(let group, let children) = node else { return [] } | ||
| return [group.id] + groupIds(in: children) | ||
| } | ||
| } | ||
|
|
||
| func testCreateGroupShowsImmediatelyInTree() throws { | ||
| XCTAssertTrue(groupIds(in: viewModel.treeItems).isEmpty) | ||
|
|
||
| viewModel.createGroup(name: "Production", color: .red, parentId: nil) | ||
|
|
||
| let created = try XCTUnwrap(groupStorage.loadGroups().first { $0.name == "Production" }) | ||
| XCTAssertTrue(groupIds(in: viewModel.treeItems).contains(created.id)) | ||
| XCTAssertTrue(viewModel.expandedGroupIds.contains(created.id)) | ||
| } | ||
|
|
||
| func testCreateSubgroupExpandsParentAndChild() throws { | ||
| viewModel.createGroup(name: "Parent", color: .none, parentId: nil) | ||
| let parentId = try XCTUnwrap(groupStorage.loadGroups().first { $0.name == "Parent" }?.id) | ||
|
|
||
| viewModel.createGroup(name: "Child", color: .none, parentId: parentId) | ||
| let childId = try XCTUnwrap(groupStorage.loadGroups().first { $0.name == "Child" }?.id) | ||
|
|
||
| XCTAssertTrue(groupIds(in: viewModel.treeItems).contains(parentId)) | ||
| XCTAssertTrue(groupIds(in: viewModel.treeItems).contains(childId)) | ||
| XCTAssertTrue(viewModel.expandedGroupIds.contains(parentId)) | ||
| XCTAssertTrue(viewModel.expandedGroupIds.contains(childId)) | ||
| } | ||
|
|
||
| func testCreateDuplicateNameDoesNotAddSecondNode() { | ||
| viewModel.createGroup(name: "Staging", color: .orange, parentId: nil) | ||
| viewModel.createGroup(name: "staging", color: .blue, parentId: nil) | ||
|
|
||
| let stagingNodes = groupIds(in: viewModel.treeItems).filter { id in | ||
| viewModel.groups.first { $0.id == id }?.name.lowercased() == "staging" | ||
| } | ||
| XCTAssertEqual(stagingNodes.count, 1) | ||
| } | ||
| } |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When this is reached from
Move to Group > New Group...,pendingMoveToNewGroupis already populated. IfaddGrouprejects the new group (for example a duplicate sibling name), this early return leaves that pending list set while the sheet still dismisses; the next unrelated successful group creation will hit the laterpendingMoveToNewGroupblock and move the old connections into that new group unexpectedly. Clear the pending move on the failure path or only retain it while the sheet remains active.Useful? React with 👍 / 👎.