Skip to content

A native macOS / windows / Linux database IDE built with Swift and AppKit. Connect to PostgreSQL, MySQL, SQLite, and Redis from a single app with a fast, keyboard-driven interface.

C++

test(postgres): add RED schema selection coverage

Tobiaf82b5d72100
diff --git a/macos/Tests/GridexTests/SidebarSchemaSelectionTests.swift b/macos/Tests/GridexTests/SidebarSchemaSelectionTests.swift
new file mode 100644
index 0000000..62946ac
--- /dev/null
+++ b/macos/Tests/GridexTests/SidebarSchemaSelectionTests.swift
@@ -0,0 +1,63 @@
+import XCTest
+@testable import Gridex
+
+final class SidebarSchemaSelectionTests: XCTestCase {
+ func test_postgresPreservesPreviouslySelectedAccessibleSchema() {
+ XCTAssertEqual(
+ SidebarSchemaSelection.resolve(
+ previous: "tenant_b",
+ for: .postgresql,
+ schemas: ["public", "tenant_a", "tenant_b"]
+ ),
+ "tenant_b"
+ )
+ }
+
+ func test_postgresPrefersPublicWhenPreviousSchemaIsMissing() {
+ XCTAssertEqual(
+ SidebarSchemaSelection.resolve(
+ previous: "removed",
+ for: .postgresql,
+ schemas: ["tenant_a", "public"]
+ ),
+ "public"
+ )
+ }
+
+ func test_postgresUsesFirstSortedSchemaWhenPublicIsAbsent() {
+ XCTAssertEqual(
+ SidebarSchemaSelection.resolve(
+ previous: nil,
+ for: .postgresql,
+ schemas: ["tenant_b", "tenant_a"]
+ ),
+ "tenant_a"
+ )
+ }
+
+ func test_nonPostgresNeverCreatesSidebarSchemaSelection() {
+ XCTAssertNil(
+ SidebarSchemaSelection.resolve(
+ previous: "app",
+ for: .mysql,
+ schemas: ["app", "information_schema"]
+ )
+ )
+ }
+
+ func test_sidebarItemRetainsSchemaForNestedActions() {
+ let item = SidebarItem(
+ title: "orders",
+ type: .table("orders"),
+ schema: "tenant_a"
+ )
+ XCTAssertEqual(item.schema, "tenant_a")
+ }
+
+ func test_tableReferenceDistinguishesSameNameAcrossSchemas() {
+ let publicOrders = AppState.TableReference(name: "orders", schema: "public")
+ let tenantOrders = AppState.TableReference(name: "orders", schema: "tenant_a")
+ XCTAssertNotEqual(publicOrders, tenantOrders)
+ XCTAssertEqual(Set([publicOrders, tenantOrders]).count, 2)
+ }
+}