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
|
// ignore_for_file: prefer-first, no-magic-number, avoid-non-null-assertion
import 'package:test/test.dart';
import 'package:x_haven_server/core/commands/add_character_command.dart';
import 'package:x_haven_server/core/commands/add_monster_command.dart';
import 'package:x_haven_server/core/commands/reorder_ability_list_command.dart';
import 'package:x_haven_server/core/commands/reorder_list_command.dart';
import 'package:x_haven_server/core/commands/reorder_modifier_list_command.dart';
import 'package:x_haven_server/core/game_methods.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();
AddCharacterCommand('Banner Spear', 'Frosthaven', 'BS', 1).execute();
AddMonsterCommand(
'Ancient Artillery (FH)',
1,
false,
gameState: getIt<GameState>(),
).execute();
});
group('ReorderListCommand', () {
test('should swap two items in the main list', () {
final list = getIt<GameState>().currentList;
final firstId = list[0].id;
final secondId = list[1].id;
ReorderListCommand(0, 1, gameState: getIt<GameState>()).execute();
expect(getIt<GameState>().currentList[0].id, secondId);
expect(getIt<GameState>().currentList[1].id, firstId);
});
test('describe returns correct string', () {
expect(
ReorderListCommand(0, 1, gameState: getIt<GameState>()).describe(),
'Reorder List',
);
});
test('undo does not throw', () {
final gs = getIt<GameState>();
gs.action(ReorderListCommand(0, 1, gameState: getIt<GameState>()));
expect(() => gs.undo(), returnsNormally);
});
});
group('ReorderAbilityListCommand', () {
test('should reorder cards in a monster ability deck', () {
final monster =
getIt<GameState>().currentList.firstWhere((e) => e is Monster)
as Monster;
final deck = GameMethods.getDeck(monster.type.deck)!;
// Need at least 2 cards
if (deck.drawPileSize >= 2) {
final firstCardNr = deck.drawPileContents.toList()[0].nr;
final secondCardNr = deck.drawPileContents.toList()[1].nr;
ReorderAbilityListCommand(
monster.type.deck,
0,
1,
gameState: getIt<GameState>(),
).execute();
expect(deck.drawPileContents.toList()[0].nr, secondCardNr);
expect(deck.drawPileContents.toList()[1].nr, firstCardNr);
}
});
test('describe returns correct string', () {
expect(
ReorderAbilityListCommand(
'deck',
0,
1,
gameState: getIt<GameState>(),
).describe(),
'Reorder Ability Cards',
);
});
});
group('ReorderModifierListCommand', () {
test('should reorder cards in a modifier deck draw pile', () {
final deck = getIt<GameState>().modifierDeck;
if (deck.drawPileSize >= 2) {
final firstGfx = deck.drawPileContents.toList()[0].gfx;
final secondGfx = deck.drawPileContents.toList()[1].gfx;
ReorderModifierListCommand(
0,
1,
'',
gameState: getIt<GameState>(),
).execute();
expect(deck.drawPileContents.toList()[0].gfx, secondGfx);
expect(deck.drawPileContents.toList()[1].gfx, firstGfx);
}
});
test('describe returns correct string', () {
expect(
ReorderModifierListCommand(
0,
1,
'',
gameState: getIt<GameState>(),
).describe(),
'Reorder Modifier Cards',
);
});
});
}
|