import 'package:dio/dio.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:ignis_app/models/ignis_group.dart'; import 'package:ignis_app/widgets/group_card.dart'; import 'test_support.dart'; void main() { TestWidgetsFlutterBinding.ensureInitialized(); testWidgets('group card toggles power and creates 4 hour timer', ( tester, ) async { final api = FakeIgnisApi(tasksData: {'tasks': []}); await pumpTestApp( tester, api: api, child: Scaffold( body: GroupCard( group: const IgnisGroup( id: 'hall', name: 'Hall', state: IgnisGroupState(isOn: true, brightness: 50), ), ), ), ); await tester.tap(find.byIcon(Icons.timer)); await tester.pumpAndSettle(); expect(api.controlledGroupId, 'hall'); expect(api.controlGroupParams, containsPair('state', true)); expect(api.scheduledOnceParams, containsPair('target_id', 'hall')); expect(api.scheduledOnceParams, containsPair('hours_from_now', 4)); await tester.tap(find.byType(Switch)); await tester.pumpAndSettle(); expect(api.controlGroupParams, containsPair('state', false)); }); testWidgets('group card loads scenes and applies selected scene', ( tester, ) async { final api = FakeIgnisApi(scenesData: {'party': 'Party'}); await pumpTestApp( tester, api: api, child: Scaffold( body: GroupCard( group: const IgnisGroup( id: 'hall', name: 'Hall', state: IgnisGroupState(isOn: true), ), ), ), ); await tester.tap(find.text('Сцена')); await tester.pump(); await tester.pump(const Duration(milliseconds: 100)); expect(find.text('Party'), findsOneWidget); await tester.tap(find.text('Party')); await tester.pumpAndSettle(); expect(api.controlledGroupId, 'hall'); expect(api.controlGroupParams, containsPair('scene', 'party')); }); testWidgets('group card shows retry when scenes fail to load', ( tester, ) async { final api = FakeIgnisApi(scenesData: {'party': 'Party'}); api.scenesError = DioException( requestOptions: RequestOptions(path: '/devices/scenes'), type: DioExceptionType.connectionError, message: 'No route to host', ); await pumpTestApp( tester, api: api, child: Scaffold( body: GroupCard( group: const IgnisGroup( id: 'hall', name: 'Hall', state: IgnisGroupState(isOn: true), ), ), ), ); await tester.tap(find.text('Сцена')); await tester.pump(); await tester.pump(const Duration(milliseconds: 100)); expect(find.text('Не удалось загрузить сцены'), findsOneWidget); api.scenesError = null; await tester.tap(find.text('Повторить')); await tester.pumpAndSettle(); expect(find.text('Party'), findsOneWidget); }); }