Add search from page tests.

This commit is contained in:
Mattia 2020-12-26 16:01:20 +01:00
parent 8372726a65
commit a9275af1e2
3 changed files with 25 additions and 6 deletions

View File

@ -143,7 +143,7 @@ class YoutubeHttpClient extends http.BaseClient {
request.headers[key] = _defaultHeaders[key];
}
});
// print('Request: $request');
// print('Request: $request');
// print('Stack:\n${StackTrace.current}');
return _httpClient.send(request);
}

View File

@ -1,4 +1,4 @@
///
/// This i can either be a [SearchVideo] or [SearchPlaylist]
abstract class BaseSearchContent {
///
const BaseSearchContent();

View File

@ -17,7 +17,26 @@ void main() {
expect(videos, isNotEmpty);
});
test('Search a youtube videos from the search page', () async {
test('Search a youtube video from the search page', () async {
var videos = await yt.search
.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;
expect(video.videoId, isNotNull);
expect(video.videoTitle, isNotEmpty);
expect(video.videoAuthor, isNotEmpty);
expect(video.videoDescriptionSnippet, isNotEmpty);
expect(video.videoDuration, isNotEmpty);
expect(video.videoViewCount, greaterThan(0));
expect(video.videoThumbnails, isNotEmpty);
});
test('Search a youtube videos from the search page - old', () async {
// ignore: deprecated_member_use_from_same_package
var searchQuery = await yt.search.queryFromPage('hello');
expect(searchQuery.content, isNotEmpty);
@ -25,7 +44,7 @@ void main() {
expect(searchQuery.relatedQueries, isNotEmpty);
}, skip: 'Not supported anymore');
test('Search with no results', () async {
test('Search with no results - old', () async {
var query =
// ignore: deprecated_member_use_from_same_package
await yt.search.queryFromPage('g;jghEOGHJeguEPOUIhjegoUEHGOGHPSASG');
@ -36,7 +55,7 @@ void main() {
expect(nextPage, isNull);
});
test('Search youtube videos have thumbnails', () async {
test('Search youtube videos have thumbnails - old', () async {
// ignore: deprecated_member_use_from_same_package
var searchQuery = await yt.search.queryFromPage('hello');
expect(searchQuery.content.first, isA<SearchVideo>());
@ -45,7 +64,7 @@ void main() {
expect(video.videoThumbnails, isNotEmpty);
});
test('Search youtube videos from search page (stream)', () async {
test('Search youtube videos from search page (stream) - old', () async {
var query = await yt.search.getVideosFromPage('hello').take(30).toList();
expect(query, hasLength(30));
});