youtube_explode/test/search_test.dart

59 lines
1.8 KiB
Dart
Raw Normal View History

2020-06-06 11:28:36 +02:00
import 'package:test/test.dart';
import 'package:youtube_explode_dart/youtube_explode_dart.dart';
void main() {
2021-03-11 14:20:10 +01:00
YoutubeExplode? yt;
2020-10-17 22:09:52 +02:00
setUp(() {
yt = YoutubeExplode();
});
2020-06-06 11:28:36 +02:00
2020-10-17 22:09:52 +02:00
tearDown(() {
2021-03-11 14:20:10 +01:00
yt?.close();
2020-10-17 22:09:52 +02:00
});
2020-06-06 11:28:36 +02:00
2021-03-04 12:20:00 +01:00
test('Search a youtube video from the search page', () async {
2021-03-11 14:20:10 +01:00
var videos = await yt!.search.getVideos('undead corporation megalomania');
2020-10-17 22:09:52 +02:00
expect(videos, isNotEmpty);
});
2020-06-16 21:49:30 +02:00
2021-03-04 12:20:00 +01:00
test('Search a youtube video from the search page-2', () async {
2021-03-11 14:20:10 +01:00
var videos = await yt!.search
// ignore: deprecated_member_use_from_same_package
2020-12-26 16:01:20 +01:00
.getVideosFromPage('hello')
.where((e) => e is SearchVideo) // Take only the videos.
.cast<SearchVideo>()
.take(10) // Take on 10 results.
.toList();
expect(videos, hasLength(10));
var video = videos.first;
2021-02-27 18:58:42 +01:00
expect(video.id, isNotNull);
2020-12-26 16:01:20 +01:00
2021-02-27 18:58:42 +01:00
expect(video.title, isNotEmpty);
expect(video.author, isNotEmpty);
expect(video.description, isNotEmpty);
expect(video.duration, isNotEmpty);
expect(video.viewCount, greaterThan(0));
expect(video.thumbnails, isNotEmpty);
2020-12-26 16:01:20 +01:00
});
test('Search with no results - old', () async {
2020-11-01 15:05:19 +01:00
var query =
// ignore: deprecated_member_use_from_same_package
2021-03-11 14:20:10 +01:00
await yt!.search.queryFromPage('g;jghEOGHJeguEPOUIhjegoUEHGOGHPSASG');
2020-10-17 22:09:52 +02:00
expect(query.content, isEmpty);
expect(query.relatedQueries, isEmpty);
expect(query.relatedVideos, isEmpty);
var nextPage = await query.nextPage();
expect(nextPage, isNull);
});
2020-09-21 17:34:03 +02:00
2020-12-26 16:01:20 +01:00
test('Search youtube videos have thumbnails - old', () async {
2020-10-30 22:20:31 +01:00
// ignore: deprecated_member_use_from_same_package
2021-03-11 14:20:10 +01:00
var searchQuery = await yt!.search.queryFromPage('hello');
2020-10-27 14:44:11 +01:00
expect(searchQuery.content.first, isA<SearchVideo>());
2020-09-23 08:38:05 +02:00
2020-10-27 14:44:11 +01:00
var video = searchQuery.content.first as SearchVideo;
2021-02-27 18:58:42 +01:00
expect(video.thumbnails, isNotEmpty);
2020-10-27 14:44:11 +01:00
});
2020-06-06 11:28:36 +02:00
}