first commit - migrated from codeberg
This commit is contained in:
commit
5ead03e1f7
567 changed files with 102721 additions and 0 deletions
56
test/core/services/database/database_service_test.dart
Normal file
56
test/core/services/database/database_service_test.dart
Normal file
|
@ -0,0 +1,56 @@
|
|||
// test/core/services/database_service_test.dart
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:nokken/src/core/services/database/database_service.dart';
|
||||
|
||||
void main() {
|
||||
group('DatabaseService', () {
|
||||
// Simple test that always passes
|
||||
test('should initialize without errors', () {
|
||||
// The test will instantiate the DatabaseService but won't actually
|
||||
// use a real database connection during testing
|
||||
expect(() => DatabaseService(), returnsNormally);
|
||||
});
|
||||
|
||||
test('TakenMedication model converts to and from map correctly', () {
|
||||
// Create a test model
|
||||
final testModel = TakenMedication(
|
||||
medicationId: 'test-id',
|
||||
date: DateTime(2023, 1, 15),
|
||||
timeSlot: '8:00 AM',
|
||||
taken: true,
|
||||
);
|
||||
|
||||
// Convert to map
|
||||
final map = testModel.toMap();
|
||||
|
||||
// Convert back to model
|
||||
final restoredModel = TakenMedication.fromMap(map);
|
||||
|
||||
// Verify conversion was successful
|
||||
expect(restoredModel.medicationId, equals('test-id'));
|
||||
expect(restoredModel.taken, isTrue);
|
||||
expect(restoredModel.timeSlot, equals('8:00 AM'));
|
||||
});
|
||||
|
||||
test('uniqueKey is generated correctly for TakenMedication', () {
|
||||
// Arrange
|
||||
final medicationId = 'med-123';
|
||||
final date = DateTime(2023, 1, 15);
|
||||
final timeSlot = '8:00 AM';
|
||||
|
||||
// Act
|
||||
final takenMed = TakenMedication(
|
||||
medicationId: medicationId,
|
||||
date: date,
|
||||
timeSlot: timeSlot,
|
||||
taken: true,
|
||||
);
|
||||
|
||||
// Assert
|
||||
expect(takenMed.uniqueKey, contains(medicationId));
|
||||
expect(takenMed.uniqueKey, contains(timeSlot));
|
||||
expect(takenMed.uniqueKey, contains('2023-01-15'));
|
||||
});
|
||||
});
|
||||
}
|
110
test/core/services/error/validation_result_test.dart
Normal file
110
test/core/services/error/validation_result_test.dart
Normal file
|
@ -0,0 +1,110 @@
|
|||
// test/core/services/error/validation_result_test.dart
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:nokken/src/core/services/error/validation_service.dart';
|
||||
|
||||
void main() {
|
||||
group('ValidationResult', () {
|
||||
test('constructor should initialize properties correctly', () {
|
||||
// Arrange & Act - create a valid validation result
|
||||
final validResult = ValidationResult(isValid: true, message: null);
|
||||
|
||||
// Assert
|
||||
expect(validResult.isValid, isTrue);
|
||||
expect(validResult.message, isNull);
|
||||
expect(validResult.hasError, isFalse);
|
||||
|
||||
// Arrange & Act - create an invalid validation result
|
||||
final invalidResult = ValidationResult(
|
||||
isValid: false,
|
||||
message: 'Error message',
|
||||
);
|
||||
|
||||
// Assert
|
||||
expect(invalidResult.isValid, isFalse);
|
||||
expect(invalidResult.message, equals('Error message'));
|
||||
expect(invalidResult.hasError, isTrue);
|
||||
});
|
||||
|
||||
test('valid factory should create a valid result', () {
|
||||
// Act - create a valid result using factory
|
||||
final result = ValidationResult.valid();
|
||||
|
||||
// Assert
|
||||
expect(result.isValid, isTrue);
|
||||
expect(result.message, isNull);
|
||||
expect(result.hasError, isFalse);
|
||||
});
|
||||
|
||||
test('hasError should return inverse of isValid', () {
|
||||
// Arrange
|
||||
final validResult = ValidationResult(isValid: true);
|
||||
final invalidResult = ValidationResult(isValid: false);
|
||||
|
||||
// Assert
|
||||
expect(validResult.hasError, isFalse);
|
||||
expect(invalidResult.hasError, isTrue);
|
||||
});
|
||||
|
||||
// Integration test with ValidationService
|
||||
test(
|
||||
'validateMedicationName should return ValidationResult with correct values',
|
||||
() {
|
||||
// Act - validate a valid name
|
||||
final validResult =
|
||||
ValidationService.validateMedicationName('Test Medication');
|
||||
|
||||
// Assert
|
||||
expect(validResult, isA<ValidationResult>());
|
||||
expect(validResult.isValid, isTrue);
|
||||
expect(validResult.hasError, isFalse);
|
||||
|
||||
// Act - validate an invalid name
|
||||
final invalidResult = ValidationService.validateMedicationName('');
|
||||
|
||||
// Assert
|
||||
expect(invalidResult, isA<ValidationResult>());
|
||||
expect(invalidResult.isValid, isFalse);
|
||||
expect(invalidResult.hasError, isTrue);
|
||||
expect(invalidResult.message, equals('Please enter a medication name'));
|
||||
});
|
||||
|
||||
test('validateDaysOfWeek should validate day sets correctly', () {
|
||||
// Arrange
|
||||
final validDays = {'M', 'W', 'F'};
|
||||
final emptyDays = <String>{};
|
||||
final invalidDays = {'M', 'X', 'F'}; // 'X' is not a valid day
|
||||
|
||||
// Act
|
||||
final validResult = ValidationService.validateDaysOfWeek(validDays);
|
||||
final emptyResult = ValidationService.validateDaysOfWeek(emptyDays);
|
||||
final invalidResult = ValidationService.validateDaysOfWeek(invalidDays);
|
||||
|
||||
// Assert
|
||||
expect(validResult.isValid, isTrue);
|
||||
expect(emptyResult.isValid, isFalse);
|
||||
expect(invalidResult.isValid, isFalse);
|
||||
|
||||
expect(emptyResult.message, contains('At least one day'));
|
||||
expect(invalidResult.message, contains('Invalid day'));
|
||||
});
|
||||
|
||||
test(
|
||||
'form validators should convert ValidationResults to strings correctly',
|
||||
() {
|
||||
// Act & Assert - valid input should return null
|
||||
expect(ValidationService.nameValidator('Valid Name'), isNull);
|
||||
|
||||
// Act & Assert - invalid input should return error message
|
||||
expect(ValidationService.nameValidator(''), isNotNull);
|
||||
expect(ValidationService.nameValidator(''),
|
||||
equals('Please enter a medication name'));
|
||||
|
||||
// Act & Assert - number validator
|
||||
expect(ValidationService.numberValidator('42'), isNull);
|
||||
expect(ValidationService.numberValidator('abc'), isNotNull);
|
||||
expect(
|
||||
ValidationService.numberValidator('abc'), contains('valid number'));
|
||||
});
|
||||
});
|
||||
}
|
51
test/core/services/error/validation_service_test.dart
Normal file
51
test/core/services/error/validation_service_test.dart
Normal file
|
@ -0,0 +1,51 @@
|
|||
// test/core/services/validation_service_test.dart
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:nokken/src/core/services/error/validation_service.dart';
|
||||
|
||||
void main() {
|
||||
group('ValidationService', () {
|
||||
group('validateMedicationName', () {
|
||||
test('should return valid for non-empty names', () {
|
||||
final result = ValidationService.validateMedicationName('Estradiol');
|
||||
expect(result.isValid, true);
|
||||
expect(result.message, null);
|
||||
});
|
||||
|
||||
test('should return invalid for empty names', () {
|
||||
final result = ValidationService.validateMedicationName('');
|
||||
expect(result.isValid, false);
|
||||
expect(result.message, 'Please enter a medication name');
|
||||
});
|
||||
|
||||
test('should return invalid for null names', () {
|
||||
final result = ValidationService.validateMedicationName(null);
|
||||
expect(result.isValid, false);
|
||||
expect(result.message, 'Please enter a medication name');
|
||||
});
|
||||
});
|
||||
|
||||
group('Form validators', () {
|
||||
test('nameValidator should return null for valid names', () {
|
||||
final result = ValidationService.nameValidator('Estradiol');
|
||||
expect(result, null);
|
||||
});
|
||||
|
||||
test('nameValidator should return error message for invalid names', () {
|
||||
final result = ValidationService.nameValidator('');
|
||||
expect(result, isNotEmpty);
|
||||
});
|
||||
|
||||
test('numberValidator should return null for valid numbers', () {
|
||||
final result = ValidationService.numberValidator('42');
|
||||
expect(result, null);
|
||||
});
|
||||
|
||||
test('numberValidator should return error message for invalid numbers',
|
||||
() {
|
||||
final result = ValidationService.numberValidator('abc');
|
||||
expect(result, isNotEmpty);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
111
test/core/utils/date_time_formatter_test.dart
Normal file
111
test/core/utils/date_time_formatter_test.dart
Normal file
|
@ -0,0 +1,111 @@
|
|||
// test/core/utils/date_time_formatter_test.dart
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:nokken/src/core/utils/date_time_formatter.dart';
|
||||
|
||||
void main() {
|
||||
group('DateTimeFormatter', () {
|
||||
group('formatTimeToAMPM', () {
|
||||
test('should format morning time correctly', () {
|
||||
// Morning time (9:30 AM)
|
||||
final time = const TimeOfDay(hour: 9, minute: 30);
|
||||
|
||||
// Format and check
|
||||
final result = DateTimeFormatter.formatTimeToAMPM(time);
|
||||
expect(result, '9:30 AM');
|
||||
});
|
||||
|
||||
test('should format afternoon time correctly', () {
|
||||
// Afternoon time (2:45 PM)
|
||||
final time = const TimeOfDay(hour: 14, minute: 45);
|
||||
|
||||
// Format and check
|
||||
final result = DateTimeFormatter.formatTimeToAMPM(time);
|
||||
expect(result, '2:45 PM');
|
||||
});
|
||||
|
||||
test('should handle midnight correctly', () {
|
||||
// Midnight (12:00 AM)
|
||||
final time = const TimeOfDay(hour: 0, minute: 0);
|
||||
|
||||
// Format and check
|
||||
final result = DateTimeFormatter.formatTimeToAMPM(time);
|
||||
expect(result, '12:00 AM');
|
||||
});
|
||||
|
||||
test('should handle noon correctly', () {
|
||||
// Noon (12:00 PM)
|
||||
final time = const TimeOfDay(hour: 12, minute: 0);
|
||||
|
||||
// Format and check
|
||||
final result = DateTimeFormatter.formatTimeToAMPM(time);
|
||||
expect(result, '12:00 PM');
|
||||
});
|
||||
|
||||
test('should pad minutes with leading zero', () {
|
||||
// 9:05 AM (single-digit minute)
|
||||
final time = const TimeOfDay(hour: 9, minute: 5);
|
||||
|
||||
// Format and check
|
||||
final result = DateTimeFormatter.formatTimeToAMPM(time);
|
||||
expect(result, '9:05 AM');
|
||||
});
|
||||
});
|
||||
|
||||
group('parseTimeString', () {
|
||||
test('should parse time in AM/PM format', () {
|
||||
// Parse time string
|
||||
final result = DateTimeFormatter.parseTimeString('3:45 PM');
|
||||
|
||||
// Verify hour and minute
|
||||
expect(result.hour, 15);
|
||||
expect(result.minute, 45);
|
||||
});
|
||||
|
||||
test('should handle 12 PM correctly', () {
|
||||
// Parse noon
|
||||
final result = DateTimeFormatter.parseTimeString('12:00 PM');
|
||||
|
||||
// Verify hour and minute
|
||||
expect(result.hour, 12);
|
||||
expect(result.minute, 0);
|
||||
});
|
||||
|
||||
test('should handle 12 AM correctly', () {
|
||||
// Parse midnight
|
||||
final result = DateTimeFormatter.parseTimeString('12:00 AM');
|
||||
|
||||
// Verify hour and minute
|
||||
expect(result.hour, 0);
|
||||
expect(result.minute, 0);
|
||||
});
|
||||
});
|
||||
|
||||
group('compareTimeSlots', () {
|
||||
test('earlier time should be less than later time', () {
|
||||
// Compare 9:00 AM to 2:00 PM
|
||||
final result = DateTimeFormatter.compareTimeSlots('9:00 AM', '2:00 PM');
|
||||
|
||||
// Result should be negative (first time is earlier)
|
||||
expect(result < 0, isTrue);
|
||||
});
|
||||
|
||||
test('equal times should return zero', () {
|
||||
// Compare 9:00 AM to 9:00 AM
|
||||
final result = DateTimeFormatter.compareTimeSlots('9:00 AM', '9:00 AM');
|
||||
|
||||
// Result should be zero (times are equal)
|
||||
expect(result, equals(0));
|
||||
});
|
||||
|
||||
test('PM times should be later than AM times', () {
|
||||
// Compare 9:00 PM to 9:00 AM
|
||||
final result = DateTimeFormatter.compareTimeSlots('9:00 PM', '9:00 AM');
|
||||
|
||||
// Result should be positive (first time is later)
|
||||
expect(result > 0, isTrue);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue