-
Notifications
You must be signed in to change notification settings - Fork 41
fix(dialog): respect auto_hide config when dismissing dialogs #276
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,293 @@ | ||
| local Dialog = require('opencode.ui.dialog') | ||
| local state = require('opencode.state') | ||
| local config = require('opencode.config') | ||
|
|
||
| describe('Dialog', function() | ||
| local input_buf, output_buf, input_win, output_win | ||
| local original_auto_hide | ||
|
|
||
| before_each(function() | ||
| -- Save original config | ||
| original_auto_hide = config.ui.input.auto_hide | ||
|
|
||
| -- Create test buffers and windows | ||
| input_buf = vim.api.nvim_create_buf(false, true) | ||
| output_buf = vim.api.nvim_create_buf(false, true) | ||
| input_win = vim.api.nvim_open_win(input_buf, true, { | ||
| relative = 'editor', | ||
| width = 80, | ||
| height = 10, | ||
| row = 0, | ||
| col = 0, | ||
| }) | ||
| output_win = vim.api.nvim_open_win(output_buf, false, { | ||
| relative = 'editor', | ||
| width = 80, | ||
| height = 10, | ||
| row = 11, | ||
| col = 0, | ||
| }) | ||
|
|
||
| state.windows = { | ||
| input_buf = input_buf, | ||
| input_win = input_win, | ||
| output_buf = output_buf, | ||
| output_win = output_win, | ||
| } | ||
|
|
||
| -- Mock input_window module | ||
| package.loaded['opencode.ui.input_window'] = nil | ||
| end) | ||
|
|
||
| after_each(function() | ||
| -- Restore original config | ||
| config.ui.input.auto_hide = original_auto_hide | ||
|
|
||
| -- Clean up windows and buffers | ||
| pcall(vim.api.nvim_win_close, input_win, true) | ||
| pcall(vim.api.nvim_win_close, output_win, true) | ||
| pcall(vim.api.nvim_buf_delete, input_buf, { force = true }) | ||
| pcall(vim.api.nvim_buf_delete, output_buf, { force = true }) | ||
|
|
||
| state.windows = nil | ||
| package.loaded['opencode.ui.input_window'] = nil | ||
| end) | ||
|
|
||
| describe('teardown with hide_input enabled', function() | ||
| it('should show input window when auto_hide is disabled', function() | ||
| config.ui.input.auto_hide = false | ||
|
|
||
| local show_called = false | ||
| local input_window = { | ||
| _show = function() | ||
| show_called = true | ||
| end, | ||
| _hide = function() end, | ||
| } | ||
| package.loaded['opencode.ui.input_window'] = input_window | ||
|
|
||
| local dialog = Dialog.new({ | ||
| buffer = output_buf, | ||
| on_select = function() end, | ||
| get_option_count = function() | ||
| return 3 | ||
| end, | ||
| hide_input = true, | ||
| }) | ||
|
|
||
| dialog:setup() | ||
| dialog:teardown() | ||
|
|
||
| assert.is_true(show_called, 'input window should be shown when auto_hide is disabled') | ||
| end) | ||
|
|
||
| it('should NOT show input window when auto_hide is enabled', function() | ||
| config.ui.input.auto_hide = true | ||
|
|
||
| local show_called = false | ||
| local input_window = { | ||
| _show = function() | ||
| show_called = true | ||
| end, | ||
| _hide = function() end, | ||
| } | ||
| package.loaded['opencode.ui.input_window'] = input_window | ||
|
|
||
| local dialog = Dialog.new({ | ||
| buffer = output_buf, | ||
| on_select = function() end, | ||
| get_option_count = function() | ||
| return 3 | ||
| end, | ||
| hide_input = true, | ||
| }) | ||
|
|
||
| dialog:setup() | ||
| dialog:teardown() | ||
|
|
||
| assert.is_false(show_called, 'input window should NOT be shown when auto_hide is enabled') | ||
| end) | ||
|
|
||
| it('should not call _show when hide_input is disabled', function() | ||
| config.ui.input.auto_hide = false | ||
|
|
||
| local show_called = false | ||
| local input_window = { | ||
| _show = function() | ||
| show_called = true | ||
| end, | ||
| _hide = function() end, | ||
| } | ||
| package.loaded['opencode.ui.input_window'] = input_window | ||
|
|
||
| local dialog = Dialog.new({ | ||
| buffer = output_buf, | ||
| on_select = function() end, | ||
| get_option_count = function() | ||
| return 3 | ||
| end, | ||
| hide_input = false, -- Dialog doesn't manage input window | ||
| }) | ||
|
|
||
| dialog:setup() | ||
| dialog:teardown() | ||
|
|
||
| assert.is_false(show_called, 'input window should not be managed when hide_input is false') | ||
| end) | ||
| end) | ||
|
|
||
| describe('setup with hide_input enabled', function() | ||
| it('should hide input window during setup', function() | ||
| config.ui.input.auto_hide = false | ||
|
|
||
| local hide_called = false | ||
| local input_window = { | ||
| _show = function() end, | ||
| _hide = function() | ||
| hide_called = true | ||
| end, | ||
| } | ||
| package.loaded['opencode.ui.input_window'] = input_window | ||
|
|
||
| local dialog = Dialog.new({ | ||
| buffer = output_buf, | ||
| on_select = function() end, | ||
| get_option_count = function() | ||
| return 3 | ||
| end, | ||
| hide_input = true, | ||
| }) | ||
|
|
||
| dialog:setup() | ||
|
|
||
| assert.is_true(hide_called, 'input window should be hidden during dialog setup') | ||
| end) | ||
|
|
||
| it('should hide input window during setup even with auto_hide enabled', function() | ||
| config.ui.input.auto_hide = true | ||
|
|
||
| local hide_called = false | ||
| local input_window = { | ||
| _show = function() end, | ||
| _hide = function() | ||
| hide_called = true | ||
| end, | ||
| } | ||
| package.loaded['opencode.ui.input_window'] = input_window | ||
|
|
||
| local dialog = Dialog.new({ | ||
| buffer = output_buf, | ||
| on_select = function() end, | ||
| get_option_count = function() | ||
| return 3 | ||
| end, | ||
| hide_input = true, | ||
| }) | ||
|
|
||
| dialog:setup() | ||
|
|
||
| assert.is_true(hide_called, 'input window should be hidden during dialog setup regardless of auto_hide') | ||
| end) | ||
| end) | ||
|
|
||
| describe('regression test for question and permission dialogs', function() | ||
| it('should not show input after answering question with auto_hide enabled', function() | ||
| config.ui.input.auto_hide = true | ||
|
|
||
| local show_called = false | ||
| local hide_called = false | ||
| local input_window = { | ||
| _show = function() | ||
| show_called = true | ||
| end, | ||
| _hide = function() | ||
| hide_called = true | ||
| end, | ||
| } | ||
| package.loaded['opencode.ui.input_window'] = input_window | ||
|
|
||
| -- Simulate question dialog flow | ||
| local dialog = Dialog.new({ | ||
| buffer = output_buf, | ||
| on_select = function() end, | ||
| get_option_count = function() | ||
| return 3 | ||
| end, | ||
| hide_input = true, | ||
| }) | ||
|
|
||
| dialog:setup() | ||
| assert.is_true(hide_called, 'input should be hidden when question appears') | ||
|
|
||
| show_called = false -- reset | ||
| dialog:teardown() | ||
| assert.is_false(show_called, 'input should NOT be shown after answering question with auto_hide enabled') | ||
| end) | ||
|
|
||
| it('should not show input after responding to permission with auto_hide enabled', function() | ||
| config.ui.input.auto_hide = true | ||
|
|
||
| local show_called = false | ||
| local hide_called = false | ||
| local input_window = { | ||
| _show = function() | ||
| show_called = true | ||
| end, | ||
| _hide = function() | ||
| hide_called = true | ||
| end, | ||
| } | ||
| package.loaded['opencode.ui.input_window'] = input_window | ||
|
|
||
| -- Simulate permission dialog flow | ||
| local dialog = Dialog.new({ | ||
| buffer = output_buf, | ||
| on_select = function() end, | ||
| get_option_count = function() | ||
| return 3 | ||
| end, | ||
| hide_input = true, | ||
| }) | ||
|
|
||
| dialog:setup() | ||
| assert.is_true(hide_called, 'input should be hidden when permission prompt appears') | ||
|
|
||
| show_called = false -- reset | ||
| dialog:teardown() | ||
| assert.is_false(show_called, 'input should NOT be shown after responding to permission with auto_hide enabled') | ||
| end) | ||
|
|
||
| it('should show input after answering question with auto_hide disabled', function() | ||
| config.ui.input.auto_hide = false | ||
|
|
||
| local show_called = false | ||
| local hide_called = false | ||
| local input_window = { | ||
| _show = function() | ||
| show_called = true | ||
| end, | ||
| _hide = function() | ||
| hide_called = true | ||
| end, | ||
| } | ||
| package.loaded['opencode.ui.input_window'] = input_window | ||
|
|
||
| -- Simulate question dialog flow | ||
| local dialog = Dialog.new({ | ||
| buffer = output_buf, | ||
| on_select = function() end, | ||
| get_option_count = function() | ||
| return 3 | ||
| end, | ||
| hide_input = true, | ||
| }) | ||
|
|
||
| dialog:setup() | ||
| assert.is_true(hide_called, 'input should be hidden when question appears') | ||
|
|
||
| show_called = false -- reset | ||
| dialog:teardown() | ||
| assert.is_true(show_called, 'input should be shown after answering question with auto_hide disabled') | ||
| end) | ||
| end) | ||
| end) |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wasn't sure if the tests belong in
input_window_specinstead but I guess it should follow the source file 😄There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More tests never hurts. 😂