-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #104 from pektinasen/62_recent_sort_order
bug: fix sort order in recent meals
- Loading branch information
Showing
3 changed files
with
101 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import 'package:opennutritracker/features/add_meal/domain/entity/meal_entity.dart'; | ||
import 'package:opennutritracker/features/add_meal/domain/entity/meal_nutriments_entity.dart'; | ||
|
||
class MealEntityFixtures { | ||
static final mealOne = MealEntity( | ||
code: "1", | ||
name: null, | ||
url: null, | ||
mealQuantity: null, | ||
mealUnit: 'g', | ||
servingQuantity: null, | ||
servingUnit: 'g', | ||
nutriments: MealNutrimentsEntity.empty(), | ||
source: MealSourceEntity.custom); | ||
static final mealTwo = MealEntity( | ||
code: "2", | ||
name: null, | ||
url: null, | ||
mealQuantity: null, | ||
mealUnit: 'g', | ||
servingQuantity: null, | ||
servingUnit: 'g', | ||
nutriments: MealNutrimentsEntity.empty(), | ||
source: MealSourceEntity.custom); | ||
static final mealThree = MealEntity( | ||
code: "3", | ||
name: null, | ||
url: null, | ||
mealQuantity: null, | ||
mealUnit: 'g', | ||
servingQuantity: null, | ||
servingUnit: 'g', | ||
nutriments: MealNutrimentsEntity.empty(), | ||
source: MealSourceEntity.custom); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:hive/hive.dart'; | ||
import 'package:opennutritracker/core/data/data_source/intake_data_source.dart'; | ||
import 'package:opennutritracker/core/data/dbo/intake_dbo.dart'; | ||
import 'package:opennutritracker/core/data/dbo/intake_type_dbo.dart'; | ||
import 'package:opennutritracker/core/data/dbo/meal_dbo.dart'; | ||
import 'package:opennutritracker/core/data/dbo/meal_nutriments_dbo.dart'; | ||
import 'package:opennutritracker/core/data/repository/intake_repository.dart'; | ||
import 'package:opennutritracker/core/domain/entity/intake_entity.dart'; | ||
import 'package:opennutritracker/core/domain/entity/intake_type_entity.dart'; | ||
|
||
import '../fixture/meal_entity_fixtures.dart'; | ||
|
||
void main() { | ||
|
||
group('IntakeRepository test', () { | ||
setUp(() { | ||
TestWidgetsFlutterBinding.ensureInitialized(); | ||
// final temp = await getTemporaryDirectory(); | ||
Hive.init("."); | ||
Hive.registerAdapter(IntakeDBOAdapter()); | ||
Hive.registerAdapter(IntakeTypeDBOAdapter()); | ||
Hive.registerAdapter(MealDBOAdapter()); | ||
Hive.registerAdapter(MealSourceDBOAdapter()); | ||
Hive.registerAdapter(MealNutrimentsDBOAdapter()); | ||
}); | ||
|
||
tearDown(() { | ||
Hive.deleteFromDisk(); | ||
}); | ||
|
||
test('returns last added first', () async { | ||
final box = await Hive.openBox<IntakeDBO>('intake_test'); | ||
|
||
final repo = IntakeRepository(IntakeDataSource(box)); | ||
|
||
|
||
await repo.addIntake(IntakeEntity( | ||
id: "1", | ||
unit: "g", | ||
amount: 1, | ||
type: IntakeTypeEntity.breakfast, | ||
meal: MealEntityFixtures.mealOne, | ||
dateTime: DateTime.utc(2024, 1, 1, 0, 0, 0))); | ||
await repo.addIntake(IntakeEntity( | ||
id: "2", | ||
unit: "g", | ||
amount: 1, | ||
type: IntakeTypeEntity.breakfast, | ||
meal: MealEntityFixtures.mealTwo, | ||
dateTime: DateTime.utc(2024, 1, 2, 0, 0, 0))); | ||
await repo.addIntake(IntakeEntity( | ||
id: "3", | ||
unit: "g", | ||
amount: 1, | ||
type: IntakeTypeEntity.breakfast, | ||
meal: MealEntityFixtures.mealThree, | ||
dateTime: DateTime.utc(2024, 1, 3, 0, 0, 0))); | ||
|
||
final recents = (await repo.getRecentIntake()).map((e) => e.id).toList(); | ||
expect(recents, List.from(["3", "2", "1"])); | ||
}); | ||
}); | ||
} |