Files
ignis_app/test/group_form_logic_test.dart
2026-05-01 09:47:08 +07:00

38 lines
1.3 KiB
Dart
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import 'package:flutter_test/flutter_test.dart';
import 'package:ignis_app/features/groups/group_form_logic.dart';
import 'package:ignis_app/models/ignis_group.dart';
void main() {
test('slugify transliterates russian names into stable ids', () {
expect(slugifyGroupId('Спальня родителей'), 'spalnya-roditeley');
expect(slugifyGroupId(' Kitchen + Hall '), 'kitchen-hall');
});
test('group id validation rejects duplicates and invalid chars', () {
const existing = [IgnisGroup(id: 'bedroom', name: 'Спальня')];
expect(validateGroupId('', existing), 'Укажите ID группы');
expect(
validateGroupId('спальня', existing),
'Только латиница, цифры, "-" и "_"',
);
expect(
validateGroupId('bedroom', existing),
'Группа с таким ID уже существует',
);
expect(validateGroupId('hall_way', existing), isNull);
});
test('membership conflicts are detected by device ids', () {
const groups = [
IgnisGroup(id: 'bedroom', name: 'Спальня', macs: ['AA:BB', 'CC:DD']),
IgnisGroup(id: 'kitchen', name: 'Кухня', macs: ['EE:FF']),
];
final conflicts = findGroupMembershipConflicts({'EE:FF', '11:22'}, groups);
expect(conflicts, hasLength(1));
expect(conflicts.single.id, 'kitchen');
});
}