|
| 1 | +import 'package:flutter/material.dart'; |
| 2 | +import 'package:flutter_test/flutter_test.dart'; |
| 3 | +import 'package:fluttermvvmtemplate/view/_product/_model/query/friend_query.dart'; |
| 4 | +import 'package:mockito/mockito.dart'; |
| 5 | +import 'package:vexana/vexana.dart'; |
| 6 | + |
| 7 | +import 'feed_mockito.dart'; |
| 8 | +import 'social_network_mock.dart'; |
| 9 | + |
| 10 | +void main() { |
| 11 | + BuildContext context; |
| 12 | + SocialNetworkMock mockService; |
| 13 | + INetworkManager networkManager; |
| 14 | + SocialMockViewModel socialMockViewModel; |
| 15 | + |
| 16 | + setUp(() { |
| 17 | + context = SocialBuildContext(); |
| 18 | + networkManager = NetworkManager(options: BaseOptions()); |
| 19 | + |
| 20 | + mockService = SocialNetworkMock(networkManager, null); |
| 21 | + socialMockViewModel = SocialMockViewModel(mockService); |
| 22 | + }); |
| 23 | + |
| 24 | + test('Context Test', () async { |
| 25 | + verify(socialMockViewModel.setContext(context)); |
| 26 | + }); |
| 27 | + |
| 28 | + test('Loading Test 2 ', () async { |
| 29 | + socialMockViewModel.fetchAllUserLoading(1); |
| 30 | + expect(socialMockViewModel.isPageLoading, true); |
| 31 | + await Future.delayed(Duration(seconds: 1)); |
| 32 | + expect(socialMockViewModel.isPageLoading, false); |
| 33 | + }); |
| 34 | + |
| 35 | + test('User All Loading', () async { |
| 36 | + socialMockViewModel.isPageLoadingLazyLoad = false; |
| 37 | + socialMockViewModel.socialUserList = []; |
| 38 | + socialMockViewModel.isLazyLoadDataFinish = false; |
| 39 | + |
| 40 | + await socialMockViewModel.fetchAllUserLoading(-1); |
| 41 | + expect(socialMockViewModel.socialUserList.isNotEmpty, true); |
| 42 | + expect(socialMockViewModel.page > 0, true); |
| 43 | + expect(socialMockViewModel.isPageLoading, false); |
| 44 | + }); |
| 45 | + |
| 46 | + test('List check', () async { |
| 47 | + socialMockViewModel.setContext(context); |
| 48 | + |
| 49 | + await socialMockViewModel.fetchAllUserLoading(1); |
| 50 | + // when(socialMockViewModel.fetchAllUserLoading(0)).thenReturn(Future.value()); |
| 51 | + |
| 52 | + expect(socialMockViewModel.socialUserList.length, 1); |
| 53 | + }); |
| 54 | + test('Loading Test', () async { |
| 55 | + await socialMockViewModel.fetchAllUserLoading(0); |
| 56 | + verifyNever(socialMockViewModel.isPageLoading); |
| 57 | + // verify(socialMockViewModel.isPageLoading).called(2); |
| 58 | + }); |
| 59 | + test('Fetch User Id', () async { |
| 60 | + final response = await mockService.fetchUser(10); |
| 61 | + expect(response, isNotNull); |
| 62 | + }); |
| 63 | + |
| 64 | + test('Fetch House Id', () async { |
| 65 | + final response = await mockService.fetchUserHouseList(FriendQuery()); |
| 66 | + expect(response, isNotEmpty); |
| 67 | + }); |
| 68 | + |
| 69 | + test('Fetch User Name Query', () async { |
| 70 | + final response = await mockService.fetchUserNameQuery('hello'); |
| 71 | + expect(response, isNotEmpty); |
| 72 | + }); |
| 73 | +} |
0 commit comments