// 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().clearList(); AddCharacterCommand('Banner Spear', 'Frosthaven', 'BS', 1).execute(); AddMonsterCommand( 'Ancient Artillery (FH)', 1, false, gameState: getIt(), ).execute(); }); group('ReorderListCommand', () { test('should swap two items in the main list', () { final list = getIt().currentList; final firstId = list[0].id; final secondId = list[1].id; ReorderListCommand(0, 1, gameState: getIt()).execute(); expect(getIt().currentList[0].id, secondId); expect(getIt().currentList[1].id, firstId); }); test('describe returns correct string', () { expect( ReorderListCommand(0, 1, gameState: getIt()).describe(), 'Reorder List', ); }); test('undo does not throw', () { final gs = getIt(); gs.action(ReorderListCommand(0, 1, gameState: getIt())); expect(() => gs.undo(), returnsNormally); }); }); group('ReorderAbilityListCommand', () { test('should reorder cards in a monster ability deck', () { final monster = getIt().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(), ).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(), ).describe(), 'Reorder Ability Cards', ); }); }); group('ReorderModifierListCommand', () { test('should reorder cards in a modifier deck draw pile', () { final deck = getIt().modifierDeck; if (deck.drawPileSize >= 2) { final firstGfx = deck.drawPileContents.toList()[0].gfx; final secondGfx = deck.drawPileContents.toList()[1].gfx; ReorderModifierListCommand( 0, 1, '', gameState: getIt(), ).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(), ).describe(), 'Reorder Modifier Cards', ); }); }); }