crearPartida clears the notes, which goes through SharedPreferences, and ServicioNearby.dispose called notifyListeners after tearing the notifier down. Both failed on plugin channels that do not exist in the test host. Suite goes from 25 passing / 8 failing to a green run.
67 lines
1.8 KiB
Dart
67 lines
1.8 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:farolero/modelos/usuario.dart';
|
|
import 'package:farolero/servicios/servicio_nearby.dart';
|
|
|
|
void main() {
|
|
TestWidgetsFlutterBinding.ensureInitialized();
|
|
|
|
group('ServicioNearby user pool', () {
|
|
late ServicioNearby servicio;
|
|
|
|
setUp(() {
|
|
servicio = ServicioNearby();
|
|
});
|
|
|
|
|
|
test('should start with empty user pool', () {
|
|
expect(servicio.usuarios, isEmpty);
|
|
});
|
|
|
|
test('should add user to pool', () {
|
|
final usuario = Usuario(id: 'user-1', nombre: 'Juan');
|
|
servicio.agregarUsuario(usuario);
|
|
|
|
expect(servicio.usuarios.length, 1);
|
|
expect(servicio.usuarios.first.nombre, 'Juan');
|
|
});
|
|
|
|
test('should remove user from pool', () {
|
|
final usuario = Usuario(id: 'user-1', nombre: 'Juan');
|
|
servicio.agregarUsuario(usuario);
|
|
expect(servicio.usuarios.length, 1);
|
|
|
|
servicio.eliminarUsuario('user-1');
|
|
expect(servicio.usuarios, isEmpty);
|
|
});
|
|
|
|
test('should synchronize users from list', () {
|
|
final usuarios = [
|
|
Usuario(id: 'user-1', nombre: 'Juan'),
|
|
Usuario(id: 'user-2', nombre: 'Maria'),
|
|
];
|
|
servicio.sincronizarUsuarios(usuarios);
|
|
|
|
expect(servicio.usuarios.length, 2);
|
|
expect(servicio.usuarios.map((u) => u.nombre).toList(), contains('Juan'));
|
|
expect(
|
|
servicio.usuarios.map((u) => u.nombre).toList(),
|
|
contains('Maria'),
|
|
);
|
|
});
|
|
|
|
test('should get usuario by id', () {
|
|
final usuario = Usuario(id: 'user-1', nombre: 'Juan');
|
|
servicio.agregarUsuario(usuario);
|
|
|
|
final found = servicio.getUsuario('user-1');
|
|
expect(found, isNotNull);
|
|
expect(found!.nombre, 'Juan');
|
|
});
|
|
|
|
test('should return null for non-existent user', () {
|
|
final found = servicio.getUsuario('non-existent');
|
|
expect(found, isNull);
|
|
});
|
|
});
|
|
}
|