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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
// ignore_for_file: no-magic-number, avoid-late-keyword
import 'package:test/test.dart';
import 'package:x_haven_server/core/commands/add_character_command.dart';
import 'package:x_haven_server/core/commands/add_condition_command.dart';
import 'package:x_haven_server/core/commands/add_monster_command.dart';
import 'package:x_haven_server/core/commands/add_standee_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();
});
late Character character;
late Monster monster;
late MonsterInstance monsterInstance;
setUp(() {
getIt<GameState>().clearList();
AddCharacterCommand('Blinkblade', 'Frosthaven', "", 1).execute();
AddMonsterCommand(
"Ancient Artillery (FH)",
1,
false,
gameState: getIt<GameState>(),
).execute();
AddStandeeCommand(
1,
null,
"Ancient Artillery (FH)",
MonsterType.normal,
false,
gameState: getIt<GameState>(),
).execute();
character =
getIt<GameState>().currentList.firstWhere((e) => e is Character)
as Character;
monster =
getIt<GameState>().currentList.firstWhere((e) => e is Monster)
as Monster;
monsterInstance = monster.monsterInstances.first;
});
group('AddConditionCommand', () {
test('should add a condition to a character', () {
// Arrange
final command = AddConditionCommand(
Condition.poison,
character.id,
character.id,
gameState: getIt<GameState>(),
);
// Act
command.execute();
// Assert
expect(character.characterState.conditions, contains(Condition.poison));
});
test('should add a condition to a monster instance', () {
// Arrange
final command = AddConditionCommand(
Condition.wound,
monsterInstance.getId(),
monster.id,
gameState: getIt<GameState>(),
);
// Act
command.execute();
// Assert
expect(monsterInstance.conditions, contains(Condition.wound));
});
test('should increment chill counter when adding CHILL condition', () {
// Arrange
final command1 = AddConditionCommand(
Condition.chill,
character.id,
character.id,
gameState: getIt<GameState>(),
);
final command2 = AddConditionCommand(
Condition.chill,
character.id,
character.id,
gameState: getIt<GameState>(),
);
// Act
command1.execute();
command2.execute();
// Assert
expect(character.characterState.chill, 2);
// The list will contain two chill entries
expect(
character.characterState.conditions
.where((c) => c == Condition.chill)
.length,
2,
);
});
test('should not add a duplicate non-stacking condition', () {
// Arrange
final command1 = AddConditionCommand(
Condition.poison,
character.id,
character.id,
gameState: getIt<GameState>(),
);
final command2 = AddConditionCommand(
Condition.poison,
character.id,
character.id,
gameState: getIt<GameState>(),
);
// Act
command1.execute();
command2.execute();
// Assert
expect(
character.characterState.conditions
.where((c) => c == Condition.poison)
.length,
1,
);
});
test('describe should return correct string for character', () {
// Arrange
final command = AddConditionCommand(
Condition.muddle,
character.id,
character.id,
gameState: getIt<GameState>(),
);
// Act & Assert
expect(command.describe(), 'Add condition: muddle');
});
test('describe should return correct string for monster', () {
// Arrange
final command = AddConditionCommand(
Condition.stun,
monster.id,
monsterInstance.getId(),
gameState: getIt<GameState>(),
);
// Act & Assert
expect(command.describe(), 'Add condition: stun');
});
});
}
|