44 lines
1.4 KiB
Dart
44 lines
1.4 KiB
Dart
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 = [
|
|
Habit(id: 1,
|
|
title: 'Habit 1',
|
|
subtitle: 'Description 1',
|
|
iconCodePoint: Icons.star.codePoint,
|
|
iconFontFamily: Icons.star.fontFamily ?? 'MaterialIcons',
|
|
isComplete: false),
|
|
Habit(id: 2,
|
|
title: 'Habit 2',
|
|
subtitle: 'Description 2',
|
|
iconCodePoint: Icons.star_border.codePoint,
|
|
iconFontFamily: Icons.star_border.fontFamily ?? 'MaterialIcons',
|
|
isComplete: true),
|
|
Habit(id: 3,
|
|
title: 'Habit 3',
|
|
subtitle: 'Description 3',
|
|
iconCodePoint: Icons.favorite.codePoint,
|
|
iconFontFamily: Icons.favorite.fontFamily ?? 'MaterialIcons',
|
|
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);
|
|
});
|
|
});
|
|
}
|