2024-05-30 19:43:56 +02:00
|
|
|
import 'package:cpd/pages/homepage.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
import 'package:cpd/database/habit.dart';
|
|
|
|
|
|
|
|
void main() {
|
|
|
|
group('MyHomePageState', () {
|
|
|
|
test('progressValue is calculated correctly', () {
|
|
|
|
// Arrange
|
|
|
|
final myHomePageState = MyHomePageState();
|
2024-06-09 17:45:17 +02:00
|
|
|
List<Habit> habits = [
|
2024-05-30 19:43:56 +02:00
|
|
|
Habit(id: 1,
|
|
|
|
title: 'Habit 1',
|
|
|
|
subtitle: 'Description 1',
|
2024-06-09 17:45:17 +02:00
|
|
|
iconCodePoint: Icons.star.codePoint,
|
|
|
|
iconFontFamily: Icons.star.fontFamily ?? 'MaterialIcons',
|
2024-05-30 19:43:56 +02:00
|
|
|
isComplete: false),
|
|
|
|
Habit(id: 2,
|
|
|
|
title: 'Habit 2',
|
|
|
|
subtitle: 'Description 2',
|
2024-06-09 17:45:17 +02:00
|
|
|
iconCodePoint: Icons.star_border.codePoint,
|
|
|
|
iconFontFamily: Icons.star_border.fontFamily ?? 'MaterialIcons',
|
2024-05-30 19:43:56 +02:00
|
|
|
isComplete: true),
|
|
|
|
Habit(id: 3,
|
|
|
|
title: 'Habit 3',
|
|
|
|
subtitle: 'Description 3',
|
2024-06-09 17:45:17 +02:00
|
|
|
iconCodePoint: Icons.favorite.codePoint,
|
|
|
|
iconFontFamily: Icons.favorite.fontFamily ?? 'MaterialIcons',
|
2024-05-30 19:43:56 +02:00
|
|
|
isComplete: true),
|
|
|
|
];
|
|
|
|
|
|
|
|
// Act
|
|
|
|
final habitCount = myHomePageState.countHabits(habits);
|
|
|
|
final completedCount = habits.where((habit) => habit.isComplete).length;
|
|
|
|
final progressValue = completedCount / habitCount;
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
expect(habitCount, 3);
|
|
|
|
expect(completedCount, 2);
|
|
|
|
expect(progressValue, 2 / 3);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|