diff --git a/MTMR.xcodeproj/project.pbxproj b/MTMR.xcodeproj/project.pbxproj index 98e0aa5..a85279c 100644 --- a/MTMR.xcodeproj/project.pbxproj +++ b/MTMR.xcodeproj/project.pbxproj @@ -8,6 +8,8 @@ /* Begin PBXBuildFile section */ 36300E83209F040900B31C71 /* SupportHelpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0008E542080286C003AD4DD /* SupportHelpers.swift */; }; + 36300E8F20A2CF3400B31C71 /* AppleScriptDefinitionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36300E8E20A2CF3400B31C71 /* AppleScriptDefinitionTests.swift */; }; + 36300E9120A2D2B200B31C71 /* BackgroundColorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36300E9020A2D2B200B31C71 /* BackgroundColorTests.swift */; }; 368EDDE720812A1D00E10953 /* ScrollViewItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 368EDDE620812A1D00E10953 /* ScrollViewItem.swift */; }; 36C2ECD7207B6DAE003CDA33 /* TimeTouchBarItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36C2ECD6207B6DAE003CDA33 /* TimeTouchBarItem.swift */; }; 36C2ECD9207B74B4003CDA33 /* AppleScriptTouchBarItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36C2ECD8207B74B4003CDA33 /* AppleScriptTouchBarItem.swift */; }; @@ -49,6 +51,8 @@ /* Begin PBXFileReference section */ 36300E85209FD16700B31C71 /* .travis.yml */ = {isa = PBXFileReference; lastKnownFileType = text; path = .travis.yml; sourceTree = SOURCE_ROOT; }; + 36300E8E20A2CF3400B31C71 /* AppleScriptDefinitionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppleScriptDefinitionTests.swift; sourceTree = ""; }; + 36300E9020A2D2B200B31C71 /* BackgroundColorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BackgroundColorTests.swift; sourceTree = ""; }; 368EDDE620812A1D00E10953 /* ScrollViewItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScrollViewItem.swift; sourceTree = ""; }; 36BDC22F207CDA8600FCFEBE /* TECHNICAL_DEBT.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = TECHNICAL_DEBT.md; sourceTree = ""; }; 36C2ECD2207B3B1D003CDA33 /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; @@ -179,6 +183,8 @@ 36300E85209FD16700B31C71 /* .travis.yml */, 36C2ECDC207C723B003CDA33 /* ParseConfigTests.swift */, B082B267205C7D8000BC04DC /* Info.plist */, + 36300E8E20A2CF3400B31C71 /* AppleScriptDefinitionTests.swift */, + 36300E9020A2D2B200B31C71 /* BackgroundColorTests.swift */, ); path = MTMRTests; sourceTree = ""; @@ -370,6 +376,8 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 36300E9120A2D2B200B31C71 /* BackgroundColorTests.swift in Sources */, + 36300E8F20A2CF3400B31C71 /* AppleScriptDefinitionTests.swift in Sources */, 36C2ECDD207C723B003CDA33 /* ParseConfigTests.swift in Sources */, 36300E83209F040900B31C71 /* SupportHelpers.swift in Sources */, 36C2ECDE207C82DE003CDA33 /* ItemsParsing.swift in Sources */, diff --git a/MTMRTests/AppleScriptDefinitionTests.swift b/MTMRTests/AppleScriptDefinitionTests.swift new file mode 100644 index 0000000..0977bab --- /dev/null +++ b/MTMRTests/AppleScriptDefinitionTests.swift @@ -0,0 +1,41 @@ +import XCTest + +class AppleScriptDefinitionTests: XCTestCase { + + func testInline() { + let buttonNoActionFixture = """ + [ { "type": "appleScriptTitledButton", "source": { "inline": "tell everything fine" } } ] + """.data(using: .utf8)! + let result = try? JSONDecoder().decode([BarItemDefinition].self, from: buttonNoActionFixture) + guard case .appleScriptTitledButton(let source, _)? = result?.first?.type else { + XCTFail() + return + } + XCTAssertEqual(source.string, "tell everything fine") + } + + func testPath() { + let buttonNoActionFixture = """ + [ { "type": "appleScriptTitledButton", "source": { "filePath": "/ololo/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 + XCTAssertEqual(sourceStruct?.filePath, "/ololo/pew") + } + + func testRefreshInterval() { + let buttonNoActionFixture = """ + [ { "type": "appleScriptTitledButton", "source": { "inline": "tell everything fine" }, "refreshInterval": 305} ] + """.data(using: .utf8)! + let result = try? JSONDecoder().decode([BarItemDefinition].self, from: buttonNoActionFixture) + guard case .appleScriptTitledButton(_, 305)? = result?.first?.type else { + XCTFail() + return + } + } + +} diff --git a/MTMRTests/BackgroundColorTests.swift b/MTMRTests/BackgroundColorTests.swift new file mode 100644 index 0000000..915bbbc --- /dev/null +++ b/MTMRTests/BackgroundColorTests.swift @@ -0,0 +1,29 @@ +import XCTest + +class BackgroundColorTests: XCTestCase { + + func testOpaque() { + let buttonNoActionFixture = """ + [ { "type": "staticButton", "title": "Pew", "background": "#FF0000" } ] + """.data(using: .utf8)! + let result = try? JSONDecoder().decode([BarItemDefinition].self, from: buttonNoActionFixture) + guard case .background(let color)? = result?.first?.additionalParameters[.background] else { + XCTFail() + return + } + XCTAssertEqual(color, .red) + } + + func testAlpha() { + let buttonNoActionFixture = """ + [ { "type": "staticButton", "title": "Pew", "background": "#FF000080" } ] + """.data(using: .utf8)! + let result = try? JSONDecoder().decode([BarItemDefinition].self, from: buttonNoActionFixture) + guard case .background(let color)? = result?.first?.additionalParameters[.background] else { + XCTFail() + return + } + XCTAssertEqual(color.alphaComponent, 0.5, accuracy: 0.01) + } + +}