diff options
Diffstat (limited to 'server/test/command/note_row_standee_death_test.dart')
| -rw-r--r-- | server/test/command/note_row_standee_death_test.dart | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/server/test/command/note_row_standee_death_test.dart b/server/test/command/note_row_standee_death_test.dart new file mode 100644 index 0000000..5586700 --- /dev/null +++ b/server/test/command/note_row_standee_death_test.dart @@ -0,0 +1,81 @@ +// ignore_for_file: no-magic-number, avoid-late-keyword + +import 'package:test/test.dart'; +import 'package:x_haven_server/core/commands/add_monster_command.dart'; +import 'package:x_haven_server/core/commands/add_note_row_command.dart'; +import 'package:x_haven_server/core/commands/add_standee_command.dart'; +import 'package:x_haven_server/core/commands/change_stat_commands/change_health_command.dart'; +import 'package:x_haven_server/core/enums.dart'; +import 'package:x_haven_server/core/state/game_state.dart'; +import 'package:x_haven_server/core/service_locator.dart'; + +import 'test_helpers.dart'; + +void main() { + setUpAll(() async { + await setUpGame(); + }); + + GameState gs() => getIt<GameState>(); + + test( + 'a note tied to a specific standee is deleted when that standee dies', + () { + gs().clearList(); + AddMonsterCommand("Zealot", 1, false, gameState: gs()).execute(); + AddStandeeCommand( + 1, + null, + "Zealot", + MonsterType.normal, + false, + gameState: gs(), + ).execute(); + final monster = + gs().currentList.firstWhere((e) => e is Monster) as Monster; + final instance = monster.monsterInstances.first; + final standeeNr = instance.standeeNr; + + // A note pinned to this standee, plus a whole-group note (standeeNr 0). + gs().action( + AddNoteRowCommand( + NoteRow.create( + 'standeeNote', + linkedId: monster.id, + standeeNr: standeeNr, + ), + gameState: gs(), + ), + ); + gs().action( + AddNoteRowCommand( + NoteRow.create('groupNote', linkedId: monster.id), + gameState: gs(), + ), + ); + expect(gs().currentList.any((e) => e.id == 'standeeNote'), true); + + // Defeat the standee (drop its health to 0). + gs().action( + ChangeHealthCommand( + -instance.health, + instance.getId(), + monster.id, + gameState: gs(), + ), + ); + + // The standee's note is gone; the whole-group note remains. + expect( + gs().currentList.any((e) => e.id == 'standeeNote'), + false, + reason: 'note tied to the defeated standee should be deleted', + ); + expect( + gs().currentList.any((e) => e.id == 'groupNote'), + true, + reason: 'whole-group note is not standee-specific and should remain', + ); + }, + ); +} |
