cpd/test/unit_testing/progressvalue_test.dart

44 lines
1.4 KiB
Dart
Raw Normal View History

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();
List<Habit> habits = [
2024-05-30 19:43:56 +02:00
Habit(id: 1,
title: 'Habit 1',
subtitle: 'Description 1',
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',
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',
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);
});
});
}