feat: swap translation languages with Return on empty input
This commit is contained in:
@@ -58,6 +58,26 @@ private func descendants(_ view: NSView) -> [NSView] { [view] + view.subviews.fl
|
||||
|
||||
@Suite(.serialized)
|
||||
struct TranslationExecutionTests {
|
||||
@Test @MainActor
|
||||
func emptyPrimaryActionSwapsLanguagesWithoutSubmitting() {
|
||||
_ = NSApplication.shared
|
||||
let suite = "TranslateEmpty.\(UUID().uuidString)"
|
||||
let defaults = UserDefaults(suiteName: suite)!
|
||||
defer { defaults.removePersistentDomain(forName: suite) }
|
||||
let tool = TranslationController(defaults: defaults,
|
||||
myMemory: { _, _, _ in Issue.record("Empty input must not submit"); return "unexpected" })
|
||||
tool.input = { " \n\t" }
|
||||
_ = tool.view
|
||||
let button = descendants(tool.view).compactMap { $0 as? NSButton }
|
||||
.first { $0.action == NSSelectorFromString("performPrimaryAction") }!
|
||||
button.performClick(nil)
|
||||
#expect(tool.sourceLanguage == "ja")
|
||||
#expect(tool.targetLanguage == "en")
|
||||
tool.performPrimaryAction()
|
||||
#expect(tool.sourceLanguage == "en")
|
||||
#expect(tool.targetLanguage == "ja")
|
||||
}
|
||||
|
||||
@Test @MainActor
|
||||
func languageActionsInvalidateOldResultsAndApplyTheSelectedPair() async throws {
|
||||
_ = NSApplication.shared
|
||||
|
||||
Reference in New Issue
Block a user