summaryrefslogtreecommitdiff
path: root/server/test/command/note_row_standee_death_test.dart
blob: 55867005ee97d580999eff9f6a5afda815500847 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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',
      );
    },
  );
}