WIP: wire Quick Look preview actions
This commit is contained in:
@@ -191,6 +191,46 @@ final class ClipboardCacheServiceTests: XCTestCase {
|
||||
XCTAssertEqual(try posixPermissions(previewURL), 0o600)
|
||||
}
|
||||
|
||||
func testTemporaryPreviewURLWritesTextFile() throws {
|
||||
let baseURL = try makeTempDirectory()
|
||||
let cacheService = ClipboardCacheService(baseURL: baseURL, encryptionService: noOpEncryptionService())
|
||||
let item = textItem("Quick Look text")
|
||||
|
||||
let previewURL = try XCTUnwrap(cacheService.temporaryPreviewURL(for: item))
|
||||
|
||||
XCTAssertEqual(previewURL.pathExtension, "txt")
|
||||
XCTAssertEqual(try String(contentsOf: previewURL), "Quick Look text")
|
||||
XCTAssertEqual(try posixPermissions(previewURL.deletingLastPathComponent()), 0o700)
|
||||
XCTAssertEqual(try posixPermissions(previewURL), 0o600)
|
||||
}
|
||||
|
||||
func testTemporaryPreviewURLWritesWebLocationFile() throws {
|
||||
let baseURL = try makeTempDirectory()
|
||||
let cacheService = ClipboardCacheService(baseURL: baseURL, encryptionService: noOpEncryptionService())
|
||||
let item = urlItem("https://example.com/releases")
|
||||
|
||||
let previewURL = try XCTUnwrap(cacheService.temporaryPreviewURL(for: item))
|
||||
let data = try Data(contentsOf: previewURL)
|
||||
let plist = try XCTUnwrap(
|
||||
PropertyListSerialization.propertyList(from: data, options: [], format: nil) as? [String: String]
|
||||
)
|
||||
|
||||
XCTAssertEqual(previewURL.pathExtension, "webloc")
|
||||
XCTAssertEqual(plist["URL"], "https://example.com/releases")
|
||||
XCTAssertEqual(try posixPermissions(previewURL), 0o600)
|
||||
}
|
||||
|
||||
func testTemporaryPreviewURLReturnsExistingFileURL() throws {
|
||||
let baseURL = try makeTempDirectory()
|
||||
let cacheService = ClipboardCacheService(baseURL: baseURL, encryptionService: noOpEncryptionService())
|
||||
let fileURL = baseURL.appendingPathComponent("report.txt")
|
||||
try Data("Report".utf8).write(to: fileURL)
|
||||
|
||||
let previewURL = try XCTUnwrap(cacheService.temporaryPreviewURL(for: fileItem(path: fileURL.path)))
|
||||
|
||||
XCTAssertEqual(previewURL.standardizedFileURL, fileURL.standardizedFileURL)
|
||||
}
|
||||
|
||||
private func makeTempDirectory() throws -> URL {
|
||||
let url = FileManager.default.temporaryDirectory
|
||||
.appendingPathComponent("clipboredtests", isDirectory: true)
|
||||
@@ -205,6 +245,38 @@ final class ClipboardCacheServiceTests: XCTestCase {
|
||||
return try FileManager.default.contentsOfDirectory(at: imageDirectory, includingPropertiesForKeys: nil)
|
||||
}
|
||||
|
||||
private func textItem(_ text: String) -> ClipboardItem {
|
||||
ClipboardItem(
|
||||
id: UUID(),
|
||||
kind: .text,
|
||||
displayText: text,
|
||||
payload: text,
|
||||
payloadHash: "hash",
|
||||
createdAt: Date(),
|
||||
lastUsedAt: Date(),
|
||||
useCount: 0,
|
||||
sourceApp: nil,
|
||||
imagePath: nil,
|
||||
thumbnailPath: nil
|
||||
)
|
||||
}
|
||||
|
||||
private func urlItem(_ url: String) -> ClipboardItem {
|
||||
ClipboardItem(
|
||||
id: UUID(),
|
||||
kind: .url,
|
||||
displayText: url,
|
||||
payload: url,
|
||||
payloadHash: "hash",
|
||||
createdAt: Date(),
|
||||
lastUsedAt: Date(),
|
||||
useCount: 0,
|
||||
sourceApp: nil,
|
||||
imagePath: nil,
|
||||
thumbnailPath: nil
|
||||
)
|
||||
}
|
||||
|
||||
private func pdfItem(path: String) -> ClipboardItem {
|
||||
ClipboardItem(
|
||||
id: UUID(),
|
||||
|
||||
@@ -147,6 +147,7 @@ final class ClipboardPanelControllerTests: XCTestCase {
|
||||
|
||||
func testCommandActionShortcutsMapToSelectedClipActions() {
|
||||
XCTAssertEqual(ClipboardPanelController.commandShortcutAction(forKeyCode: 8, modifiers: .command), .copy)
|
||||
XCTAssertEqual(ClipboardPanelController.commandShortcutAction(forKeyCode: 16, modifiers: .command), .preview)
|
||||
XCTAssertEqual(ClipboardPanelController.commandShortcutAction(forKeyCode: 31, modifiers: .command), .open)
|
||||
XCTAssertEqual(ClipboardPanelController.commandShortcutAction(forKeyCode: 15, modifiers: .command), .reveal)
|
||||
}
|
||||
|
||||
@@ -182,8 +182,8 @@ final class ClipboardPanelViewTests: XCTestCase {
|
||||
|
||||
fixture.viewModel.selectFirstItem()
|
||||
XCTAssertEqual(fixture.viewModel.visibleItems.first?.kind, .file)
|
||||
XCTAssertEqual(fixture.view.debugFirstCardVisibleActionLabels, ["Paste", "Copy", "Pin", "Open", "Reveal", "Delete"])
|
||||
XCTAssertEqual(fixture.view.debugFirstCardVisibleActionRailWidth, 182)
|
||||
XCTAssertEqual(fixture.view.debugFirstCardVisibleActionLabels, ["Paste", "Copy", "Pin", "Preview", "Open", "Reveal", "Delete"])
|
||||
XCTAssertEqual(fixture.view.debugFirstCardVisibleActionRailWidth, 210)
|
||||
XCTAssertFalse(fixture.view.debugFirstCardFooterDetailIsHidden)
|
||||
XCTAssertTrue(fixture.view.debugFirstCardHeaderBadgeIsHidden)
|
||||
}
|
||||
@@ -329,6 +329,18 @@ final class ClipboardPanelViewTests: XCTestCase {
|
||||
)
|
||||
}
|
||||
|
||||
func testPreviewableCardsExposeQuickLookContextMenuAction() {
|
||||
let fixture = makePanelFixture()
|
||||
fixture.store.upsert(makeItem(kind: .file, text: "/tmp/report.txt", store: fixture.store))
|
||||
drainMainQueue()
|
||||
fixture.window.contentView?.layoutSubtreeIfNeeded()
|
||||
|
||||
XCTAssertEqual(
|
||||
fixture.view.debugFirstCardMenuTitles,
|
||||
["Paste", "Copy", "Quick Look", "Pin", "Add to Collection", "-", "Open", "Reveal in Finder", "-", "Delete"]
|
||||
)
|
||||
}
|
||||
|
||||
func testCollectionMenuOffersExistingCustomCollections() {
|
||||
let fixture = makePanelFixture()
|
||||
var existing = makeTextItem("Existing client note", store: fixture.store)
|
||||
|
||||
Reference in New Issue
Block a user