From 855ddea44e1d52f90cbad113d0df0c8cc632231d Mon Sep 17 00:00:00 2001 From: Mark Rickert Date: Wed, 6 Nov 2019 14:48:26 -0700 Subject: [PATCH] Tests relative file paths and images. --- MTMRTests/AppleScriptDefinitionTests.swift | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/MTMRTests/AppleScriptDefinitionTests.swift b/MTMRTests/AppleScriptDefinitionTests.swift index 8b6c442..98101b6 100644 --- a/MTMRTests/AppleScriptDefinitionTests.swift +++ b/MTMRTests/AppleScriptDefinitionTests.swift @@ -26,6 +26,33 @@ class AppleScriptDefinitionTests: XCTestCase { XCTAssertEqual(sourceStruct?.filePath, "/ololo/pew") } + // This tests that users can pass paths to files with ~ in them + func testUserPath() { + let buttonNoActionFixture = """ + [ { "type": "appleScriptTitledButton", "source": { "filePath": "~/pew" } } ] + """.data(using: .utf8)! + let result = try? JSONDecoder().decode([BarItemDefinition].self, from: buttonNoActionFixture) + guard case .appleScriptTitledButton(let source, _)? = result?.first?.type else { + XCTFail() + return + } + let sourceStruct = source as? Source + // gives you a string in the format of file:///Users/your_uer_name/pew + let expandedPath = URL(fileURLWithPath: NSString("~/pew").expandingTildeInPath) as URL + XCTAssertEqual(sourceStruct?.filePath?.fileURL, expandedPath) + } + + // This tests that users can pass paths to images with ~ in them + func testUserImagePath() { + let relativeImagePath = """ + [ { "filePath": "~/pew/image.png" } ] + """.data(using: .utf8)! + let result = try? JSONDecoder().decode([Source].self, from: relativeImagePath) + // gives you a string in the format of file:///Users/your_uer_name/pew/image.png + let expandedPath = URL(fileURLWithPath: NSString("~/pew/image.png").expandingTildeInPath) as URL + XCTAssertEqual(result?.first?.filePath?.fileURL, expandedPath) + } + func testRefreshInterval() { let buttonNoActionFixture = """ [ { "type": "appleScriptTitledButton", "source": { "inline": "tell everything fine" }, "refreshInterval": 305} ]