Skip to content

Commit

Permalink
Refactor integration test
Browse files Browse the repository at this point in the history
Instead of pulling information out of the screen to do stuff with it, we are
asking the screen to tell us what we need.
  • Loading branch information
doctor-g committed Feb 1, 2024
1 parent d3373f4 commit 045b7b3
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 16 deletions.
2 changes: 1 addition & 1 deletion project/story/starting_stories/steven_dnd.gd
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var options := {
"curiosity": 1,
}
},
"Er... No thanks.": {
"Er... No thanks. ": {
"text": "\"Oh, Okay.\" \nSteven walks away dejectedly.",
},
}
Expand Down
18 changes: 5 additions & 13 deletions project/test/integration/simple_story_validity_test.gd
Original file line number Diff line number Diff line change
Expand Up @@ -216,20 +216,12 @@ func _test_text_content(text, story_path: String):
func _get_option_line_lengths(story: SimpleStory) -> Array[int]:
var game_screen: Node = add_child_autofree(preload("res://ui/game_screen.tscn").instantiate())

for option in story.options:
game_screen.create_option_button(option)
# Extract just the option names from the options dictionary
var options :Array = story.options.keys()

game_screen.show_options(options)

# Required to let the UI "settle" before checking the line count.
await get_tree().process_frame

var option_buttons := game_screen.get_node("%OptionArea").get_children()

var result: Array[int] = []

for button in option_buttons:
var label := button.get_node("%Label")
var text_lines = label.get_visible_line_count()

result.append(text_lines)

return result
return game_screen.get_visible_line_counts_in_options()
4 changes: 4 additions & 0 deletions project/ui/audible_button.gd
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ signal pressed
%Label.add_theme_color_override("font_color", text_color)


func get_visible_line_count() -> int:
return %Label.get_visible_line_count()


func _on_pressed():
Sfx.play_click_sound()
pressed.emit()
15 changes: 13 additions & 2 deletions project/ui/game_screen.gd
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ func _input(event):
tapped_anywhere.emit()


## Return the respective line count of each option button text.
##
## This is used for integration testing and is not intended to be
## part of the presenter layer.
func get_visible_line_counts_in_options() -> Array[int]:
var result : Array[int] = []
for button in _option_area.get_children():
result.append(button.get_visible_line_count())
return result


## Finish an interaction with the presenter.
## This gives the player a chance to confirm that they are done with the
## current story.
Expand Down Expand Up @@ -106,7 +117,7 @@ func show_npc(npc:Npc, location:Texture) -> void:
func show_options(options: Array) -> String:
var buttons : Array[Control] = []
for option in options:
buttons.append(create_option_button(option))
buttons.append(_create_option_button(option))

var selection = await _option_selected
GameLog.made_choice(selection)
Expand All @@ -117,7 +128,7 @@ func show_options(options: Array) -> String:
return selection


func create_option_button(option: String) -> Node:
func _create_option_button(option: String) -> Node:
var button := preload("res://ui/audible_button.tscn").instantiate()
button.text = option
button.pressed.connect(func(): _option_selected.emit(option))
Expand Down

0 comments on commit 045b7b3

Please sign in to comment.