This repository has been archived by the owner on Jun 9, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 261
/
view_model_test.dart
63 lines (57 loc) · 2.18 KB
/
view_model_test.dart
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
import 'package:app/data/model/result.dart';
import 'package:app/data/remote/app_dio.dart';
import 'package:app/data/remote/news_data_source.dart';
import 'package:app/data/repository/news_repository_impl.dart';
import 'package:app/foundation/constants.dart';
import 'package:app/ui/news/news_view_model.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:mocktail/mocktail.dart';
import '../data/dummy/dummy_news.dart';
import '../data/remote/fake_app_dio.dart';
import '../data/remote/fake_news_data_source_impl.dart';
import '../data/repository/fake_news_repository_impl.dart';
class MockNewsRepositoryImpl extends Mock implements NewsRepositoryImpl {}
void main() {
test('HomeViewModel Test', () async {
final container = ProviderContainer(
overrides: [
newsRepositoryProvider.overrideWithValue(FakeNewsRepositoryImpl())
],
);
final viewModel = container.read(newsViewModelProvider);
await expectLater(
viewModel.fetchNews(), completion(Result.success(data: dummyNews)));
});
test('NewsRepository Test', () async {
final container = ProviderContainer(
overrides: [
newsDataSourceProvider.overrideWithValue(FakeNewsDataSourceImpl())
],
);
final newsRepository = container.read(newsRepositoryProvider);
await expectLater(
newsRepository.getNews(), completion(Result.success(data: dummyNews)));
});
test('NewsDataSource Test', () async {
final container = ProviderContainer(
overrides: [dioProvider.overrideWithValue(FakeAppDio())],
);
final dataSource = container.read(newsDataSourceProvider);
await expectLater(
dataSource.getNews(
apiKey: 'apikey',
from: 'from',
query: 'query',
),
completion(isNotNull));
});
test('AppDio options Test', () async {
final realDio = AppDio.getInstance();
expect(realDio.options.baseUrl, Constants.of().endpoint);
expect(realDio.options.contentType, 'application/json');
expect(realDio.options.connectTimeout, 30000);
expect(realDio.options.sendTimeout, 30000);
expect(realDio.options.receiveTimeout, 30000);
});
}