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
|
// ignore_for_file: no-magic-number
import 'package:test/test.dart';
import 'package:x_haven_server/core/commands/add_monster_command.dart';
import 'package:x_haven_server/core/commands/set_level_command.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();
});
setUp(() {
getIt<GameState>().clearList();
});
group('AddMonsterCommand', () {
test('should add a monster to the game', () {
// Arrange
final command = AddMonsterCommand(
"Ancient Artillery (FH)",
2,
false,
gameState: getIt<GameState>(),
);
// Act
command.execute();
// Assert
final monster =
getIt<GameState>().currentList.firstWhere((e) => e is Monster)
as Monster;
expect(getIt<GameState>().currentList, contains(monster));
expect(monster.id, "Ancient Artillery (FH)");
expect(monster.level, 2);
expect(monster.isAlly, isFalse);
});
test('should add an allied monster', () {
// Arrange
final command = AddMonsterCommand(
"Ancient Artillery (FH)",
2,
true,
gameState: getIt<GameState>(),
);
// Act
command.execute();
// Assert
final monster =
getIt<GameState>().currentList.firstWhere((e) => e is Monster)
as Monster;
expect(monster.isAlly, isTrue);
});
test('should use game level if monster level is null', () {
// Arrange
SetLevelCommand(3, null).execute();
final command = AddMonsterCommand(
"Ancient Artillery (FH)",
null,
false,
gameState: getIt<GameState>(),
);
// Act
command.execute();
// Assert
final monster =
getIt<GameState>().currentList.firstWhere((e) => e is Monster)
as Monster;
expect(monster.level, 3);
});
test('describe should return correct string', () {
// Arrange
final command = AddMonsterCommand(
"Ancient Artillery (FH)",
2,
false,
gameState: getIt<GameState>(),
);
// Act & Assert
expect(command.describe(), 'Add Ancient Artillery');
});
});
}
|