Skip to content
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

Update InputSender documentation for "emit" approach. #550

Open
bitwes opened this issue Jan 9, 2024 · 0 comments
Open

Update InputSender documentation for "emit" approach. #550

bitwes opened this issue Jan 9, 2024 · 0 comments

Comments

@bitwes
Copy link
Owner

bitwes commented Jan 9, 2024

          I think you could put these informations in the [DOCS](https://gut.readthedocs.io/en/latest/Mocking-Input.html).

It would help a lot beginners, I was searching these information for three days already.

Thank you you put here!

Information 1

There is some stuff in the InputSender that makes this a little cleaner, but the "waits" are necessary. You can string all your commands together and there is wait_frames and wait_secs built into the sender. There's also hold_for which can save you a "button up". You can then wait for the idle signal on the sender.

Some waits can be skipped in different scenarios (such as no wait between your button down/up). But if you want something like just_pressed you have to use waits (I'm pretty sure).

Here's another way to write that test without using any direct calls to wait_frames.

func test_open_settings_menu() -> void:
	var settings_button_pos = button_settings.get_global_position()
	_sender.mouse_set_position(settings_button_pos, settings_button_pos)\
		.wait_frames(1)\
		.mouse_left_button_down(settings_button_pos, settings_button_pos)\
		.hold_for('1f')\ # holds the button down for one frame, for illustration purposes, no button up needed
		.wait_frames(1)
	await _sender.idle

	assert_eq(main_menu.visible,false)
	assert_eq(settings_menu.visible,true)

Information 2

I absolutely love seeing people using InputSender, but if you are only checking that you are handling the button pressed correctly then the following is a better test.

func test_open_settings_menu_seconds() -> void:
	button_settings.pressed.emit()
	assert_eq(main_menu.visible, false)
	assert_eq(settings_menu.visible, true)

If all of your buttons are standard buttons then it is overkill to test whether or not they work with the mouse (a minor case of "testing the framework"). Getting a reference to

I believe the second information is more simple to use, and draw attention that also exists button_up and button_down could help more people.

Originally posted by @hugarty in #511 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant