diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index bcf1fde..0308ff9 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -279,5 +279,5 @@ jobs: echo "| SHA-256 DMG | \`${DMG_SHA256}\` |" echo "| SHA-256 ZIP | \`${ZIP_SHA256}\` |" echo "| Архитектуры | arm64 + x86_64 |" - echo "| Тесты | 161 XCTest |" + echo "| Тесты | 165 XCTest |" } >> "$GITHUB_STEP_SUMMARY" diff --git a/README.md b/README.md index 491115b..2c5653f 100644 --- a/README.md +++ b/README.md @@ -256,7 +256,7 @@ Sources/ DiskScopeKit/ Core/ сканер, дерево, форматирование, treemap-раскладка UI/ SwiftUI-интерфейс - App/ AppModel — состояние, сканирование, действия + App/ AppModel и feature-модели (search, cleanup, disk, history…) DiskScope/ точка входа приложения DiskScopeCLI/ headless-сканер для замеров DiskScopeSnapshots/ рендер интерфейса в PNG без screen recording @@ -371,7 +371,7 @@ Headless-сканер для бенчмарков: ## Тесты -161 тест: сравнение суммы скана с `du`, агрегация мелких файлов, пакеты, +165 тестов: сравнение суммы скана с `du`, агрегация мелких файлов, пакеты, симлинки, Unicode-имена, отказ доступа, отмена, copy-on-write удаление, свойства squarified-раскладки, вложенные ячейки, полный цикл `AppModel` (скан → навигация → фильтры), даты создания и изменения, правила очистки, diff --git a/ROADMAP.md b/ROADMAP.md index 8e3c18a..6ca6717 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -1,6 +1,6 @@ # Roadmap -**Цикл:** 3.0 · **Релиз:** 2.0.0 · **Обновлено:** 23 октября 2026 +**Цикл:** 3.0 · **Релиз:** 2.0.0 · **Обновлено:** 24 октября 2026 **Задачи:** [issues](https://github.com/fso13/DiskScope/issues) · **Этапы:** [milestones](https://github.com/fso13/DiskScope/milestones) · **Новые:** [#57–#72](https://github.com/fso13/DiskScope/issues?q=is%3Aissue+is%3Aopen) @@ -23,7 +23,7 @@ | 2.0 — Платформа | 6/6: локализация, notarization/Sparkle/Homebrew, CLI, App Intents, доступность, меню-бар | | Backlog | 5/5: кэш, параллельный скан, бюджеты, старые файлы, APFS-клоны | -Текущая база: **161 XCTest**, 17,9 тыс. строк исходников, 398 ключей +Текущая база: **165 XCTest**, 17,9 тыс. строк исходников, 398 ключей локализации, `main` зелёный. ## Принципы @@ -39,7 +39,7 @@ | Область | Симптом | Риск | | --- | --- | --- | -| `AppModel` | 1561 строка, 8 вкладок, cleanup/search/disk/history в одном типе | любая фича замедляет сборку и тесты | +| `AppModel` | 497 строк; состояние разложено на feature-модели, координатор остался тонким | дальнейшие фичи не раздувают центр | | `DiskScanner` | 1009 строк: bulk/readdir, парсинг, сессия и TreeBuilder вместе | сложно менять под APFS/параллельность | | Кэш | хранит всё дерево, один корень, FSEvents-тесты со `sleep` | хрупкость и большой файл | | CI | Dependency review падает, нет coverage/benchmark/release smoke | регрессии ловятся поздно | @@ -93,7 +93,7 @@ F9 стартует как research, а не как обещание. | ID | Задача | Приоритет | Оценка | Когда | | --- | --- | --- | --- | --- | -| [T1](https://github.com/fso13/DiskScope/issues/66) | **Разложить `AppModel`** на feature-модели (`CleanupStore`, `SearchStore`, `DiskStore`, `BudgetStore`) с инъекцией зависимостей | P1 | L (6 д) | до F1 | +| [T1](https://github.com/fso13/DiskScope/issues/66) | **Разложить `AppModel`** на feature-модели с инъекцией зависимостей — закрыт, 497 строк | P1 | L (6 д) | сделано | | [T2](https://github.com/fso13/DiskScope/issues/67) | **Разложить `DiskScanner`**: `BulkDirectoryReader`, `ReaddirReader`, `ScanSession`, `TreeBuilder`, протокол + фикстуры | P1 | L (8 д) | до F9/T3 | | [T3](https://github.com/fso13/DiskScope/issues/68) | **Кэш 2.0**: сжатие/TTL/версии, partial reuse, инъекция FSEvents вместо `sleep` | P1 | L (6 д) | после T2 | | [T4](https://github.com/fso13/DiskScope/issues/69) | **CI/release**: coverage ≥85% Core, benchmark baseline, snapshot/UI smoke, release/notarization dry-run, починить Dependency review, поднять версию | P1 | M (5 д) | сейчас | diff --git a/Sources/DiskScope/DiskScopeApp.swift b/Sources/DiskScope/DiskScopeApp.swift index 43b8404..17c504b 100644 --- a/Sources/DiskScope/DiskScopeApp.swift +++ b/Sources/DiskScope/DiskScopeApp.swift @@ -116,12 +116,12 @@ struct DiskScopeApp: App { Divider() Button("Наверх") { model.goUp() } .keyboardShortcut(.upArrow, modifiers: .command) - .disabled(!model.canGoUp) + .disabled(!model.browser.canGoUp) Button("Показать в Finder") { if model.selection.isEmpty { - model.revealCurrentFolder() + model.browser.revealCurrentFolder() } else { - model.revealSelection() + model.browser.revealSelection() } } .keyboardShortcut("r", modifiers: [.command, .shift]) diff --git a/Sources/DiskScopeKit/App/AppModel+Folders.swift b/Sources/DiskScopeKit/App/AppModel+Folders.swift index e488fbd..c51bb97 100644 --- a/Sources/DiskScopeKit/App/AppModel+Folders.swift +++ b/Sources/DiskScopeKit/App/AppModel+Folders.swift @@ -19,7 +19,7 @@ extension AppModel { } public func scanHome() { - scan(path: homePath) + scan(path: browser.homePath) } public func scanVolume(_ volume: VolumeInfo) { diff --git a/Sources/DiskScopeKit/App/AppModel+SearchActions.swift b/Sources/DiskScopeKit/App/AppModel+SearchActions.swift index 2e088aa..44dd1a0 100644 --- a/Sources/DiskScopeKit/App/AppModel+SearchActions.swift +++ b/Sources/DiskScopeKit/App/AppModel+SearchActions.swift @@ -4,7 +4,7 @@ import Foundation extension AppModel { public func revealSearchHit(_ hit: SearchHit) { search.show = false - reveal(indices: [hit.index]) + browser.reveal(indices: [hit.index]) } public func navigateToSearchHit(_ hit: SearchHit) { @@ -17,7 +17,7 @@ extension AppModel { if node.parent >= 0 { navigate(to: node.parent) } - reveal(indices: [hit.index]) + browser.reveal(indices: [hit.index]) } } diff --git a/Sources/DiskScopeKit/App/AppModel.swift b/Sources/DiskScopeKit/App/AppModel.swift index 977e896..7329767 100644 --- a/Sources/DiskScopeKit/App/AppModel.swift +++ b/Sources/DiskScopeKit/App/AppModel.swift @@ -76,6 +76,7 @@ public final class AppModel: ObservableObject { @Published public internal(set) var scan: ScanController @Published public internal(set) var nav = NavigationModel() + @Published public internal(set) var browser = BrowserModel() @Published public var tab: Tab = .map { didSet { if tab == .cleanup { @@ -139,7 +140,7 @@ public final class AppModel: ObservableObject { environmentProvider: { [weak self] in guard let self else { return .current() } return CleanupEnvironment( - homePath: self.homePath, + homePath: self.browser.homePath, runningBundleIdentifiers: self.runningBundleIdentifiers() ) }, @@ -163,6 +164,10 @@ public final class AppModel: ObservableObject { nav.objectWillChange.sink { [weak self] _ in self?.objectWillChange.send() }.store(in: &cancellables) + browser.attach(appModel: self) + browser.objectWillChange.sink { [weak self] _ in + self?.objectWillChange.send() + }.store(in: &cancellables) inspector.attach( treeProvider: { [weak self] in self?.tree }, currentIndexProvider: { [weak self] in self?.currentIndex ?? 0 }, @@ -178,8 +183,8 @@ public final class AppModel: ObservableObject { currentIndexProvider: { [weak self] in self?.currentIndex ?? 0 }, searchProvider: { [weak self] in self?.searchText ?? "" }, categoryProvider: { [weak self] in self?.categoryFilter }, - currentNameProvider: { [weak self] in self?.currentName ?? "" }, - rootDisplayNameProvider: { [weak self] in self?.rootDisplayName ?? "DiskScope" }, + currentNameProvider: { [weak self] in self?.browser.currentName ?? "" }, + rootDisplayNameProvider: { [weak self] in self?.browser.rootDisplayName ?? "DiskScope" }, toast: { [weak self] text, symbol in self?.showToast(text, symbol: symbol) }, error: { [weak self] message in self?.errorMessage = message } ) @@ -197,7 +202,7 @@ public final class AppModel: ObservableObject { cleanupOperations.objectWillChange.sink { [weak self] _ in self?.objectWillChange.send() }.store(in: &cancellables) - disk.attach { [weak self] in self?.internalVolume } + disk.attach { [weak self] in self?.browser.internalVolume } diskCancellable = disk.objectWillChange.sink { [weak self] _ in self?.objectWillChange.send() } @@ -313,13 +318,6 @@ public final class AppModel: ObservableObject { report.exportReport(format: format, scope: scope) } - // MARK: - Derived state - - public var scanSummary: String { - guard let tree else { return "" } - return "\(ByteFormat.string(tree.totalSize)) · \(Plural.files(tree.totalFiles)) · \(Plural.folders(folderCount))" - } - // MARK: - Scanning public func scan(path: String) { @@ -367,7 +365,7 @@ public final class AppModel: ObservableObject { } else if let lastScanPath { scan(path: lastScanPath) } else { - scan(path: homePath) + scan(path: browser.homePath) } } @@ -384,7 +382,7 @@ public final class AppModel: ObservableObject { tab = .map fileCount = result.totalFiles folderCount = result.directoryCount() - refreshVolumes() + browser.refreshVolumes() nav.rebuild() stats.refresh() history.record(result) @@ -415,49 +413,6 @@ public final class AppModel: ObservableObject { nav.navigate(to: 0) } - public func activateRow(_ index: Int32) { - guard let tree, index >= 0, Int(index) < tree.count else { return } - guard tree.node(index).nodeKind != .aggregate else { return } - if tree.node(index).nodeKind == .directory { - navigate(to: index) - } else { - reveal(indices: [index]) - } - } - - public func openRow(_ index: Int32) { - guard let tree, index >= 0, Int(index) < tree.count else { return } - let node = tree.node(index) - guard node.nodeKind != .aggregate else { return } - if node.nodeKind.isContainer { - navigate(to: index) - } else { - let url = tree.url(of: index) - if !NSWorkspace.shared.open(url) { - errorMessage = "Не удалось открыть «\(tree.name(of: index))»" - } - } - } - - public func reveal(indices: [Int32]) { - guard let tree else { return } - let urls = indices.compactMap { index -> URL? in - guard index >= 0, Int(index) < tree.count, !tree.isDeleted(index) else { return nil } - return tree.url(of: index) - } - guard !urls.isEmpty else { return } - NSWorkspace.shared.activateFileViewerSelecting(urls) - } - - public func revealSelection() { - reveal(indices: Array(selection)) - } - - public func revealCurrentFolder() { - guard let tree else { return } - NSWorkspace.shared.activateFileViewerSelecting([tree.url(of: currentIndex)]) - } - // MARK: - Trash func resetTrashUndo() { @@ -494,18 +449,6 @@ public final class AppModel: ObservableObject { nav.clearCategoryFilter() } - // MARK: - Permissions - - public func openFullDiskAccessSettings() { - let candidates = [ - "x-apple.systempreferences:com.apple.settings.PrivacySecurity.extension?Privacy_AllFiles", - "x-apple.systempreferences:com.apple.preference.security?Privacy_AllFiles", - ] - for candidate in candidates { - if let url = URL(string: candidate), NSWorkspace.shared.open(url) { return } - } - } - // MARK: - UI helpers public func showToast(_ text: String, symbol: String = "checkmark.circle.fill") { @@ -550,111 +493,5 @@ extension AppModel { } extension AppModel { - public var freeSpaceText: String { - guard let volume = internalVolume else { return "—" } - return ByteFormat.string(volume.freeBytes) - } - - public func refreshVolumes() { - volumes = VolumeInfo.loadAll() - } -} - -extension AppModel { - public var currentName: String { - guard let tree else { return "" } - if currentIndex == 0 { return rootDisplayName } - let name = tree.name(of: currentIndex) - return name.isEmpty ? rootDisplayName : name - } - - public var breadcrumbs: [Int32] { - guard let tree else { return [] } - var chain: [Int32] = [] - var cursor = currentIndex - while cursor >= 0, chain.count < 256 { - chain.append(cursor) - let parent = tree.node(cursor).parent - if parent < 0 { break } - cursor = parent - } - return chain.reversed() - } - - public var canGoUp: Bool { - guard let tree else { return false } - return tree.node(currentIndex).parent >= 0 - } - - public var currentSize: Int64 { - tree?.node(currentIndex).size ?? 0 - } - - public var currentItemCount: Int { - Int(tree?.node(currentIndex).itemCount ?? 0) - } - - public var currentDirectCount: Int { - guard let tree, Int(currentIndex) < tree.count else { return 0 } - return Int(tree.node(currentIndex).childrenCount) - } - - public var currentPath: String { - tree?.path(of: currentIndex) ?? "" - } - - public var selectedSize: Int64 { - guard let tree else { return 0 } - return selection.reduce(Int64(0)) { $0 + tree.node($1).size } - } - - public var selectedCount: Int { selection.count } - - public var canRevealSelection: Bool { - guard let tree, !selection.isEmpty else { return false } - return selection.contains { !tree.isDeleted($0) } - } - - public var hasPermissionIssues: Bool { - (tree?.report.skippedItems ?? 0) > 0 - } - public var isScanning: Bool { phase == .scanning } - - public var volume: VolumeInfo? { - volumes.first(where: { $0.isInternal }) ?? volumes.first - } - - public var internalVolume: VolumeInfo? { - volumes.first(where: { $0.path == "/" }) ?? volumes.first - } - - public var currentNode: ScanNode? { - guard let tree, currentIndex >= 0, Int(currentIndex) < tree.count else { return nil } - return tree.node(currentIndex) - } - - public var homePath: String { - FileManager.default.homeDirectoryForCurrentUser.path - } - - public var rootDisplayName: String { - guard let tree else { return "DiskScope" } - if tree.rootPath == "/" { return internalVolume?.name ?? "Macintosh HD" } - let known: [String: String] = [ - homePath: "Домашняя папка", - homePath + "/Applications": "Программы", - "/Applications": "Программы", - homePath + "/Downloads": "Загрузки", - homePath + "/Documents": "Документы", - homePath + "/Desktop": "Рабочий стол", - homePath + "/Library": "Библиотека", - homePath + "/Movies": "Видео", - homePath + "/Music": "Музыка", - homePath + "/Pictures": "Изображения", - ] - if let known = known[tree.rootPath] { return known } - let name = URL(fileURLWithPath: tree.rootPath).lastPathComponent - return name.isEmpty ? tree.rootPath : name - } } diff --git a/Sources/DiskScopeKit/App/BrowserModel.swift b/Sources/DiskScopeKit/App/BrowserModel.swift new file mode 100644 index 0000000..0982fbb --- /dev/null +++ b/Sources/DiskScopeKit/App/BrowserModel.swift @@ -0,0 +1,186 @@ +import AppKit +import Combine +import Foundation + +/// Owns browser presentation (folder path, selection summary) and file actions. +@MainActor +public final class BrowserModel: ObservableObject { + weak var appModel: AppModel? + + public init() {} + + func attach(appModel: AppModel) { + self.appModel = appModel + } + + // MARK: - Presentation + + public var currentName: String { + guard let model = appModel, let tree = model.tree else { return "" } + if model.currentIndex == 0 { return rootDisplayName } + let name = tree.name(of: model.currentIndex) + return name.isEmpty ? rootDisplayName : name + } + + public var breadcrumbs: [Int32] { + guard let model = appModel, let tree = model.tree else { return [] } + var chain: [Int32] = [] + var cursor = model.currentIndex + while cursor >= 0, chain.count < 256 { + chain.append(cursor) + let parent = tree.node(cursor).parent + if parent < 0 { break } + cursor = parent + } + return chain.reversed() + } + + public var canGoUp: Bool { + guard let model = appModel, let tree = model.tree else { return false } + return tree.node(model.currentIndex).parent >= 0 + } + + public var currentSize: Int64 { + appModel?.tree?.node(appModel?.currentIndex ?? 0).size ?? 0 + } + + public var currentItemCount: Int { + Int(appModel?.tree?.node(appModel?.currentIndex ?? 0).itemCount ?? 0) + } + + public var currentDirectCount: Int { + guard let model = appModel, let tree = model.tree, Int(model.currentIndex) < tree.count else { + return 0 + } + return Int(tree.node(model.currentIndex).childrenCount) + } + + public var currentPath: String { + guard let model = appModel else { return "" } + return model.tree?.path(of: model.currentIndex) ?? "" + } + + public var selectedSize: Int64 { + guard let model = appModel, let tree = model.tree else { return 0 } + return model.selection.reduce(Int64(0)) { $0 + tree.node($1).size } + } + + public var selectedCount: Int { appModel?.selection.count ?? 0 } + + public var canRevealSelection: Bool { + guard let model = appModel, let tree = model.tree, !model.selection.isEmpty else { + return false + } + return model.selection.contains { !tree.isDeleted($0) } + } + + public var hasPermissionIssues: Bool { + (appModel?.tree?.report.skippedItems ?? 0) > 0 + } + + public var volume: VolumeInfo? { + guard let volumes = appModel?.volumes else { return nil } + return volumes.first(where: { $0.isInternal }) ?? volumes.first + } + + public var internalVolume: VolumeInfo? { + guard let volumes = appModel?.volumes else { return nil } + return volumes.first(where: { $0.path == "/" }) ?? volumes.first + } + + public var currentNode: ScanNode? { + guard let model = appModel, let tree = model.tree, + model.currentIndex >= 0, Int(model.currentIndex) < tree.count else { return nil } + return tree.node(model.currentIndex) + } + + public var homePath: String { + FileManager.default.homeDirectoryForCurrentUser.path + } + + public var rootDisplayName: String { + guard let model = appModel, let tree = model.tree else { return "DiskScope" } + if tree.rootPath == "/" { return internalVolume?.name ?? "Macintosh HD" } + let known: [String: String] = [ + homePath: "Домашняя папка", + homePath + "/Applications": "Программы", + "/Applications": "Программы", + homePath + "/Downloads": "Загрузки", + homePath + "/Documents": "Документы", + homePath + "/Desktop": "Рабочий стол", + homePath + "/Library": "Библиотека", + homePath + "/Movies": "Видео", + homePath + "/Music": "Музыка", + homePath + "/Pictures": "Изображения", + ] + if let known = known[tree.rootPath] { return known } + let name = URL(fileURLWithPath: tree.rootPath).lastPathComponent + return name.isEmpty ? tree.rootPath : name + } + + public var freeSpaceText: String { + guard let volume = internalVolume else { return "—" } + return ByteFormat.string(volume.freeBytes) + } + + public func refreshVolumes() { + appModel?.volumes = VolumeInfo.loadAll() + } + + // MARK: - File actions + + public func activateRow(_ index: Int32) { + guard let model = appModel, let tree = model.tree, + index >= 0, Int(index) < tree.count else { return } + guard tree.node(index).nodeKind != .aggregate else { return } + if tree.node(index).nodeKind == .directory { + model.navigate(to: index) + } else { + reveal(indices: [index]) + } + } + + public func openRow(_ index: Int32) { + guard let model = appModel, let tree = model.tree, + index >= 0, Int(index) < tree.count else { return } + let node = tree.node(index) + guard node.nodeKind != .aggregate else { return } + if node.nodeKind.isContainer { + model.navigate(to: index) + } else { + let url = tree.url(of: index) + if !NSWorkspace.shared.open(url) { + model.errorMessage = "Не удалось открыть «\(tree.name(of: index))»" + } + } + } + + public func reveal(indices: [Int32]) { + guard let tree = appModel?.tree else { return } + let urls = indices.compactMap { index -> URL? in + guard index >= 0, Int(index) < tree.count, !tree.isDeleted(index) else { return nil } + return tree.url(of: index) + } + guard !urls.isEmpty else { return } + NSWorkspace.shared.activateFileViewerSelecting(urls) + } + + public func revealSelection() { + reveal(indices: Array(appModel?.selection ?? [])) + } + + public func revealCurrentFolder() { + guard let model = appModel, let tree = model.tree else { return } + NSWorkspace.shared.activateFileViewerSelecting([tree.url(of: model.currentIndex)]) + } + + public func openFullDiskAccessSettings() { + let candidates = [ + "x-apple.systempreferences:com.apple.settings.PrivacySecurity.extension?Privacy_AllFiles", + "x-apple.systempreferences:com.apple.preference.security?Privacy_AllFiles", + ] + for candidate in candidates { + if let url = URL(string: candidate), NSWorkspace.shared.open(url) { return } + } + } +} diff --git a/Sources/DiskScopeKit/App/CleanupOperationsModel.swift b/Sources/DiskScopeKit/App/CleanupOperationsModel.swift index 2ac597c..2b1c7d2 100644 --- a/Sources/DiskScopeKit/App/CleanupOperationsModel.swift +++ b/Sources/DiskScopeKit/App/CleanupOperationsModel.swift @@ -104,7 +104,7 @@ public final class CleanupOperationsModel: ObservableObject { model.currentIndex = max(cursor, 0) } model.rebuildCurrentRows() - model.refreshVolumes() + model.browser.refreshVolumes() model.stats.refresh() model.invalidateCleanup() diff --git a/Sources/DiskScopeKit/App/TrashOperationsModel.swift b/Sources/DiskScopeKit/App/TrashOperationsModel.swift index 638b4f6..12380c3 100644 --- a/Sources/DiskScopeKit/App/TrashOperationsModel.swift +++ b/Sources/DiskScopeKit/App/TrashOperationsModel.swift @@ -126,7 +126,7 @@ public final class TrashOperationsModel: ObservableObject { model.currentIndex = max(cursor, 0) } model.rebuildCurrentRows() - model.refreshVolumes() + model.browser.refreshVolumes() model.stats.refresh() model.invalidateCleanup() model.showToast( @@ -205,7 +205,7 @@ public final class TrashOperationsModel: ObservableObject { model.currentIndex = max(cursor, 0) } model.rebuildCurrentRows() - model.refreshVolumes() + model.browser.refreshVolumes() model.stats.refresh() model.invalidateCleanup() let bytes = groups.reduce(Int64(0)) { $0 + $1.bytes } diff --git a/Sources/DiskScopeKit/UI/CleanupView.swift b/Sources/DiskScopeKit/UI/CleanupView.swift index 7535e98..650ac8c 100644 --- a/Sources/DiskScopeKit/UI/CleanupView.swift +++ b/Sources/DiskScopeKit/UI/CleanupView.swift @@ -186,7 +186,7 @@ struct CleanupView: View { suggestion: suggestion, isSelected: model.cleanup.selection.contains(suggestion.id), onToggle: { model.cleanup.toggle(suggestion.id) }, - onReveal: { model.reveal(indices: [suggestion.nodeIndex]) } + onReveal: { model.browser.reveal(indices: [suggestion.nodeIndex]) } ) } } @@ -259,7 +259,7 @@ struct CleanupView: View { suggestion: suggestion, isSelected: model.cleanup.selection.contains(suggestion.id), onToggle: { model.cleanup.toggle(suggestion.id) }, - onReveal: { model.reveal(indices: [suggestion.nodeIndex]) } + onReveal: { model.browser.reveal(indices: [suggestion.nodeIndex]) } ) } } diff --git a/Sources/DiskScopeKit/UI/CollectionView.swift b/Sources/DiskScopeKit/UI/CollectionView.swift index 0ab0f93..7bd595a 100644 --- a/Sources/DiskScopeKit/UI/CollectionView.swift +++ b/Sources/DiskScopeKit/UI/CollectionView.swift @@ -24,7 +24,7 @@ struct CollectionView: View { ForEach(rows) { row in CollectionRow( row: row, - onReveal: { model.reveal(indices: [row.id]) }, + onReveal: { model.browser.reveal(indices: [row.id]) }, onRemove: { model.removeFromCollection([row.id]) } ) } diff --git a/Sources/DiskScopeKit/UI/ContentView.swift b/Sources/DiskScopeKit/UI/ContentView.swift index 0ec54cd..b38c809 100644 --- a/Sources/DiskScopeKit/UI/ContentView.swift +++ b/Sources/DiskScopeKit/UI/ContentView.swift @@ -59,15 +59,15 @@ public struct ContentView: View { HistoryView() .environmentObject(model) } - .onAppear { model.refreshVolumes() } + .onAppear { model.browser.refreshVolumes() } .quickLookPreview($model.inspector.quickLookURL) .preferredColorScheme(AppAppearance(rawValue: appearance)?.colorScheme) .environment(\.locale, AppLanguage(rawValue: language)?.locale ?? Locale.current) } private var trashMessage: String { - let count = model.selectedCount - let size = ByteFormat.string(model.selectedSize) + let count = model.browser.selectedCount + let size = ByteFormat.string(model.browser.selectedSize) return "\(Plural.items(count)) · \(size). Объекты можно восстановить из Корзины." } @@ -122,11 +122,11 @@ struct ReadyView: View { VStack(spacing: 0) { HeaderView() - if model.hasPermissionIssues && model.tab != .media { + if model.browser.hasPermissionIssues && model.tab != .media { PermissionBanner( count: model.tree?.report.skippedItems ?? 0, onDetails: { model.showPermissionSheet = true }, - onSettings: { model.openFullDiskAccessSettings() } + onSettings: { model.browser.openFullDiskAccessSettings() } ) .padding(.horizontal, 20) .padding(.bottom, 10) @@ -173,7 +173,7 @@ struct StatusBar: View { .fill(Theme.success) .frame(width: 5, height: 5) if let tree = model.tree { - Text("\(L10n.t(model.rootDisplayName)) · \(ByteFormat.string(tree.totalSize)) · \(Plural.files(tree.totalFiles))") + Text("\(L10n.t(model.browser.rootDisplayName)) · \(ByteFormat.string(tree.totalSize)) · \(Plural.files(tree.totalFiles))") Text("·") Text(L10n.isEnglish ? "scanned in \(ByteFormat.duration(tree.report.duration))" @@ -199,7 +199,7 @@ struct StatusBar: View { .help("Открыть коллекцию (⌘6)") } Spacer() - Text(L10n.isEnglish ? "Free \(model.freeSpaceText)" : "Свободно \(model.freeSpaceText)") + Text(L10n.isEnglish ? "Free \(model.browser.freeSpaceText)" : "Свободно \(model.browser.freeSpaceText)") } .font(.system(size: 10, weight: .medium)) .foregroundStyle(.secondary) @@ -310,7 +310,7 @@ struct PermissionSheet: View { GhostButton(title: "Закрыть", action: { dismiss() }) Spacer() AccentButton(title: "Открыть настройки", symbol: "gearshape.fill") { - model.openFullDiskAccessSettings() + model.browser.openFullDiskAccessSettings() dismiss() } } diff --git a/Sources/DiskScopeKit/UI/DiskOverviewView.swift b/Sources/DiskScopeKit/UI/DiskOverviewView.swift index b04b11d..2787e6b 100644 --- a/Sources/DiskScopeKit/UI/DiskOverviewView.swift +++ b/Sources/DiskScopeKit/UI/DiskOverviewView.swift @@ -25,7 +25,7 @@ struct DiskOverviewView: View { VStack(alignment: .leading, spacing: 14) { HStack(alignment: .firstTextBaseline) { VStack(alignment: .leading, spacing: 3) { - Text(overview?.volume.name ?? model.internalVolume?.name ?? "Macintosh HD") + Text(overview?.volume.name ?? model.browser.internalVolume?.name ?? "Macintosh HD") .font(.system(size: 12.5, weight: .semibold)) Text("Занято, свободно и purgeable") .font(.system(size: 10.5)) diff --git a/Sources/DiskScopeKit/UI/DuplicatesView.swift b/Sources/DiskScopeKit/UI/DuplicatesView.swift index 213b8b1..3783d51 100644 --- a/Sources/DiskScopeKit/UI/DuplicatesView.swift +++ b/Sources/DiskScopeKit/UI/DuplicatesView.swift @@ -270,7 +270,7 @@ private struct DuplicateGroupCard: View { .foregroundStyle(.tertiary) IconActionButton(symbol: "magnifyingglass", help: "Показать в Finder") { - model.reveal(indices: [file.index]) + model.browser.reveal(indices: [file.index]) } IconActionButton(symbol: "eye", help: "Быстрый просмотр") { model.inspector.previewNode(file.index) diff --git a/Sources/DiskScopeKit/UI/HeaderView.swift b/Sources/DiskScopeKit/UI/HeaderView.swift index b0c0132..ed2fff8 100644 --- a/Sources/DiskScopeKit/UI/HeaderView.swift +++ b/Sources/DiskScopeKit/UI/HeaderView.swift @@ -50,7 +50,7 @@ struct HeaderView: View { ScrollViewReader { proxy in ScrollView(.horizontal, showsIndicators: false) { HStack(spacing: 3) { - ForEach(Array(model.breadcrumbs.enumerated()), id: \.element) { offset, index in + ForEach(Array(model.browser.breadcrumbs.enumerated()), id: \.element) { offset, index in if offset > 0 { Image(systemName: "chevron.right") .font(.system(size: 7, weight: .bold)) @@ -107,12 +107,12 @@ struct HeaderView: View { private var rootSymbol: String { guard let path = model.tree?.rootPath else { return "internaldrive.fill" } if path == "/" { return "internaldrive.fill" } - if path == model.homePath { return "house.fill" } + if path == model.browser.homePath { return "house.fill" } return "folder.fill" } private func crumbTitle(_ index: Int32) -> String { - if index == 0 { return model.rootDisplayName } + if index == 0 { return model.browser.rootDisplayName } guard let tree = model.tree else { return "" } let name = tree.name(of: index) return name.isEmpty ? "…" : name @@ -169,18 +169,18 @@ struct HeaderView: View { } } else { VStack(alignment: .leading, spacing: 8) { - Text(LocalizedStringKey(model.currentName)) + Text(LocalizedStringKey(model.browser.currentName)) .font(.system(size: 25, weight: .semibold)) .tracking(-0.4) .lineLimit(1) .truncationMode(.middle) HStack(spacing: 6) { - StatPill(symbol: "internaldrive", text: ByteFormat.string(model.currentSize)) - StatPill(symbol: "doc.on.doc", text: Plural.files(model.currentItemCount)) - StatPill(symbol: "square.stack.3d.up", text: Plural.elements(model.currentDirectCount)) + StatPill(symbol: "internaldrive", text: ByteFormat.string(model.browser.currentSize)) + StatPill(symbol: "doc.on.doc", text: Plural.files(model.browser.currentItemCount)) + StatPill(symbol: "square.stack.3d.up", text: Plural.elements(model.browser.currentDirectCount)) if model.currentIndex != 0, let tree = model.tree { - Text("\(ByteFormat.percent(model.currentSize, of: tree.totalSize)) от скана") + Text("\(ByteFormat.percent(model.browser.currentSize, of: tree.totalSize)) от скана") .font(.system(size: 10.5, weight: .medium)) .foregroundStyle(.tertiary) } @@ -195,7 +195,7 @@ struct HeaderView: View { HStack(spacing: 5) { Menu { Button("Сканировать снова") { model.rescan() } - Button("Текущую папку") { model.scan(path: model.currentPath) } + Button("Текущую папку") { model.scan(path: model.browser.currentPath) } .disabled(model.currentIndex == 0) Divider() Button("Домашняя папка") { model.scanHome() } @@ -236,7 +236,7 @@ struct HeaderView: View { .frame(width: 1, height: 18) .padding(.horizontal, 3) - IconActionButton(symbol: "arrow.up", help: "Наверх (⌘↑)", disabled: !model.canGoUp) { + IconActionButton(symbol: "arrow.up", help: "Наверх (⌘↑)", disabled: !model.browser.canGoUp) { model.goUp() } @@ -247,9 +247,9 @@ struct HeaderView: View { : "Показать выбранное в Finder (⇧⌘R)" ) { if model.selection.isEmpty { - model.revealCurrentFolder() + model.browser.revealCurrentFolder() } else { - model.revealSelection() + model.browser.revealSelection() } } diff --git a/Sources/DiskScopeKit/UI/InspectorView.swift b/Sources/DiskScopeKit/UI/InspectorView.swift index a8b6916..24ed542 100644 --- a/Sources/DiskScopeKit/UI/InspectorView.swift +++ b/Sources/DiskScopeKit/UI/InspectorView.swift @@ -59,7 +59,7 @@ struct InspectorView: View { VStack(alignment: .leading, spacing: 4) { Text("Выбрано объектов: \(selectedCount)") .font(.system(size: 13, weight: .semibold)) - Text(ByteFormat.string(model.selectedSize)) + Text(ByteFormat.string(model.browser.selectedSize)) .font(AppFont.number(22)) .monospacedDigit() } @@ -307,7 +307,7 @@ private struct InspectorDetails: View { VStack(spacing: 7) { HStack(spacing: 6) { GhostButton(title: "Finder", symbol: "magnifyingglass") { - model.reveal(indices: [index]) + model.browser.reveal(indices: [index]) } if node?.nodeKind == .file { GhostButton(title: "Пробел", symbol: "eye") { diff --git a/Sources/DiskScopeKit/UI/LargestFilesView.swift b/Sources/DiskScopeKit/UI/LargestFilesView.swift index cbe4a53..5fc36ca 100644 --- a/Sources/DiskScopeKit/UI/LargestFilesView.swift +++ b/Sources/DiskScopeKit/UI/LargestFilesView.swift @@ -131,8 +131,8 @@ struct LargestFilesView: View { .contextMenu(forSelectionType: Int32.self) { selection in if let first = selection.first { let isContainer = model.tree?.node(first).nodeKind.isContainer == true - Button("Открыть") { model.openRow(first) } - Button("Показать в Finder") { model.reveal(indices: Array(selection)) } + Button("Открыть") { model.browser.openRow(first) } + Button("Показать в Finder") { model.browser.reveal(indices: Array(selection)) } if !isContainer { Button("Быстрый просмотр") { model.inspector.previewNode(first) } } @@ -154,16 +154,16 @@ struct LargestFilesView: View { } } primaryAction: { selection in if let first = selection.first { - model.activateRow(first) + model.browser.activateRow(first) } } } private func folderLabel(_ row: AppModel.ItemRow) -> String { let relative = row.relativePath - guard let slash = relative.lastIndex(of: "/") else { return model.rootDisplayName } + guard let slash = relative.lastIndex(of: "/") else { return model.browser.rootDisplayName } let folder = String(relative[.. String { guard !path.isEmpty else { return "" } - if path == model.homePath { return "~" } - if path.hasPrefix(model.homePath + "/") { - return "~" + path.dropFirst(model.homePath.count) + if path == model.browser.homePath { return "~" } + if path.hasPrefix(model.browser.homePath + "/") { + return "~" + path.dropFirst(model.browser.homePath.count) } return path } diff --git a/Sources/DiskScopeKit/UI/SidebarView.swift b/Sources/DiskScopeKit/UI/SidebarView.swift index 18f3c56..088cd20 100644 --- a/Sources/DiskScopeKit/UI/SidebarView.swift +++ b/Sources/DiskScopeKit/UI/SidebarView.swift @@ -47,7 +47,7 @@ struct SidebarView: View { private var volumeCard: some View { Button { - if let volume = model.internalVolume { + if let volume = model.browser.internalVolume { model.scanVolume(volume) } } label: { @@ -56,19 +56,19 @@ struct SidebarView: View { Image(systemName: "internaldrive.fill") .font(.system(size: 10, weight: .semibold)) .foregroundStyle(.white.opacity(0.65)) - Text(model.internalVolume?.name ?? "Macintosh HD") + Text(model.browser.internalVolume?.name ?? "Macintosh HD") .font(.system(size: 12, weight: .semibold)) .foregroundStyle(.white.opacity(0.92)) .lineLimit(1) Spacer(minLength: 4) - if let volume = model.internalVolume { + if let volume = model.browser.internalVolume { Text(ByteFormat.percent(volume.usedBytes, of: volume.totalBytes)) .font(AppFont.number(13)) .foregroundStyle(.white.opacity(0.9)) } } - if let volume = model.internalVolume { + if let volume = model.browser.internalVolume { ProgressBar( fraction: volume.usedFraction, tint: AnyShapeStyle( @@ -140,7 +140,7 @@ struct SidebarView: View { .buttonStyle(.plain) .focusable(false) .focusEffectDisabled() - .help("Сканировать \(model.internalVolume?.name ?? "диск")") + .help("Сканировать \(model.browser.internalVolume?.name ?? "диск")") } private var quickAccess: some View { @@ -212,7 +212,7 @@ struct SidebarView: View { .frame(width: 5, height: 5) Text(model.isScanning ? L10n.t("Сканирование…") - : (L10n.isEnglish ? "Free \(model.freeSpaceText)" : "Свободно \(model.freeSpaceText)")) + : (L10n.isEnglish ? "Free \(model.browser.freeSpaceText)" : "Свободно \(model.browser.freeSpaceText)")) .font(.system(size: 10, weight: .medium)) .foregroundStyle(.white.opacity(0.55)) Spacer(minLength: 0) @@ -220,7 +220,7 @@ struct SidebarView: View { Button("Выбрать папку…") { model.chooseFolder() } Button("Полная картина диска…") { model.showDiskOverview() } Button("История сканов…") { model.history.show = true } - Button("Полный доступ к диску…") { model.openFullDiskAccessSettings() } + Button("Полный доступ к диску…") { model.browser.openFullDiskAccessSettings() } Divider() Button("О программе DiskScope") { NSApp.orderFrontStandardAboutPanel(nil) diff --git a/Sources/DiskScopeKit/UI/SimilarImagesView.swift b/Sources/DiskScopeKit/UI/SimilarImagesView.swift index cb1de86..e1e7ff8 100644 --- a/Sources/DiskScopeKit/UI/SimilarImagesView.swift +++ b/Sources/DiskScopeKit/UI/SimilarImagesView.swift @@ -253,7 +253,7 @@ private struct SimilarGroupCard: View { .foregroundStyle(.tertiary) IconActionButton(symbol: "magnifyingglass", help: "Показать в Finder") { - model.reveal(indices: [image.index]) + model.browser.reveal(indices: [image.index]) } IconActionButton(symbol: "eye", help: "Быстрый просмотр") { model.inspector.previewNode(image.index) diff --git a/Sources/DiskScopeKit/UI/TreemapView.swift b/Sources/DiskScopeKit/UI/TreemapView.swift index 99507b8..cc14574 100644 --- a/Sources/DiskScopeKit/UI/TreemapView.swift +++ b/Sources/DiskScopeKit/UI/TreemapView.swift @@ -143,8 +143,8 @@ struct TreemapView: View { .clipped() .contextMenu { if let node = previewNode, isValid(node: node) { - Button("Открыть") { model.openRow(node) } - Button("Показать в Finder") { model.reveal(indices: [node]) } + Button("Открыть") { model.browser.openRow(node) } + Button("Показать в Finder") { model.browser.reveal(indices: [node]) } Button("Быстрый просмотр") { model.inspector.previewNode(node) } Button("Копировать путь") { model.inspector.copyPaths([node]) } Button("Открыть в терминале") { model.inspector.openInTerminal(node) } @@ -158,7 +158,7 @@ struct TreemapView: View { model.trashOperations.requestSelection() } } else { - Button("Показать в Finder") { model.reveal(indices: [root]) } + Button("Показать в Finder") { model.browser.reveal(indices: [root]) } Button("Сканировать эту папку") { model.scan(path: tree.path(of: root)) } } } @@ -455,7 +455,7 @@ struct TreemapView: View { } Spacer(minLength: 6) GhostButton(title: "Finder", symbol: "magnifyingglass") { - model.reveal(indices: [node]) + model.browser.reveal(indices: [node]) } GhostButton( title: model.isInCollection(node) ? "Убрать" : "В коллекцию", diff --git a/Sources/DiskScopeKit/UI/TypesView.swift b/Sources/DiskScopeKit/UI/TypesView.swift index a4e9e68..6bec572 100644 --- a/Sources/DiskScopeKit/UI/TypesView.swift +++ b/Sources/DiskScopeKit/UI/TypesView.swift @@ -27,7 +27,7 @@ struct TypesView: View { VStack(alignment: .leading, spacing: 3) { Text("Распределение по типам") .font(.system(size: 12.5, weight: .semibold)) - Text("Внутри «\(model.rootDisplayName)»") + Text("Внутри «\(model.browser.rootDisplayName)»") .font(.system(size: 10.5)) .foregroundStyle(.secondary) } @@ -125,8 +125,8 @@ struct TypesView: View { Rectangle().fill(Theme.border).frame(height: 1) ForEach(model.stats.largestItems.prefix(5)) { row in - TopItemRow(row: row, rootName: model.rootDisplayName) { - model.reveal(indices: [row.id]) + TopItemRow(row: row, rootName: model.browser.rootDisplayName) { + model.browser.reveal(indices: [row.id]) } } } @@ -305,8 +305,8 @@ private struct TopItemRow: View { .onHover { hovering = $0 } .help(row.path) .contextMenu { - Button("Открыть") { model.openRow(row.id) } - Button("Показать в Finder") { model.reveal(indices: [row.id]) } + Button("Открыть") { model.browser.openRow(row.id) } + Button("Показать в Finder") { model.browser.reveal(indices: [row.id]) } if !row.isContainer { Button("Быстрый просмотр") { model.inspector.previewNode(row.id) } } diff --git a/Sources/DiskScopeKit/UI/WelcomeView.swift b/Sources/DiskScopeKit/UI/WelcomeView.swift index d05c396..03855d1 100644 --- a/Sources/DiskScopeKit/UI/WelcomeView.swift +++ b/Sources/DiskScopeKit/UI/WelcomeView.swift @@ -137,7 +137,7 @@ struct WelcomeView: View { } private func abbreviate(_ path: String) -> String { - let home = model.homePath + let home = model.browser.homePath if path.hasPrefix(home) { return "~" + path.dropFirst(home.count) } @@ -157,7 +157,7 @@ struct WelcomeView: View { VStack(alignment: .leading, spacing: 7) { HStack(spacing: 7) { - Text(model.internalVolume?.name ?? "Macintosh HD") + Text(model.browser.internalVolume?.name ?? "Macintosh HD") .font(.system(size: 13, weight: .semibold)) Text("APFS") .font(.system(size: 8, weight: .bold)) @@ -167,7 +167,7 @@ struct WelcomeView: View { .background(Theme.subtleFill, in: Capsule()) } - if let volume = model.internalVolume { + if let volume = model.browser.internalVolume { ProgressBar(fraction: volume.usedFraction, height: 7) Text(volumeSummary(volume)) .font(.system(size: 9.5, weight: .medium)) @@ -177,7 +177,7 @@ struct WelcomeView: View { Spacer(minLength: 10) - if let volume = model.internalVolume { + if let volume = model.browser.internalVolume { VStack(alignment: .trailing, spacing: 2) { Text(ByteFormat.percent(volume.usedBytes, of: volume.totalBytes)) .font(AppFont.number(21)) @@ -189,7 +189,7 @@ struct WelcomeView: View { } Button { - if let volume = model.internalVolume { model.scanVolume(volume) } + if let volume = model.browser.internalVolume { model.scanVolume(volume) } } label: { HStack(spacing: 5) { Image(systemName: "waveform.path.ecg") @@ -253,7 +253,7 @@ struct WelcomeView: View { .foregroundStyle(.secondary) Spacer(minLength: 6) Button("Открыть настройки") { - model.openFullDiskAccessSettings() + model.browser.openFullDiskAccessSettings() } .buttonStyle(.plain) .font(.system(size: 10.5, weight: .semibold)) diff --git a/Sources/DiskScopeKit/UI/WindowChrome.swift b/Sources/DiskScopeKit/UI/WindowChrome.swift index f00b833..233eb7d 100644 --- a/Sources/DiskScopeKit/UI/WindowChrome.swift +++ b/Sources/DiskScopeKit/UI/WindowChrome.swift @@ -551,9 +551,9 @@ struct CommandPaletteView: View { shortcut: "⇧⌘R" ) { if model.selection.isEmpty { - model.revealCurrentFolder() + model.browser.revealCurrentFolder() } else { - model.revealSelection() + model.browser.revealSelection() } } ) @@ -604,7 +604,7 @@ struct CommandPaletteView: View { symbol: "lock.shield", shortcut: nil ) { - model.openFullDiskAccessSettings() + model.browser.openFullDiskAccessSettings() }, PaletteCommand( id: "about", diff --git a/Sources/DiskScopeSnapshots/SnapshotsMain.swift b/Sources/DiskScopeSnapshots/SnapshotsMain.swift index c09ca54..deb5ef2 100644 --- a/Sources/DiskScopeSnapshots/SnapshotsMain.swift +++ b/Sources/DiskScopeSnapshots/SnapshotsMain.swift @@ -312,7 +312,7 @@ final class SnapshotRenderer { render(model: model, named: "07-welcome-dark", dark: true) model.preview.scanning( - path: model.homePath + "/Library/Application Support", + path: model.browser.homePath + "/Library/Application Support", progress: ScanProgress( entries: 2_148_932, files: 1_842_010, diff --git a/Tests/DiskScopeKitTests/AppModelTests.swift b/Tests/DiskScopeKitTests/AppModelTests.swift index d722390..87b73e6 100644 --- a/Tests/DiskScopeKitTests/AppModelTests.swift +++ b/Tests/DiskScopeKitTests/AppModelTests.swift @@ -96,12 +96,12 @@ final class AppModelTests: XCTestCase { XCTAssertTrue(sub.isContainer) model.navigate(to: sub.id) XCTAssertEqual(model.currentIndex, sub.id) - XCTAssertEqual(model.currentName, "Sub") - XCTAssertTrue(model.canGoUp) + XCTAssertEqual(model.browser.currentName, "Sub") + XCTAssertTrue(model.browser.canGoUp) model.goUp() XCTAssertEqual(model.currentIndex, 0) - XCTAssertFalse(model.canGoUp) + XCTAssertFalse(model.browser.canGoUp) } func testPreviewCategoryFilterAndLargestRows() throws { diff --git a/Tests/DiskScopeKitTests/BrowserModelTests.swift b/Tests/DiskScopeKitTests/BrowserModelTests.swift new file mode 100644 index 0000000..07131d6 --- /dev/null +++ b/Tests/DiskScopeKitTests/BrowserModelTests.swift @@ -0,0 +1,89 @@ +import Foundation +import XCTest +@testable import DiskScopeKit + +@MainActor +final class BrowserModelTests: XCTestCase { + private func makeTree() throws -> ScanTree { + let root = FileManager.default.temporaryDirectory + .appendingPathComponent("DiskScopeBrowser-\(UUID().uuidString)", isDirectory: true) + try FileManager.default.createDirectory( + at: root.appendingPathComponent("Sub"), + withIntermediateDirectories: true + ) + try Data(repeating: 0x41, count: 5_000) + .write(to: root.appendingPathComponent("video.mov")) + try Data(repeating: 0x42, count: 3_000) + .write(to: root.appendingPathComponent("Sub/notes.txt")) + addTeardownBlock { try? FileManager.default.removeItem(at: root) } + return try DiskScanner(options: .detailed).scan(path: root.path) + } + + func testPresentationFollowsNavigation() throws { + let tree = try makeTree() + let model = AppModel() + model.preview.load(tree: tree) + + XCTAssertEqual(model.browser.currentName, model.browser.rootDisplayName) + XCTAssertEqual(model.browser.breadcrumbs, [0]) + XCTAssertFalse(model.browser.canGoUp) + XCTAssertEqual(model.browser.currentPath, tree.path(of: 0)) + XCTAssertEqual(model.browser.currentSize, tree.node(0).size) + XCTAssertEqual(model.browser.currentItemCount, Int(tree.node(0).itemCount)) + XCTAssertEqual(model.browser.currentDirectCount, tree.children(of: 0).count) + + let folder = try XCTUnwrap(model.currentRows.first { $0.isContainer }) + model.navigate(to: folder.id) + XCTAssertEqual(model.browser.currentName, "Sub") + XCTAssertEqual(model.browser.breadcrumbs, [0, folder.id]) + XCTAssertTrue(model.browser.canGoUp) + XCTAssertEqual(model.browser.currentDirectCount, 1) + } + + func testSelectionSummaryAndRevealAvailability() throws { + let tree = try makeTree() + let model = AppModel() + model.preview.load(tree: tree) + + XCTAssertEqual(model.browser.selectedCount, 0) + XCTAssertEqual(model.browser.selectedSize, 0) + XCTAssertFalse(model.browser.canRevealSelection) + + let file = try XCTUnwrap(model.currentRows.first { !$0.isContainer && !$0.isAggregate }) + model.selection = [file.id] + XCTAssertEqual(model.browser.selectedCount, 1) + XCTAssertEqual(model.browser.selectedSize, file.size) + XCTAssertTrue(model.browser.canRevealSelection) + } + + func testFolderActivationAndOpeningNavigate() throws { + let tree = try makeTree() + let model = AppModel() + model.preview.load(tree: tree) + + let folder = try XCTUnwrap(model.currentRows.first { $0.isContainer }) + model.browser.activateRow(folder.id) + XCTAssertEqual(model.currentIndex, folder.id) + + model.browser.openRow(0) + XCTAssertEqual(model.currentIndex, 0) + model.browser.openRow(folder.id) + XCTAssertEqual(model.currentIndex, folder.id) + } + + func testVolumesAndRootNames() throws { + let tree = try makeTree() + let model = AppModel() + model.preview.load(tree: tree) + + XCTAssertEqual(model.browser.rootDisplayName, URL(fileURLWithPath: tree.rootPath).lastPathComponent) + XCTAssertFalse(model.browser.homePath.isEmpty) + XCTAssertNotNil(model.browser.internalVolume) + XCTAssertNotNil(model.browser.volume) + XCTAssertFalse(model.browser.freeSpaceText.isEmpty) + XCTAssertFalse(model.browser.hasPermissionIssues) + + model.browser.refreshVolumes() + XCTAssertFalse(model.volumes.isEmpty) + } +} diff --git a/docs/build.md b/docs/build.md index 083e94c..4706826 100644 --- a/docs/build.md +++ b/docs/build.md @@ -95,7 +95,7 @@ MKDOCS_SITE_URL=http://localhost:8000/ .venv/bin/mkdocs build --strict ## Тесты -161 XCTest-тест покрывает: +165 XCTest-тестов покрывают: - сканер и точность суммы против `du`; - агрегацию мелких файлов, пакеты, симлинки, Unicode-имена; @@ -115,7 +115,7 @@ Sources/ DiskScopeKit/ Core/ сканер, дерево, форматирование, treemap-раскладка UI/ SwiftUI-интерфейс - App/ AppModel + App/ AppModel и feature-модели DiskScope/ точка входа приложения DiskScopeCLI/ headless-сканер DiskScopeSnapshots/ рендер интерфейса в PNG