-
-
Notifications
You must be signed in to change notification settings - Fork 143
Expand file tree
/
Copy pathQueryTabManagerTests.swift
More file actions
60 lines (50 loc) · 1.89 KB
/
QueryTabManagerTests.swift
File metadata and controls
60 lines (50 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//
// QueryTabManagerTests.swift
// TableProTests
//
// Locks the contract for selectedTabAndIndex — the helper that
// MainContentCoordinator+Pagination (and future coordinator extensions)
// use in place of the selectedTabIndex + bounds-check + tabs[index]
// pattern. The tests guard against silent staleness if selectedTabId
// ever points to a removed tab.
//
import Foundation
import Testing
@testable import TablePro
@Suite("QueryTabManager.selectedTabAndIndex")
@MainActor
struct QueryTabManagerSelectedTabAndIndexTests {
@Test("returns nil when no tab is selected")
func nilWhenNoSelection() {
let manager = QueryTabManager()
#expect(manager.selectedTabAndIndex == nil)
}
@Test("returns the selected tab and its index after addTableTab")
func returnsSelectedTabAfterAdd() {
let manager = QueryTabManager()
manager.addTableTab(tableName: "users")
let result = manager.selectedTabAndIndex
#expect(result?.index == 0)
#expect(result?.tab.tableContext.tableName == "users")
}
@Test("returns nil when selectedTabId points to a removed tab")
func nilWhenSelectionIsStale() {
let manager = QueryTabManager()
manager.addTableTab(tableName: "users")
let staleId = manager.tabs[0].id
manager.tabs.removeAll()
manager.selectedTabId = staleId
#expect(manager.selectedTabAndIndex == nil)
}
@Test("returns the correct (tab, index) pair after switching tabs")
func returnsCorrectPairAfterSwitch() {
let manager = QueryTabManager()
manager.addTableTab(tableName: "users")
manager.addTableTab(tableName: "orders")
let firstId = manager.tabs[0].id
manager.selectedTabId = firstId
let result = manager.selectedTabAndIndex
#expect(result?.index == 0)
#expect(result?.tab.tableContext.tableName == "users")
}
}