krz/orgstar

A native macOS editor for org-mode files. editor org-mode swift

Tests/OrgWorkspaceTests/ICloudTests.swift

2fa201330f61c801f777baa3f2943d49d8758cda
orgstar/Tests/OrgWorkspaceTests/ICloudTests.swift history · blame · raw

31 lines · 1562 bytes

 1import Foundation
 2import Testing
 3@testable import OrgWorkspace
 4
 5struct ICloudTests {
 6    @Test func onlyFilesNotOnTheDeviceWait() {
 7        #expect(WorkspaceScanner.isPending(isUbiquitous: true, status: .notDownloaded))
 8        #expect(!WorkspaceScanner.isPending(isUbiquitous: true, status: .current))
 9        #expect(!WorkspaceScanner.isPending(isUbiquitous: true, status: .downloaded))
10        #expect(!WorkspaceScanner.isPending(isUbiquitous: nil, status: nil))
11        #expect(!WorkspaceScanner.isPending(isUbiquitous: false, status: .notDownloaded))
12    }
13
14    @Test func folderPresenterHearsCoordinatedWrites() throws {
15        let root = FileManager.default.temporaryDirectory.appendingPathComponent("orgstar-presenter-\(UUID().uuidString)").resolvingSymlinksInPath()
16        try FileManager.default.createDirectory(at: root, withIntermediateDirectories: true)
17        defer { try? FileManager.default.removeItem(at: root) }
18        let file = root.appendingPathComponent("a.org")
19        try "* A\n".write(to: file, atomically: true, encoding: .utf8)
20        let received = Received()
21        let presenter = FolderPresenter(root: root, latency: 0.05) { events in received.add(events) }
22        presenter.start()
23        defer { presenter.stop() }
24        var error: NSError?
25        NSFileCoordinator(filePresenter: nil).coordinate(writingItemAt: file, options: .forReplacing, error: &error) { url in
26            try? "* B\n".write(to: url, atomically: true, encoding: .utf8)
27        }
28        #expect(received.wait(for: "a.org", timeout: 3))
29    }
30}
31