Revert "Merge branch 'feature/193-statisticsview-rework' into development"
All checks were successful
Push Pipeline / update_version (push) Successful in 6s
Push Pipeline / generate_licenses (push) Successful in 38s
Push Pipeline / generate_localizations (push) Successful in 29s
Push Pipeline / test (push) Successful in 1m35s
Push Pipeline / sort_arb_files (push) Successful in 31s
Push Pipeline / format (push) Successful in 55s
Push Pipeline / build (push) Successful in 4m58s
All checks were successful
Push Pipeline / update_version (push) Successful in 6s
Push Pipeline / generate_licenses (push) Successful in 38s
Push Pipeline / generate_localizations (push) Successful in 29s
Push Pipeline / test (push) Successful in 1m35s
Push Pipeline / sort_arb_files (push) Successful in 31s
Push Pipeline / format (push) Successful in 55s
Push Pipeline / build (push) Successful in 4m58s
This reverts commit24f49e17b9, reversing changes made todba6c218d6. # Conflicts: # pubspec.yaml
This commit is contained in:
@@ -194,31 +194,6 @@ void main() {
|
||||
expect(allGroups, isEmpty);
|
||||
});
|
||||
|
||||
test('getGroupsByPlayer() works correctly', () async {
|
||||
await database.groupDao.addGroupsAsList(
|
||||
groups: [testGroup1, testGroup2],
|
||||
);
|
||||
|
||||
final groups = await database.groupDao.getGroupsByPlayer(
|
||||
playerId: testPlayer2.id,
|
||||
);
|
||||
|
||||
expect(groups, hasLength(2));
|
||||
expect(groups.any((group) => group.id == testGroup1.id), isTrue);
|
||||
expect(groups.any((group) => group.id == testGroup2.id), isTrue);
|
||||
});
|
||||
|
||||
test(
|
||||
'getGroupsByPlayer() returns empty list for non-existent player',
|
||||
() async {
|
||||
final groups = await database.groupDao.getGroupsByPlayer(
|
||||
playerId: 'non-existent-player-id',
|
||||
);
|
||||
|
||||
expect(groups, isEmpty);
|
||||
},
|
||||
);
|
||||
|
||||
test('addGroupsAsList() with duplicate groups only adds once', () async {
|
||||
await database.groupDao.addGroupsAsList(
|
||||
groups: [testGroup1, testGroup1, testGroup1],
|
||||
|
||||
@@ -56,7 +56,7 @@ void main() {
|
||||
name: 'Test Game',
|
||||
ruleset: Ruleset.singleWinner,
|
||||
description: 'A test game',
|
||||
color: AppColor.blue,
|
||||
color: GameColor.blue,
|
||||
icon: '',
|
||||
);
|
||||
testMatch1 = Match(
|
||||
@@ -260,34 +260,6 @@ void main() {
|
||||
expect(match.group!.id, testGroup1.id);
|
||||
});
|
||||
|
||||
test('getMatchesByPlayer() works correctly', () async {
|
||||
await database.matchDao.addMatchesAsList(
|
||||
matches: [testMatch1, testMatch2],
|
||||
);
|
||||
|
||||
final matches = await database.matchDao.getMatchesByPlayer(
|
||||
playerId: testPlayer1.id,
|
||||
);
|
||||
|
||||
expect(matches, hasLength(1));
|
||||
expect(matches.first.id, testMatch2.id);
|
||||
expect(
|
||||
matches.first.players.any((p) => p.id == testPlayer1.id),
|
||||
isTrue,
|
||||
);
|
||||
});
|
||||
|
||||
test(
|
||||
'getMatchesByPlayer() returns empty list for non-existent player',
|
||||
() async {
|
||||
final matches = await database.matchDao.getMatchesByPlayer(
|
||||
playerId: 'non-existing-player-id',
|
||||
);
|
||||
|
||||
expect(matches, isEmpty);
|
||||
},
|
||||
);
|
||||
|
||||
test('getMatchCount() works correctly', () async {
|
||||
var count = await database.matchDao.getMatchCount();
|
||||
expect(count, 0);
|
||||
|
||||
@@ -49,7 +49,7 @@ void main() {
|
||||
testGame = Game(
|
||||
name: 'Test Game',
|
||||
ruleset: Ruleset.highestScore,
|
||||
color: AppColor.blue,
|
||||
color: GameColor.blue,
|
||||
icon: '',
|
||||
);
|
||||
testMatch1 = Match(
|
||||
|
||||
@@ -28,7 +28,7 @@ void main() {
|
||||
name: 'Chess',
|
||||
ruleset: Ruleset.singleWinner,
|
||||
description: 'A classic strategy game',
|
||||
color: AppColor.blue,
|
||||
color: GameColor.blue,
|
||||
icon: 'chess_icon',
|
||||
);
|
||||
testGame2 = Game(
|
||||
@@ -36,7 +36,7 @@ void main() {
|
||||
name: 'Poker',
|
||||
ruleset: Ruleset.multipleWinners,
|
||||
description: 'Card game with multiple winners',
|
||||
color: AppColor.red,
|
||||
color: GameColor.red,
|
||||
icon: 'poker_icon',
|
||||
);
|
||||
testGame3 = Game(
|
||||
@@ -44,7 +44,7 @@ void main() {
|
||||
name: 'Monopoly',
|
||||
ruleset: Ruleset.highestScore,
|
||||
description: 'A board game about real estate',
|
||||
color: AppColor.orange,
|
||||
color: GameColor.orange,
|
||||
icon: '',
|
||||
);
|
||||
});
|
||||
@@ -124,7 +124,7 @@ void main() {
|
||||
name: 'Game\'s & "Special" <Name>',
|
||||
ruleset: Ruleset.multipleWinners,
|
||||
description: 'Description with émojis 🎮🎲',
|
||||
color: AppColor.purple,
|
||||
color: GameColor.purple,
|
||||
icon: '',
|
||||
);
|
||||
await database.gameDao.addGame(game: specialGame);
|
||||
@@ -280,19 +280,19 @@ void main() {
|
||||
|
||||
await database.gameDao.updateGameColor(
|
||||
gameId: testGame1.id,
|
||||
color: AppColor.green,
|
||||
color: GameColor.green,
|
||||
);
|
||||
|
||||
final updatedGame = await database.gameDao.getGameById(
|
||||
gameId: testGame1.id,
|
||||
);
|
||||
expect(updatedGame.color, AppColor.green);
|
||||
expect(updatedGame.color, GameColor.green);
|
||||
});
|
||||
|
||||
test('updateGameColor() does nothing for non-existent game', () async {
|
||||
final updated = await database.gameDao.updateGameColor(
|
||||
gameId: 'non-existent-id',
|
||||
color: AppColor.green,
|
||||
color: GameColor.green,
|
||||
);
|
||||
expect(updated, isFalse);
|
||||
|
||||
@@ -336,7 +336,7 @@ void main() {
|
||||
name: newName,
|
||||
);
|
||||
|
||||
const newGameColor = AppColor.teal;
|
||||
const newGameColor = GameColor.teal;
|
||||
await database.gameDao.updateGameColor(
|
||||
gameId: testGame1.id,
|
||||
color: newGameColor,
|
||||
|
||||
@@ -233,95 +233,6 @@ void main() {
|
||||
expect(allPlayers, isEmpty);
|
||||
});
|
||||
|
||||
test('updatePlayerName() sets correct nameCount with 2 player', () async {
|
||||
await database.playerDao.addPlayer(player: testPlayer1);
|
||||
await database.playerDao.addPlayer(player: testPlayer2);
|
||||
|
||||
final newName = testPlayer1.name;
|
||||
await database.playerDao.updatePlayerName(
|
||||
playerId: testPlayer2.id,
|
||||
name: newName,
|
||||
);
|
||||
|
||||
var player = await database.playerDao.getPlayerById(
|
||||
playerId: testPlayer1.id,
|
||||
);
|
||||
expect(player.nameCount, 1);
|
||||
|
||||
player = await database.playerDao.getPlayerById(
|
||||
playerId: testPlayer2.id,
|
||||
);
|
||||
expect(player.nameCount, 2);
|
||||
|
||||
await database.playerDao.updatePlayerName(
|
||||
playerId: testPlayer1.id,
|
||||
name: 'different name',
|
||||
);
|
||||
|
||||
player = await database.playerDao.getPlayerById(
|
||||
playerId: testPlayer1.id,
|
||||
);
|
||||
expect(player.nameCount, 0);
|
||||
|
||||
player = await database.playerDao.getPlayerById(
|
||||
playerId: testPlayer2.id,
|
||||
);
|
||||
expect(player.nameCount, 0);
|
||||
});
|
||||
|
||||
test('updatePlayerName() sets correct nameCount with 3 player', () async {
|
||||
await database.playerDao.addPlayersAsList(
|
||||
players: [testPlayer1, testPlayer2, testPlayer3],
|
||||
);
|
||||
|
||||
// Changing both names to player 1's name
|
||||
final newName = testPlayer1.name;
|
||||
await database.playerDao.updatePlayerName(
|
||||
playerId: testPlayer2.id,
|
||||
name: newName,
|
||||
);
|
||||
await database.playerDao.updatePlayerName(
|
||||
playerId: testPlayer3.id,
|
||||
name: newName,
|
||||
);
|
||||
|
||||
var player = await database.playerDao.getPlayerById(
|
||||
playerId: testPlayer1.id,
|
||||
);
|
||||
expect(player.nameCount, 1);
|
||||
|
||||
player = await database.playerDao.getPlayerById(
|
||||
playerId: testPlayer2.id,
|
||||
);
|
||||
expect(player.nameCount, 2);
|
||||
|
||||
player = await database.playerDao.getPlayerById(
|
||||
playerId: testPlayer3.id,
|
||||
);
|
||||
expect(player.nameCount, 3);
|
||||
|
||||
// Changing the middle players name
|
||||
await database.playerDao.updatePlayerName(
|
||||
playerId: testPlayer2.id,
|
||||
name: 'different name',
|
||||
);
|
||||
|
||||
player = await database.playerDao.getPlayerById(
|
||||
playerId: testPlayer1.id,
|
||||
);
|
||||
expect(player.nameCount, 1);
|
||||
|
||||
player = await database.playerDao.getPlayerById(
|
||||
playerId: testPlayer2.id,
|
||||
);
|
||||
expect(player.nameCount, 0);
|
||||
|
||||
player = await database.playerDao.getPlayerById(
|
||||
playerId: testPlayer3.id,
|
||||
);
|
||||
expect(player.nameCount, 2);
|
||||
});
|
||||
|
||||
test('updatePlayerDescription() works correctly', () async {
|
||||
await database.playerDao.addPlayer(player: testPlayer1);
|
||||
|
||||
@@ -461,22 +372,14 @@ void main() {
|
||||
final player1 = Player(name: testPlayer1.name, description: '');
|
||||
await database.playerDao.addPlayer(player: player1);
|
||||
|
||||
final player2 = Player(name: testPlayer1.name, description: '');
|
||||
await database.playerDao.addPlayer(player: player2);
|
||||
|
||||
var players = await database.playerDao.getAllPlayers();
|
||||
|
||||
expect(players.length, 3);
|
||||
expect(players.length, 2);
|
||||
players.sort((a, b) => a.nameCount.compareTo(b.nameCount));
|
||||
|
||||
for (int i = 0; i < players.length - 1; i++) {
|
||||
expect(players[i].nameCount, i + 1);
|
||||
}
|
||||
|
||||
// ids are correct in the right order
|
||||
expect(players[0].id, testPlayer1.id);
|
||||
expect(players[1].id, player1.id);
|
||||
expect(players[2].id, player2.id);
|
||||
},
|
||||
);
|
||||
|
||||
@@ -501,62 +404,24 @@ void main() {
|
||||
for (int i = 0; i < players.length - 1; i++) {
|
||||
expect(players[i].nameCount, i + 1);
|
||||
}
|
||||
|
||||
// ids are correct in the right order
|
||||
expect(players[0].id, testPlayer1.id);
|
||||
expect(players[1].id, player1.id);
|
||||
expect(players[2].id, player2.id);
|
||||
expect(players[3].id, player3.id);
|
||||
},
|
||||
);
|
||||
|
||||
test('getNameCount works correctly', () async {
|
||||
final player1 = Player(name: testPlayer1.name);
|
||||
test('getNameCount works correctly', () async {
|
||||
final player2 = Player(name: testPlayer1.name);
|
||||
final player3 = Player(name: testPlayer1.name);
|
||||
|
||||
await database.playerDao.addPlayer(player: testPlayer1);
|
||||
|
||||
var nameCount = await database.playerDao.getNameCount(
|
||||
name: testPlayer1.name,
|
||||
await database.playerDao.addPlayersAsList(
|
||||
players: [testPlayer1, player2, player3],
|
||||
);
|
||||
|
||||
expect(nameCount, 1);
|
||||
|
||||
await database.playerDao.addPlayersAsList(players: [player1, player2]);
|
||||
|
||||
nameCount = await database.playerDao.getNameCount(
|
||||
final nameCount = await database.playerDao.getNameCount(
|
||||
name: testPlayer1.name,
|
||||
);
|
||||
|
||||
expect(nameCount, 3);
|
||||
});
|
||||
|
||||
test('calculateNameCount works correctly', () async {
|
||||
final player1 = Player(name: testPlayer1.name);
|
||||
final player2 = Player(name: testPlayer1.name);
|
||||
|
||||
// Case 1: No existing players with the name
|
||||
var nameCount = await database.playerDao.calculateNameCount(
|
||||
name: testPlayer1.name,
|
||||
);
|
||||
expect(nameCount, 0);
|
||||
|
||||
// Case 2: One existing player with the name. Should return 2 for
|
||||
// the new player
|
||||
await database.playerDao.addPlayer(player: testPlayer1);
|
||||
nameCount = await database.playerDao.calculateNameCount(
|
||||
name: testPlayer1.name,
|
||||
);
|
||||
expect(nameCount, 2);
|
||||
|
||||
// Case 3: Multiple existing players with the name. Should return count + 1
|
||||
await database.playerDao.addPlayersAsList(players: [player1, player2]);
|
||||
nameCount = await database.playerDao.calculateNameCount(
|
||||
name: testPlayer1.name,
|
||||
);
|
||||
expect(nameCount, 4);
|
||||
});
|
||||
|
||||
test('updateNameCount works correctly', () async {
|
||||
await database.playerDao.addPlayer(player: testPlayer1);
|
||||
|
||||
@@ -576,24 +441,14 @@ void main() {
|
||||
final player2 = Player(name: testPlayer1.name, description: '');
|
||||
final player3 = Player(name: testPlayer1.name, description: '');
|
||||
|
||||
await database.playerDao.addPlayer(player: testPlayer1);
|
||||
var player = await database.playerDao.getPlayerWithHighestNameCount(
|
||||
name: testPlayer1.name,
|
||||
await database.playerDao.addPlayersAsList(
|
||||
players: [testPlayer1, player2, player3],
|
||||
);
|
||||
expect(player, isNotNull);
|
||||
expect(player!.nameCount, 0);
|
||||
|
||||
await database.playerDao.addPlayer(player: player2);
|
||||
player = await database.playerDao.getPlayerWithHighestNameCount(
|
||||
final player = await database.playerDao.getPlayerWithHighestNameCount(
|
||||
name: testPlayer1.name,
|
||||
);
|
||||
expect(player, isNotNull);
|
||||
expect(player!.nameCount, 2);
|
||||
|
||||
await database.playerDao.addPlayer(player: player3);
|
||||
player = await database.playerDao.getPlayerWithHighestNameCount(
|
||||
name: testPlayer1.name,
|
||||
);
|
||||
expect(player, isNotNull);
|
||||
expect(player!.nameCount, 3);
|
||||
});
|
||||
@@ -605,6 +460,32 @@ void main() {
|
||||
expect(player, isNull);
|
||||
});
|
||||
|
||||
test('calculateNameCount works correctly', () async {
|
||||
// Case 1: No existing players with the name
|
||||
var count = await database.playerDao.calculateNameCount(
|
||||
name: testPlayer1.name,
|
||||
);
|
||||
expect(count, 0);
|
||||
|
||||
// Case 2: One existing player with the name. Should update that
|
||||
// player's nameCount to 1 and return 2 for the new player
|
||||
await database.playerDao.addPlayer(player: testPlayer1);
|
||||
|
||||
count = await database.playerDao.calculateNameCount(
|
||||
name: testPlayer1.name,
|
||||
);
|
||||
expect(count, 2);
|
||||
|
||||
// Case 3: Multiple existing players with the name.
|
||||
final player2 = Player(name: testPlayer1.name, nameCount: count);
|
||||
await database.playerDao.addPlayer(player: player2);
|
||||
|
||||
count = await database.playerDao.calculateNameCount(
|
||||
name: testPlayer1.name,
|
||||
);
|
||||
expect(count, 3);
|
||||
});
|
||||
|
||||
test('getPlayerWithHighestNameCount with non existing player', () async {
|
||||
await database.playerDao.addPlayer(player: testPlayer1);
|
||||
await database.playerDao.initializeNameCount(name: testPlayer1.name);
|
||||
|
||||
@@ -42,7 +42,7 @@ void main() {
|
||||
name: 'Test Game',
|
||||
ruleset: Ruleset.singleWinner,
|
||||
description: 'A test game',
|
||||
color: AppColor.blue,
|
||||
color: GameColor.blue,
|
||||
icon: '',
|
||||
);
|
||||
testMatch1 = Match(
|
||||
|
||||
@@ -1,122 +0,0 @@
|
||||
import 'dart:core';
|
||||
|
||||
import 'package:clock/clock.dart';
|
||||
import 'package:drift/drift.dart' hide isNotNull;
|
||||
import 'package:drift/native.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:tallee/core/enums.dart';
|
||||
import 'package:tallee/data/db/database.dart';
|
||||
import 'package:tallee/data/models/game.dart';
|
||||
import 'package:tallee/data/models/group.dart';
|
||||
import 'package:tallee/data/models/player.dart';
|
||||
import 'package:tallee/data/models/statistic.dart';
|
||||
|
||||
void main() {
|
||||
late AppDatabase database;
|
||||
late Player testPlayer1;
|
||||
late Player testPlayer2;
|
||||
late Player testPlayer3;
|
||||
late Player testPlayer4;
|
||||
late Player testPlayer5;
|
||||
late Group testGroup1;
|
||||
late Group testGroup2;
|
||||
late Game testGame;
|
||||
/*late Match testMatch1;
|
||||
late Match testMatch2;
|
||||
late Match testMatchOnlyPlayers;
|
||||
late Match testMatchOnlyGroup;*/
|
||||
final fixedDate = DateTime(2025, 19, 11, 00, 11, 23);
|
||||
final fakeClock = Clock(() => fixedDate);
|
||||
|
||||
setUp(() async {
|
||||
database = AppDatabase(
|
||||
DatabaseConnection(
|
||||
NativeDatabase.memory(),
|
||||
// Recommended for widget tests to avoid test errors.
|
||||
closeStreamsSynchronously: true,
|
||||
),
|
||||
);
|
||||
|
||||
withClock(fakeClock, () {
|
||||
testPlayer1 = Player(name: 'Alice');
|
||||
testPlayer2 = Player(name: 'Bob');
|
||||
testPlayer3 = Player(name: 'Charlie');
|
||||
testPlayer4 = Player(name: 'Diana');
|
||||
testPlayer5 = Player(name: 'Eve');
|
||||
testGroup1 = Group(
|
||||
name: 'Test Group 1',
|
||||
description: '',
|
||||
members: [testPlayer1, testPlayer2, testPlayer3],
|
||||
);
|
||||
testGroup2 = Group(
|
||||
name: 'Test Group 2',
|
||||
description: '',
|
||||
members: [testPlayer4, testPlayer5],
|
||||
);
|
||||
testGame = Game(
|
||||
name: 'Test Game',
|
||||
ruleset: Ruleset.singleWinner,
|
||||
description: 'A test game',
|
||||
color: AppColor.blue,
|
||||
icon: '',
|
||||
);
|
||||
/*testMatch1 = Match(
|
||||
name: 'First Test Match',
|
||||
game: testGame,
|
||||
group: testGroup1,
|
||||
players: [testPlayer4, testPlayer5],
|
||||
scores: {testPlayer4.id: ScoreEntry(score: 1)},
|
||||
);
|
||||
testMatch2 = Match(
|
||||
name: 'Second Test Match',
|
||||
game: testGame,
|
||||
group: testGroup2,
|
||||
players: [testPlayer1, testPlayer2, testPlayer3],
|
||||
);
|
||||
testMatchOnlyPlayers = Match(
|
||||
name: 'Test Match with Players',
|
||||
game: testGame,
|
||||
players: [testPlayer1, testPlayer2, testPlayer3],
|
||||
);
|
||||
testMatchOnlyGroup = Match(
|
||||
name: 'Test Match with Group',
|
||||
game: testGame,
|
||||
group: testGroup2,
|
||||
players: testGroup2.members,
|
||||
);*/
|
||||
});
|
||||
await database.playerDao.addPlayersAsList(
|
||||
players: [
|
||||
testPlayer1,
|
||||
testPlayer2,
|
||||
testPlayer3,
|
||||
testPlayer4,
|
||||
testPlayer5,
|
||||
],
|
||||
);
|
||||
await database.groupDao.addGroupsAsList(groups: [testGroup1, testGroup2]);
|
||||
await database.gameDao.addGame(game: testGame);
|
||||
});
|
||||
tearDown(() async {
|
||||
await database.close();
|
||||
});
|
||||
|
||||
test('Adding/fetching statistic works correclty', () async {
|
||||
final statistic = Statistic(
|
||||
type: StatisticType.averageScore,
|
||||
scopes: [StatisticScope.allPlayers, StatisticScope.selectedGames],
|
||||
timeframe: Timeframe.allTime,
|
||||
selectedGames: [testGame],
|
||||
selectedGroups: [testGroup1],
|
||||
);
|
||||
|
||||
final added = await database.statisticDao.addStatistic(
|
||||
statistic: statistic,
|
||||
);
|
||||
expect(added, isTrue);
|
||||
|
||||
final fetched = await database.statisticDao.getStatisticById(statistic.id);
|
||||
expect(fetched, isNotNull);
|
||||
expect(fetched!.type, statistic.type);
|
||||
});
|
||||
}
|
||||
@@ -40,7 +40,7 @@ void main() {
|
||||
name: 'Test Game',
|
||||
ruleset: Ruleset.singleWinner,
|
||||
description: 'A test game',
|
||||
color: AppColor.blue,
|
||||
color: GameColor.blue,
|
||||
icon: '',
|
||||
);
|
||||
testMatch1 = Match(
|
||||
|
||||
@@ -45,7 +45,7 @@ void main() {
|
||||
name: 'Chess',
|
||||
ruleset: Ruleset.singleWinner,
|
||||
description: 'Strategic board game',
|
||||
color: AppColor.blue,
|
||||
color: GameColor.blue,
|
||||
icon: 'chess_icon',
|
||||
);
|
||||
|
||||
@@ -448,19 +448,19 @@ void main() {
|
||||
Game(
|
||||
name: 'Red Game',
|
||||
ruleset: Ruleset.singleWinner,
|
||||
color: AppColor.red,
|
||||
color: GameColor.red,
|
||||
icon: 'icon',
|
||||
),
|
||||
Game(
|
||||
name: 'Blue Game',
|
||||
ruleset: Ruleset.singleWinner,
|
||||
color: AppColor.blue,
|
||||
color: GameColor.blue,
|
||||
icon: 'icon',
|
||||
),
|
||||
Game(
|
||||
name: 'Green Game',
|
||||
ruleset: Ruleset.singleWinner,
|
||||
color: AppColor.green,
|
||||
color: GameColor.green,
|
||||
icon: 'icon',
|
||||
),
|
||||
];
|
||||
@@ -484,19 +484,19 @@ void main() {
|
||||
Game(
|
||||
name: 'Highest Score Game',
|
||||
ruleset: Ruleset.highestScore,
|
||||
color: AppColor.blue,
|
||||
color: GameColor.blue,
|
||||
icon: 'icon',
|
||||
),
|
||||
Game(
|
||||
name: 'Lowest Score Game',
|
||||
ruleset: Ruleset.lowestScore,
|
||||
color: AppColor.blue,
|
||||
color: GameColor.blue,
|
||||
icon: 'icon',
|
||||
),
|
||||
Game(
|
||||
name: 'Single Winner',
|
||||
ruleset: Ruleset.singleWinner,
|
||||
color: AppColor.blue,
|
||||
color: GameColor.blue,
|
||||
icon: 'icon',
|
||||
),
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user