Initial commit
This commit is contained in:
52
test/services/m3u_service_test.dart
Normal file
52
test/services/m3u_service_test.dart
Normal file
@@ -0,0 +1,52 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mocktail/mocktail.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:yommi_ff/services/m3u_service.dart';
|
||||
import 'package:yommi_ff/models/stream_entry.dart';
|
||||
|
||||
class _MockClient extends Mock implements http.Client {}
|
||||
|
||||
void main() {
|
||||
group('M3UService', () {
|
||||
test('parses simple m3u content', () {
|
||||
final content = '''#EXTM3U
|
||||
#EXTINF:-1,Channel One
|
||||
http://example.com/stream1.m3u8
|
||||
#EXTINF:-1,Second Channel
|
||||
http://example.com/stream2.m3u8
|
||||
''';
|
||||
final svc = M3UService(client: http.Client());
|
||||
final entries = svc.parse(content);
|
||||
expect(entries, [
|
||||
StreamEntry(
|
||||
title: 'Channel One', url: 'http://example.com/stream1.m3u8'),
|
||||
StreamEntry(
|
||||
title: 'Second Channel', url: 'http://example.com/stream2.m3u8'),
|
||||
]);
|
||||
});
|
||||
|
||||
test('fetches and caches', () async {
|
||||
final mock = _MockClient();
|
||||
final url = 'http://mock/m3u';
|
||||
final body = '#EXTM3U\n#EXTINF:-1,Mock\nhttp://mock/stream\n';
|
||||
when(() => mock.get(Uri.parse(url)))
|
||||
.thenAnswer((_) async => http.Response(body, 200));
|
||||
|
||||
final svc = M3UService(client: mock);
|
||||
final first = await svc.fetch(url);
|
||||
expect(first.length, 1);
|
||||
// second fetch should use cache — we verify by changing mock to throw if called again
|
||||
when(() => mock.get(Uri.parse(url)))
|
||||
.thenThrow(Exception('should not be called'));
|
||||
final second = await svc.fetch(url);
|
||||
expect(second.length, 1);
|
||||
});
|
||||
|
||||
test('throws on empty', () {
|
||||
final svc = M3UService();
|
||||
expect(() => svc.parse(''), throwsA(isA<M3uParseException>()));
|
||||
});
|
||||
});
|
||||
}
|
||||
23
test/widget_test.dart
Normal file
23
test/widget_test.dart
Normal file
@@ -0,0 +1,23 @@
|
||||
// This is a basic Flutter widget test.
|
||||
//
|
||||
// To perform an interaction with a widget in your test, use the WidgetTester
|
||||
// utility in the flutter_test package. For example, you can send tap and scroll
|
||||
// gestures. You can also use WidgetTester to find child widgets in the widget
|
||||
// tree, read text, and verify that the values of widget properties are correct.
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import 'package:yommi_ff/main.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
|
||||
// Build our app and trigger a frame.
|
||||
await tester.pumpWidget(ProviderScope(child: const MyApp()));
|
||||
|
||||
// Verify HomeScreen has main controls (M3U URL input)
|
||||
expect(find.text('M3U URL'), findsOneWidget);
|
||||
expect(find.byType(TextField), findsOneWidget);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user