Browse Source

test: multiple commands on one line

master
Dominique Merle 2 years ago
parent
commit
a19261edd7
  1. 14
      gui/forms/CandidatesTree.gd
  2. 18
      project.godot
  3. 38
      tests/commands.test.gd

14
gui/forms/CandidatesTree.gd

@ -10,6 +10,9 @@ const TEXT_COLUMN := 0
signal item_moved(item, to_item, section)
var invite_text = "+"
func _ready():
setup()
setup_dummy_items()
@ -20,8 +23,9 @@ func setup():
var root := create_item()
root.set_text(TEXT_COLUMN, "Candidates")
connect("item_edited", self, "__on_item_edited")
connect("item_moved", self, "__on_item_moved")
var _c
_c = connect("item_edited", self, "__on_item_edited")
_c = connect("item_moved", self, "__on_item_moved")
func setup_dummy_items():
@ -36,9 +40,7 @@ func create_candidate_item(__name:String):
func append_item_invitation():
var invite_text = "+"
var root = get_root()
# var item = root.get_children() # get_first_child(), probably
var items = __get_children_items(root)
if items and items.back().get_text(TEXT_COLUMN) == invite_text:
@ -49,8 +51,9 @@ func append_item_invitation():
invite.set_text(TEXT_COLUMN, invite_text)
invite.move_to_bottom() # superfluous
func prune_empty_items():
var items_to_prune = Array()
# var items_to_prune = Array()
for item in __get_children_items(get_root()):
if item.get_text(TEXT_COLUMN) == '':
if item.get_next():
@ -105,7 +108,6 @@ func __get_item_index(of_item:TreeItem):
return -1
func get_drag_data(_position) -> TreeItem:
set_drop_mode_flags(DROP_MODE_INBETWEEN)

18
project.godot

@ -74,6 +74,11 @@ _global_script_classes=[ {
"language": "GDScript",
"path": "res://addons/godot-twicil/helpers/irc_client_scure.gd"
}, {
"base": "Reference",
"class": "MajorityJudgmentAbstractJudgmentsProvider",
"language": "GDScript",
"path": "res://addons/majority_judgment/providers/MajorityJudgmentAbstractJudgmentsProvider.gd"
}, {
"base": "Resource",
"class": "MajorityJudgmentAbstractTallier",
"language": "GDScript",
@ -94,6 +99,16 @@ _global_script_classes=[ {
"language": "GDScript",
"path": "res://addons/majority_judgment/MajorityJudgmentCandidateTally.gd"
}, {
"base": "MajorityJudgmentAbstractJudgmentsProvider",
"class": "MajorityJudgmentChatCommandJudgmentsProvider",
"language": "GDScript",
"path": "res://addons/majority_judgment/providers/MajorityJudgmentChatCommandJudgmentsProvider.gd"
}, {
"base": "MajorityJudgmentChatCommandJudgmentsProvider",
"class": "MajorityJudgmentDemoProvider",
"language": "GDScript",
"path": "res://addons/majority_judgment/providers/MajorityJudgmentDemoProvider.gd"
}, {
"base": "MajorityJudgmentAbstractTallier",
"class": "MajorityJudgmentEasyTallier",
"language": "GDScript",
@ -188,10 +203,13 @@ _global_script_class_icons={
"IrcChatMessage": "",
"IrcClientEx": "",
"IrcClientSecure": "",
"MajorityJudgmentAbstractJudgmentsProvider": "",
"MajorityJudgmentAbstractTallier": "",
"MajorityJudgmentCandidate": "",
"MajorityJudgmentCandidateMeritProfile": "",
"MajorityJudgmentCandidateTally": "",
"MajorityJudgmentChatCommandJudgmentsProvider": "",
"MajorityJudgmentDemoProvider": "",
"MajorityJudgmentEasyTallier": "",
"MajorityJudgmentGrade": "",
"MajorityJudgmentGrading": "",

38
tests/commands.test.gd

@ -9,13 +9,19 @@ func title():
func start():
# Runs before all test related methods once
self.provider = MajorityJudgmentChatCommandJudgmentsProvider.new()
watch(self.provider, "judgment_emitted")
pass
func pre():
# Runs before each test method
pass
refresh_provider()
func refresh_provider():
if self.provider:
unwatch(self.provider, "judgment_emitted")
self.provider = MajorityJudgmentChatCommandJudgmentsProvider.new()
watch(self.provider, "judgment_emitted")
func test_single_command():
@ -25,7 +31,13 @@ func test_single_command():
do_test_single_command("E4", [4, 4])
func test_multi_command():
do_test_multi_command("A4 B3 C3", [[0, 4],[1, 3],[2, 3]])
do_test_multi_command("B4b1L0n3", [[1, 4],[1, 1],[11, 0],[13, 3]])
func do_test_single_command(command:String, expected:Array):
refresh_provider()
var author = "Tester"
self.provider.process_chat_command(author, command)
asserts.signal_was_emitted(
@ -39,3 +51,23 @@ func do_test_single_command(command:String, expected:Array):
[author, expected[0], expected[1]],
"Signal was emitted with correct arguments"
)
func do_test_multi_command(command:String, expecteds:Array):
refresh_provider()
var author = "Tester"
self.provider.process_chat_command(author, command)
asserts.signal_was_emitted_x_times(
self.provider,
"judgment_emitted",
expecteds.size(),
"Signal was emitted %d times" % expecteds.size()
)
for expected in expecteds:
asserts.signal_was_emitted_with_arguments(
self.provider,
"judgment_emitted",
[author, expected[0], expected[1]],
"Signal was emitted with correct arguments"
)
Loading…
Cancel
Save