GardenPlanner/test/logic/plant.service_test.dart

106 lines
4.2 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:garden_planner/constance.dart';
import 'package:garden_planner/entities/plant.dart';
import 'package:garden_planner/logic/plant.service.dart';
import '../helpers/plant_generator.dart';
void main() {
test('PlantService isActionNeeded should work', () {
// Arrange
final PlantService plantService = PlantService();
final Plant plant = PlantGenerator.getPlant();
// Act
var actionShouldBeTrue =
plantService.isActionNeeded(plant, DateTime(2023, 05, 01));
var actionShouldBeFalseBecauseNoEntry =
plantService.isActionNeeded(plant, DateTime(2023, 07, 01));
var actionShouldBeFalse =
plantService.isActionNeeded(plant, DateTime(2023, 10, 01));
// Assert
expect(actionShouldBeTrue, equals(true),
reason: 'PlantService isActionNeeded ist between but returns false');
expect(actionShouldBeFalse, equals(false),
reason: 'PlantService isActionNeeded ist outside set but returns true');
expect(actionShouldBeFalseBecauseNoEntry, equals(false),
reason: 'PlantService isActionNeeded ist not set but returns true');
});
test('PlantService getTimeDescription should work', () {
// Arrange
final PlantService plantService = PlantService();
final Plant plant = PlantGenerator.getPlant();
// Act
var descritpionJanuar =
plantService.getTimeDescription(plant, DateTime(2023, 01, 01));
var descritpionApril =
plantService.getTimeDescription(plant, DateTime(2023, 04, 02));
var descritpionMai =
plantService.getTimeDescription(plant, DateTime(2023, 05, 20));
var descritpionJuni =
plantService.getTimeDescription(plant, DateTime(2023, 06, 20));
// Assert
expect(descritpionJanuar, equals(Constance.defaultDescription),
reason: 'Description is not equal');
expect(descritpionMai, equals('Wachstumsphase'),
reason: 'Description is not equal');
expect(descritpionApril, equals('Aussaat'),
reason: 'Description is not equal');
expect(descritpionJuni, equals('Erntezeit'),
reason: 'Description is not equal');
});
test('PlantService getTimeDescription extremValues should work', () {
// Arrange
final PlantService plantService = PlantService();
final Plant plant = PlantGenerator.getPlant();
// Act
var descritpionBevorWachstum =
plantService.getTimeDescription(plant, DateTime(2023, 05, 15));
var descritpionWachstumstart =
plantService.getTimeDescription(plant, DateTime(2023, 05, 16));
var descritpionWachstumEnd =
plantService.getTimeDescription(plant, DateTime(2023, 06, 15));
var descritpionAfterWachstum =
plantService.getTimeDescription(plant, DateTime(2023, 06, 16));
// Assert
expect(descritpionBevorWachstum, isNot(equals('Wachstumsphase')),
reason: 'Description returns wrong value bevor');
expect(descritpionWachstumstart, equals('Wachstumsphase'),
reason: 'Description returns wrong value start');
expect(descritpionWachstumEnd, equals('Wachstumsphase'),
reason: 'Description returns wrong value end');
expect(descritpionAfterWachstum, isNot(equals('Wachstumsphase')),
reason: 'Description returns wrong value after');
});
test('PlantService getColor should work', () {
// Arrange
final PlantService plantService = PlantService();
final Plant plant = PlantGenerator.getPlant();
// Act
var descritpionJanuar =
plantService.getColor(plant, DateTime(2023, 01, 01));
var descritpionApril = plantService.getColor(plant, DateTime(2023, 04, 02));
var descritpionMai = plantService.getColor(plant, DateTime(2023, 05, 20));
var descritpionJuni = plantService.getColor(plant, DateTime(2023, 06, 20));
// Assert
expect(descritpionJanuar, equals(Constance.defaultColor),
reason: 'Color is not equal');
expect(descritpionMai, equals(Colors.purple),
reason: 'Description is not equal');
expect(descritpionApril, equals(Colors.yellow),
reason: 'Description is not equal');
expect(descritpionJuni, equals(Colors.red),
reason: 'Description is not equal');
});
}