Skip to content

Commit

Permalink
Add:Tests for misses
Browse files Browse the repository at this point in the history
  • Loading branch information
AyushRaghuvanshi committed Nov 19, 2023
1 parent b48e73d commit 9695c90
Showing 1 changed file with 58 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:graphql_flutter/graphql_flutter.dart';
import 'package:mockito/mockito.dart';
import 'package:talawa/enums/enums.dart';
import 'package:talawa/services/graphql_config.dart';
import 'package:talawa/services/size_config.dart';
import 'package:talawa/view_model/after_auth_view_models/profile_view_models/profile_page_view_model.dart';
Expand Down Expand Up @@ -58,10 +60,15 @@ void main() {
model.initialize();

model.showSnackBar("fake_message");
verify(navigationService.showSnackBar("fake_message"));
verify(
navigationService.showTalawaErrorDialog(
"fake_message",
MessageType.error,
),
).called(1);

model.popBottomSheet();
verify(navigationService.pop());
verify(navigationService.pop()).called(1);
});

test("Test updateSheetHeight function", () {
Expand All @@ -87,43 +94,59 @@ void main() {
expect((iconButton as IconButton).icon, testIcon);
});

testWidgets("Test dominationButton function", (tester) async {
final mockContext = MockBuildContext();
final model = ProfilePageViewModel();
model.initialize();
const String amt = "test_amt";
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: model.dominationButton(
amt,
mockContext,
(void Function() callback) {},
),
),
),
);
final containerFinder = find.byType(Container);
final Container container = tester.firstWidget(containerFinder);
expect(
container.padding,
EdgeInsets.symmetric(
vertical: SizeConfig.screenHeight! * 0.02,
horizontal: SizeConfig.screenWidth! * 0.075,
testWidgets('Test logout function', (WidgetTester tester) async {
final mockDatabaseFunctions = databaseFunctions;

when(mockDatabaseFunctions.gqlAuthMutation(queries.logout())).thenAnswer(
(_) async => QueryResult(
data: {'logout': true},
source: QueryResultSource.network,
options: QueryOptions(document: gql(queries.logout())),
),
);
});

testWidgets("Test logout function", (tester) async {
final mockContext = MockBuildContext();
final model = ProfilePageViewModel();
final mocknav = getAndRegisterNavigationService();
model.initialize();
await model.logout(mockContext);
await tester.pumpAndSettle();
final ProfilePageViewModel viewModel = ProfilePageViewModel();

//Ensures that naviagation service was called
verifyInteraction(mocknav, mockName: "NavigationService");
await viewModel.logout(MockBuildContext());
});
});

testWidgets("Test dominationButton function", (tester) async {
final mockContext = MockBuildContext();
final model = ProfilePageViewModel();
model.initialize();
const String amt = "test_amt";
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: model.dominationButton(
amt,
mockContext,
(void Function() callback) {},
),
),
),
);
final containerFinder = find.byType(Container);
final Container container = tester.firstWidget(containerFinder);
expect(
container.padding,
EdgeInsets.symmetric(
vertical: SizeConfig.screenHeight! * 0.02,
horizontal: SizeConfig.screenWidth! * 0.075,
),
);
});

// testWidgets("Test logout function", (tester) async {
// final mockContext = MockBuildContext();
// final model = ProfilePageViewModel();
// final mocknav = getAndRegisterNavigationService();
// model.initialize();
// await model.logout(mockContext);
// await tester.pumpAndSettle();

// //Ensures that naviagation service was called
// verifyInteraction(mocknav, mockName: "NavigationService");
// });
}

0 comments on commit 9695c90

Please sign in to comment.