forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwaveform_section_test.dart
More file actions
84 lines (73 loc) · 2.72 KB
/
Copy pathwaveform_section_test.dart
File metadata and controls
84 lines (73 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:provider/provider.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:omi/l10n/app_localizations.dart';
import 'package:omi/models/playback_state.dart';
import 'package:omi/providers/sync_provider.dart';
import 'package:omi/services/services.dart';
import 'package:omi/widgets/waveform_section.dart';
// Mock SyncProvider for testing
class MockSyncProvider extends SyncProvider {
@override
Duration get totalDuration => const Duration(seconds: 60);
}
const _testPlaybackState = PlaybackState(
isPlaying: false,
isProcessing: false,
canPlayOrShare: true,
isSynced: true,
hasError: false,
currentPosition: Duration.zero,
totalDuration: Duration(seconds: 60),
playbackProgress: 0.0,
);
void main() {
setUpAll(() async {
TestWidgetsFlutterBinding.ensureInitialized();
SharedPreferences.setMockInitialValues({});
try {
await ServiceManager.init();
} catch (_) {
// Ignore if already initialized
}
});
group('WaveformSection timer cadence', () {
testWidgets('timer updates at 250ms intervals for reduced CPU usage', (tester) async {
// Build the widget with required providers
await tester.pumpWidget(
MaterialApp(
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
home: ChangeNotifierProvider<SyncProvider>(
create: (_) => MockSyncProvider(),
child: const Scaffold(
body: SizedBox(
height: 200,
child: WaveformSection(
seconds: 60,
waveformData: [0.5, 0.6, 0.7, 0.8],
isProcessingWaveform: false,
playbackState: _testPlaybackState,
isPlaying: true,
),
),
),
),
),
);
// Wait for initial build
await tester.pumpAndSettle();
// The widget should be created successfully with 250ms timer
expect(find.byType(WaveformSection), findsOneWidget);
// Advance by 100ms - should not trigger update yet (was 100ms before optimization)
await tester.pump(const Duration(milliseconds: 100));
// Advance by another 150ms to reach 250ms total - should trigger update now
await tester.pump(const Duration(milliseconds: 150));
// Widget should still be present and functional
expect(find.byType(WaveformSection), findsOneWidget);
// Unmount widget tree to cancel the 250ms periodic timer in WaveformSection.dispose()
await tester.pumpWidget(const SizedBox.shrink());
});
});
}