mirror of
https://github.com/Toxblh/MTMR.git
synced 2026-01-10 17:08:39 +00:00
* Implement double tap and new actions array in config * Update native widgets to use new actions parameter * Refactor new actions parameter moving it to main definition Renamed old action and longAction to legacy * Fix tests * Remove unused code * Readd test for legacyAction * Implement triple tap * Add new actions explanation * Add support for multiple actions and same trigger
83 lines
3.0 KiB
Swift
83 lines
3.0 KiB
Swift
import XCTest
|
|
|
|
class ParseConfig: XCTestCase {
|
|
func testButtonNoAction() {
|
|
let buttonNoActionFixture = """
|
|
[ { "type": "staticButton", "title": "Pew" } ]
|
|
""".data(using: .utf8)!
|
|
let result = try? JSONDecoder().decode([BarItemDefinition].self, from: buttonNoActionFixture)
|
|
guard case .staticButton("Pew")? = result?.first?.type else {
|
|
XCTFail()
|
|
return
|
|
}
|
|
guard result?.first?.actions.count == 0 else {
|
|
XCTFail()
|
|
return
|
|
}
|
|
}
|
|
|
|
func testButtonKeyCodeAction() {
|
|
let buttonKeycodeFixture = """
|
|
[ { "type": "staticButton", "title": "Pew", "actions": [ { "trigger": "singleTap", "action": "hidKey", "keycode": 123 } ] } ]
|
|
""".data(using: .utf8)!
|
|
let result = try? JSONDecoder().decode([BarItemDefinition].self, from: buttonKeycodeFixture)
|
|
guard case .staticButton("Pew")? = result?.first?.type else {
|
|
XCTFail()
|
|
return
|
|
}
|
|
guard case .hidKey(keycode: 123)? = result?.first?.actions.filter({ $0.trigger == .singleTap }).first?.value else {
|
|
XCTFail()
|
|
return
|
|
}
|
|
}
|
|
|
|
func testButtonKeyCodeLegacyAction() {
|
|
let buttonKeycodeFixture = """
|
|
[ { "type": "staticButton", "title": "Pew", "action": "hidKey", "keycode": 123 } ]
|
|
""".data(using: .utf8)!
|
|
let result = try? JSONDecoder().decode([BarItemDefinition].self, from: buttonKeycodeFixture)
|
|
guard case .staticButton("Pew")? = result?.first?.type else {
|
|
XCTFail()
|
|
return
|
|
}
|
|
guard case .hidKey(keycode: 123)? = result?.first?.legacyAction else {
|
|
XCTFail()
|
|
return
|
|
}
|
|
}
|
|
|
|
func testPredefinedItem() {
|
|
let buttonKeycodeFixture = """
|
|
[ { "type": "escape" } ]
|
|
""".data(using: .utf8)!
|
|
let result = try? JSONDecoder().decode([BarItemDefinition].self, from: buttonKeycodeFixture)
|
|
guard case .staticButton("esc")? = result?.first?.type else {
|
|
XCTFail()
|
|
return
|
|
}
|
|
guard case .keyPress(keycode: 53)? = result?.first?.actions.filter({ $0.trigger == .singleTap }).first?.value else {
|
|
XCTFail()
|
|
return
|
|
}
|
|
}
|
|
|
|
func testExtendedWidthForPredefinedItem() {
|
|
let buttonKeycodeFixture = """
|
|
[ { "type": "escape", "width": 110}, ]
|
|
""".data(using: .utf8)!
|
|
let result = try? JSONDecoder().decode([BarItemDefinition].self, from: buttonKeycodeFixture)
|
|
guard case .staticButton("esc")? = result?.first?.type else {
|
|
XCTFail()
|
|
return
|
|
}
|
|
guard case .keyPress(keycode: 53)? = result?.first?.actions.filter({ $0.trigger == .singleTap }).first?.value else {
|
|
XCTFail()
|
|
return
|
|
}
|
|
guard case .width(110)? = result?.first?.additionalParameters[.width] else {
|
|
XCTFail()
|
|
return
|
|
}
|
|
}
|
|
}
|