41 lines
1.2 KiB
Dart
41 lines
1.2 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();
|
||
|
final habits = [
|
||
|
Habit(id: 1,
|
||
|
title: 'Habit 1',
|
||
|
subtitle: 'Description 1',
|
||
|
icon: Icons.star,
|
||
|
isComplete: false),
|
||
|
Habit(id: 2,
|
||
|
title: 'Habit 2',
|
||
|
subtitle: 'Description 2',
|
||
|
icon: Icons.star_border,
|
||
|
isComplete: true),
|
||
|
Habit(id: 3,
|
||
|
title: 'Habit 3',
|
||
|
subtitle: 'Description 3',
|
||
|
icon: Icons.favorite,
|
||
|
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);
|
||
|
});
|
||
|
});
|
||
|
}
|