Files
eatvio_app/test/core/utils/toasts_test.dart
2026-01-26 16:38:15 +03:00

115 lines
3.3 KiB
Dart

import 'package:eatvio_app/core/utils/toasts.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
group('Toast Functions', () {
setUpAll(() {
// Mock Fluttertoast plugin
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(
const MethodChannel('PonnamKarthik/fluttertoast'),
(MethodCall methodCall) async {
return null;
},
);
});
tearDownAll(() {
// Clear mock handlers
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(
const MethodChannel('PonnamKarthik/fluttertoast'),
null,
);
});
test('showInfoToast can be called without errors', () {
// This function shows a toast, which is hard to test directly
// In tests, we mock the plugin to avoid MissingPluginException
showInfoToast('Test info message');
// Test passes if no exception is thrown
});
test('showErrorToast can be called without errors', () {
showErrorToast('Test error message');
});
test('showSuccessToast can be called without errors', () {
showSuccessToast('Test success message');
});
test('showInternetConnectionToast can be called without errors', () {
showInternetConnectionToast();
});
test('showInfoToast accepts different messages', () {
final messages = ['Message 1', 'Message 2', 'Long message with special chars: !@#\$%'];
for (final message in messages) {
showInfoToast(message);
}
});
test('showErrorToast accepts different messages', () {
final messages = ['Error 1', 'Error 2', 'Critical error occurred'];
for (final message in messages) {
showErrorToast(message);
}
});
test('showSuccessToast accepts different messages', () {
final messages = ['Success 1', 'Success 2', 'Operation completed successfully'];
for (final message in messages) {
showSuccessToast(message);
}
});
test('showInfoToast handles empty string', () {
showInfoToast('');
});
test('showErrorToast handles empty string', () {
showErrorToast('');
});
test('showSuccessToast handles empty string', () {
showSuccessToast('');
});
test('showInfoToast handles long messages', () {
showInfoToast('A' * 200);
});
test('showErrorToast handles long messages', () {
showErrorToast('A' * 200);
});
test('showSuccessToast handles long messages', () {
showSuccessToast('A' * 200);
});
test('showInfoToast handles messages with special characters', () {
showInfoToast('Message with special chars: !@#\$%^&*()');
});
test('showErrorToast handles messages with special characters', () {
showErrorToast('Error with special chars: !@#\$%^&*()');
});
test('showSuccessToast handles messages with special characters', () {
showSuccessToast('Success with special chars: !@#\$%^&*()');
});
test('showInternetConnectionToast can be called multiple times', () {
showInternetConnectionToast();
showInternetConnectionToast();
showInternetConnectionToast();
});
});
}