Compare commits
2 Commits
39b2068121
...
2179331455
| Author | SHA1 | Date | |
|---|---|---|---|
| 2179331455 | |||
| 9229f1f0a5 |
@@ -61,4 +61,13 @@ class PlayerDao extends DatabaseAccessor<AppDatabase> with _$PlayerDaoMixin {
|
||||
PlayerTableCompanion(name: Value(newName)),
|
||||
);
|
||||
}
|
||||
|
||||
/// Retrieves the total count of players in the database.
|
||||
Future<int> getPlayerCount() async {
|
||||
final count =
|
||||
await (selectOnly(playerTable)..addColumns([playerTable.id.count()]))
|
||||
.map((row) => row.read(playerTable.id.count()))
|
||||
.getSingle();
|
||||
return count ?? 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:game_tracker/core/custom_theme.dart';
|
||||
import 'package:game_tracker/data/db/database.dart';
|
||||
import 'package:game_tracker/data/dto/game.dart';
|
||||
import 'package:game_tracker/data/dto/group.dart';
|
||||
import 'package:game_tracker/data/dto/player.dart';
|
||||
import 'package:game_tracker/presentation/views/main_menu/custom_navigation_bar.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
@@ -22,8 +19,6 @@ class GameTracker extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
dbCheck(context);
|
||||
|
||||
return MaterialApp(
|
||||
debugShowCheckedModeBanner: false,
|
||||
title: 'Game Tracker',
|
||||
@@ -44,29 +39,4 @@ class GameTracker extends StatelessWidget {
|
||||
home: const CustomNavigationBar(),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> dbCheck(BuildContext context) async {
|
||||
Player player1 = Player(id: 'p1', name: 'Alice');
|
||||
Player player2 = Player(id: 'p2', name: 'Bob');
|
||||
Player player3 = Player(id: 'p3', name: 'Charlie');
|
||||
Player player4 = Player(id: 'p4', name: 'Diana');
|
||||
Group testgroup = Group(
|
||||
id: 'gr1',
|
||||
name: 'Test Group',
|
||||
members: [player1, player2, player3],
|
||||
);
|
||||
Game testgame = Game(
|
||||
id: 'ga1',
|
||||
name: 'Test Game',
|
||||
winner: player1.id,
|
||||
players: [player4],
|
||||
group: testgroup,
|
||||
);
|
||||
|
||||
final db = Provider.of<AppDatabase>(context, listen: false);
|
||||
//await db.gameDao.addGame(game: testgame);
|
||||
print('Game added: ${testgame.name}');
|
||||
final game = await db.gameDao.getGameById(gameId: testgame.id);
|
||||
print(game.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,4 +127,22 @@ void main() {
|
||||
final playerExists = result.members.any((p) => p.id == playerToRemove.id);
|
||||
expect(playerExists, false);
|
||||
});
|
||||
|
||||
test('get group count works correctly', () async {
|
||||
final initialCount = await database.groupDao.getGroupCount();
|
||||
expect(initialCount, 0);
|
||||
|
||||
await database.groupDao.addGroup(group: testgroup);
|
||||
|
||||
final groupAdded = await database.groupDao.getGroupCount();
|
||||
expect(groupAdded, 1);
|
||||
|
||||
final groupRemoved = await database.groupDao.deleteGroup(
|
||||
groupId: testgroup.id,
|
||||
);
|
||||
expect(groupRemoved, true);
|
||||
|
||||
final finalCount = await database.groupDao.getGroupCount();
|
||||
expect(finalCount, 0);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -62,5 +62,23 @@ void main() {
|
||||
);
|
||||
expect(result.name, newPlayerName);
|
||||
});
|
||||
|
||||
test('get player count works correctly', () async {
|
||||
final initialCount = await database.playerDao.getPlayerCount();
|
||||
expect(initialCount, 0);
|
||||
|
||||
await database.playerDao.addPlayer(player: testPlayer);
|
||||
|
||||
final playerAdded = await database.playerDao.getPlayerCount();
|
||||
expect(playerAdded, 1);
|
||||
|
||||
final playerRemoved = await database.playerDao.deletePlayer(
|
||||
playerId: testPlayer.id,
|
||||
);
|
||||
expect(playerRemoved, true);
|
||||
|
||||
final finalCount = await database.playerDao.getPlayerCount();
|
||||
expect(finalCount, 0);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user