-
-
Notifications
You must be signed in to change notification settings - Fork 359
Expand file tree
/
Copy pathSortableHeaderCellTests.swift
More file actions
74 lines (59 loc) · 2.69 KB
/
Copy pathSortableHeaderCellTests.swift
File metadata and controls
74 lines (59 loc) · 2.69 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import AppKit
import TableProPluginKit
@testable import TablePro
import Testing
@MainActor
@Suite("SortableHeaderCell")
struct SortableHeaderCellTests {
@Test("Title rect uses data cell horizontal padding")
func titleRectUsesDataCellHorizontalPadding() {
let cell = SortableHeaderCell(textCell: "id")
cell.supportsValueFilter = false
let titleRect = cell.titleRect(forBounds: NSRect(x: 10, y: 0, width: 100, height: 24))
#expect(titleRect.minX == 14)
#expect(titleRect.width == 92)
}
@Test("Narrow title rect does not produce negative width")
func narrowTitleRectDoesNotProduceNegativeWidth() {
let cell = SortableHeaderCell(textCell: "id")
let titleRect = cell.titleRect(forBounds: NSRect(x: 0, y: 0, width: 6, height: 24))
#expect(titleRect.minX == 3)
#expect(titleRect.width == 0)
}
@Test("Sorted title rect reserves trailing space for the indicator")
func sortedTitleRectReservesTrailingSpaceForIndicator() {
let bounds = NSRect(x: 0, y: 0, width: 100, height: 24)
let unsorted = SortableHeaderCell(textCell: "id")
let sorted = SortableHeaderCell(textCell: "id")
sorted.sortDirection = .ascending
let unsortedRect = unsorted.titleRect(forBounds: bounds)
let sortedRect = sorted.titleRect(forBounds: bounds)
#expect(sortedRect.minX == unsortedRect.minX)
#expect(sortedRect.width < unsortedRect.width)
#expect(sortedRect.maxX <= bounds.maxX - DataGridMetrics.cellHorizontalInset)
}
@Test("Priority badge shrinks the sorted title rect further")
func priorityBadgeShrinksSortedTitleRectFurther() {
let bounds = NSRect(x: 0, y: 0, width: 100, height: 24)
let sorted = SortableHeaderCell(textCell: "id")
sorted.sortDirection = .ascending
let prioritized = SortableHeaderCell(textCell: "id")
prioritized.sortDirection = .ascending
prioritized.sortPriority = 2
let sortedWidth = sorted.titleRect(forBounds: bounds).width
let prioritizedWidth = prioritized.titleRect(forBounds: bounds).width
#expect(prioritizedWidth < sortedWidth)
}
}
@MainActor
@Suite("DataGridView.makeRowNumberColumn")
struct DataGridRowNumberColumnTests {
@Test("Row-number column header uses a right-aligned SortableHeaderCell")
func rowNumberHeaderIsRightAlignedSortableCell() throws {
let column = DataGridView.makeRowNumberColumn()
let headerCell = try #require(column.headerCell as? SortableHeaderCell)
#expect(headerCell.alignment == .right)
#expect(column.identifier == ColumnIdentitySchema.rowNumberIdentifier)
#expect(column.title == "#")
}
}