-
Notifications
You must be signed in to change notification settings - Fork 5.1k
CAMEL-23838: Fix camel-jbang TUI help (F1/? broken) #24277
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
...ugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/CamelMonitorTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.camel.dsl.jbang.core.commands.tui; | ||
|
|
||
| import dev.tamboui.tui.event.KeyCode; | ||
| import dev.tamboui.tui.event.KeyEvent; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertFalse; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| class CamelMonitorTest { | ||
|
|
||
| // '?' is an alternative to F1 for opening the help overlay. Unlike F1, it must be suppressed | ||
| // while a text input is focused, otherwise typing '?' in a search or probe field would | ||
| // pop up help instead of inserting the character. | ||
|
|
||
| @Test | ||
| void f1OpensHelpEvenWhileTextEditing() { | ||
| assertTrue(CamelMonitor.opensHelp(KeyEvent.ofKey(KeyCode.F1), true), "F1 must open help regardless of text editing"); | ||
| assertTrue(CamelMonitor.opensHelp(KeyEvent.ofKey(KeyCode.F1), false), "F1 must open help"); | ||
| } | ||
|
|
||
| @Test | ||
| void questionMarkOpensHelpWhenNotTextEditing() { | ||
| assertTrue(CamelMonitor.opensHelp(KeyEvent.ofChar('?'), false), "'?' must open help when no input is focused"); | ||
| } | ||
|
|
||
| @Test | ||
| void questionMarkIsSuppressedWhileTextEditing() { | ||
| assertFalse(CamelMonitor.opensHelp(KeyEvent.ofChar('?'), true), | ||
| "'?' must not open help while a text input is focused"); | ||
| } | ||
|
|
||
| @Test | ||
| void unrelatedKeyDoesNotOpenHelp() { | ||
| assertFalse(CamelMonitor.opensHelp(KeyEvent.ofChar('x'), false), "an unrelated key must not open help"); | ||
| } | ||
| } | ||
72 changes: 72 additions & 0 deletions
72
...lugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/HelpOverlayTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.camel.dsl.jbang.core.commands.tui; | ||
|
|
||
| import dev.tamboui.tui.event.KeyCode; | ||
| import dev.tamboui.tui.event.KeyEvent; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertFalse; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| class HelpOverlayTest { | ||
|
|
||
| // The help overlay is opened with either F1 or '?'. Pressing the same keys again must close it, | ||
| // so the binding is a true toggle. '?' was previously ignored by the overlay (CAMEL: TUI help). | ||
|
|
||
| @Test | ||
| void questionMarkClosesOverlay() { | ||
| HelpOverlay overlay = new HelpOverlay(); | ||
| overlay.open("# Help"); | ||
| assertTrue(overlay.isVisible()); | ||
|
|
||
| boolean handled = overlay.handleKeyEvent(KeyEvent.ofChar('?')); | ||
|
|
||
| assertTrue(handled, "the overlay must consume the key while visible"); | ||
| assertFalse(overlay.isVisible(), "'?' must close the help overlay it opened"); | ||
| } | ||
|
|
||
| @Test | ||
| void f1ClosesOverlay() { | ||
| HelpOverlay overlay = new HelpOverlay(); | ||
| overlay.open("# Help"); | ||
|
|
||
| overlay.handleKeyEvent(KeyEvent.ofKey(KeyCode.F1)); | ||
|
|
||
| assertFalse(overlay.isVisible(), "F1 must still close the help overlay"); | ||
| } | ||
|
|
||
| @Test | ||
| void quitKeyClosesOverlay() { | ||
| HelpOverlay overlay = new HelpOverlay(); | ||
| overlay.open("# Help"); | ||
|
|
||
| overlay.handleKeyEvent(KeyEvent.ofChar('q')); | ||
|
|
||
| assertFalse(overlay.isVisible(), "'q' must still close the help overlay"); | ||
| } | ||
|
|
||
| @Test | ||
| void unrelatedKeyKeepsOverlayOpen() { | ||
| HelpOverlay overlay = new HelpOverlay(); | ||
| overlay.open("# Help"); | ||
|
|
||
| overlay.handleKeyEvent(KeyEvent.ofChar('x')); | ||
|
|
||
| assertTrue(overlay.isVisible(), "an unrelated key must not close the help overlay"); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.