79 lines
2.8 KiB
Dart
79 lines
2.8 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:smilet/Aktivitet/NewActivity.dart';
|
|
import 'package:smilet/User.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
void main() {
|
|
late NewActivity newActivity;
|
|
|
|
setUp(() {
|
|
final user = User(id: 1997, username: 'mimmsan', password: 'Smilet2024!', schoolCode: 'a3RoLWluZGVr', );
|
|
newActivity = NewActivity(user: user);
|
|
|
|
});
|
|
|
|
group('NewActivity validation tests', () {
|
|
|
|
test('Validates that the activity name is not empty', () {
|
|
final titleController = TextEditingController();
|
|
|
|
titleController.text = '';
|
|
final isValid = (titleController.text != '') ? null : 'Skriv in ett namn på aktiviteten';
|
|
expect(isValid, 'Skriv in ett namn på aktiviteten');
|
|
|
|
titleController.text = 'Valid Name';
|
|
final isValid2 = (titleController.text != '') ? null : 'Skriv in ett namn på aktiviteten';
|
|
expect(isValid2, null);
|
|
|
|
});
|
|
|
|
test('Validates that the activity place is not empty', () {
|
|
final placeController = TextEditingController();
|
|
placeController.text = '';
|
|
|
|
final isValid = (placeController.text != '') ? null : 'Skriv in en plats';
|
|
expect(isValid, 'Skriv in en plats');
|
|
|
|
placeController.text = 'Valid Place';
|
|
final isValid2 = (placeController.text != '') ? null : 'Skriv in en plats';
|
|
expect(isValid2, null);
|
|
});
|
|
|
|
test('Validates that the activity time is in the correct format', () {
|
|
final timeController = TextEditingController();
|
|
timeController.text = '25:61';
|
|
|
|
final timeRegExp = RegExp(r'^(?:[01]\d|2[0-3]):[0-5]\d$');
|
|
final isValid = (timeController.text != '' && timeRegExp.hasMatch(timeController.text))
|
|
? null
|
|
: 'Skriv in en tid i formatet "HH:MM"';
|
|
expect(isValid, 'Skriv in en tid i formatet "HH:MM"');
|
|
|
|
timeController.text = '12:34';
|
|
final isValid2 = (timeController.text != '' && timeRegExp.hasMatch(timeController.text))
|
|
? null
|
|
: 'Skriv in en tid i formatet "HH:MM"';
|
|
expect(isValid2, null);
|
|
});
|
|
|
|
test('Validates that the activity date is in the correct format', () {
|
|
final dateController = TextEditingController();
|
|
dateController.text = '32/13';
|
|
|
|
final dateRegExp = RegExp(r'^(0[1-9]|[12][0-9]|3[01])/(0[1-9]|1[0-2])$');
|
|
final isValid = (dateController.text != '' && dateRegExp.hasMatch(dateController.text))
|
|
? null
|
|
: 'Skriv in ett datum i formatet "DD/MM"';
|
|
expect(isValid, 'Skriv in ett datum i formatet "DD/MM"');
|
|
|
|
dateController.text = '12/12';
|
|
final isValid2 = (dateController.text != '' && dateRegExp.hasMatch(dateController.text))
|
|
? null
|
|
: 'Skriv in ett datum i formatet "DD/MM"';
|
|
expect(isValid2, null);
|
|
});
|
|
|
|
});
|
|
}
|