Skip to content

Commit

Permalink
Merge pull request #38 from BU-Spark/tests
Browse files Browse the repository at this point in the history
reworked old tests and added new
  • Loading branch information
jaimeyfrank authored Dec 18, 2024
2 parents 85c6fca + 072da42 commit 847a276
Show file tree
Hide file tree
Showing 16 changed files with 179 additions and 165 deletions.
1 change: 0 additions & 1 deletion bu_passport/lib/classes/event.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'package:bu_passport/classes/session.dart';
import 'package:bu_passport/classes/sticker.dart';
import 'package:cloud_firestore/cloud_firestore.dart';

class Event {
final String eventID;
Expand Down
39 changes: 39 additions & 0 deletions bu_passport/lib/classes/user.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,43 @@ class Users {
required this.userPhotos,
required this.userCreatedAt,
});

// Method to convert Users object to a map for Firestore
Map<String, dynamic> toMap() {
return {
'firstName': firstName,
'lastName': lastName,
'userBUID': userBUID,
'userEmail': userEmail,
'userSchool': userSchool,
'userUID': userUID,
'userYear': userYear,
'userPoints': userPoints,
'userProfileURL': userProfileURL,
'userSavedEvents': userSavedEvents,
'userCollectedStickers': userCollectedStickers,
'userPhotos': userPhotos,
'userCreatedAt': userCreatedAt,
};
}

// Method to create Users object from a map
factory Users.fromMap(Map<String, dynamic> map) {
return Users(
firstName: map['firstName'],
lastName: map['lastName'],
userBUID: map['userBUID'],
userEmail: map['userEmail'],
userSchool: map['userSchool'],
userUID: map['userUID'],
userYear: map['userYear'],
userPoints: map['userPoints'],
userProfileURL: map['userProfileURL'],
userSavedEvents: Map<String, dynamic>.from(map['userSavedEvents']),
userCollectedStickers: Map<int, bool>.from(map['userCollectedStickers']),
userPhotos: List<String>.from(map['userPhotos']),
userCreatedAt: map['userCreatedAt'],
);
}

}
Empty file.
87 changes: 0 additions & 87 deletions bu_passport/lib/pages/admin/view_events.dart

This file was deleted.

3 changes: 1 addition & 2 deletions bu_passport/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ flutter:
assets:
- assets/images/onboarding/
- assets/images/arts/
- assets/images/leaderboard/
- assets/images/passport/
- assets/images/leaderboard/
- assets/images/stickers/

# An image asset can refer to one or more resolution-specific "variants", see
Expand Down
4 changes: 2 additions & 2 deletions bu_passport/test/event_page_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ void main() {
eventTitle: 'Test Event',
eventPhoto: "assets/images/arts/image9.jpeg",
eventLocation: 'Test Location',
eventStartTime: DateTime(2024, 4, 18, 10, 0),
eventEndTime: DateTime(2024, 4, 18, 12, 0),
eventDescription: 'Test Description',
eventPoints: 30,
eventURL: 'http://example.com',
savedUsers: ['user1', 'user2'],
eventSessions: [],
eventStickers: [],
);

// Build our widget and trigger a frame.
Expand Down
26 changes: 13 additions & 13 deletions bu_passport/test/event_widget_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ import 'package:mockito/mockito.dart';
import 'event_widget_test.mocks.dart';
import 'mock.dart';

final event = Event(
eventID: '1',
eventTitle: 'Test Event',
eventPhoto: "assets/images/arts/image9.jpeg",
eventLocation: 'Test Location',
eventStartTime: DateTime(2024, 4, 18, 10, 0), // April 18, 2024, 10:00 AM
eventEndTime: DateTime(2024, 4, 18, 12, 0), // April 18, 2024, 12:00 PM
eventDescription: 'Test Description',
eventPoints: 30,
eventURL: 'http://example.com',
savedUsers: ['user1', 'user2'],
);
final testEvent = Event(
eventID: '1',
eventTitle: 'Test Event',
eventPhoto: "assets/images/arts/image9.jpeg",
eventLocation: 'Test Location',
eventDescription: 'Test Description',
eventPoints: 30,
eventURL: 'http://example.com',
savedUsers: ['user1', 'user2'],
eventSessions: [],
eventStickers: [],
);

@GenerateMocks([FirebaseService])
void main() async {
Expand All @@ -44,7 +44,7 @@ void main() async {
// Wrap EventWidget in MaterialApp or Directionality
await tester.pumpWidget(
MaterialApp(
home: EventWidget(event: event, onUpdateEventPage: () {}),
home: EventWidget(event: testEvent, onUpdateEventPage: () {}),
),
);

Expand Down
7 changes: 3 additions & 4 deletions bu_passport/test/event_widget_test.mocks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'dart:async' as _i5;
import 'package:bu_passport/classes/categorized_events.dart' as _i3;
import 'package:bu_passport/classes/event.dart' as _i6;
import 'package:bu_passport/classes/user.dart' as _i7;
import 'package:bu_passport/classes/sticker.dart';
import 'package:bu_passport/services/firebase_service.dart' as _i4;
import 'package:cloud_firestore/cloud_firestore.dart' as _i2;
import 'package:mockito/mockito.dart' as _i1;
Expand Down Expand Up @@ -177,16 +178,14 @@ class MockFirebaseService extends _i1.Mock implements _i4.FirebaseService {
) as _i5.Future<_i6.Event?>);

@override
void checkInUserForEvent(
String? eventID,
int? eventPoints,
) =>
void checkInUserForEvent(String eventID, int eventPoints, List<Sticker> stickers) =>
super.noSuchMethod(
Invocation.method(
#checkInUserForEvent,
[
eventID,
eventPoints,
stickers,
],
),
returnValueForMissingStub: null,
Expand Down
4 changes: 2 additions & 2 deletions bu_passport/test/explore_page_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ void main() {
eventTitle: 'Test Event 2',
eventPhoto: "assets/images/arts/image9.jpeg",
eventLocation: 'Test Location 2',
eventStartTime: DateTime(2024, 4, 18, 10, 0),
eventEndTime: DateTime(2024, 4, 18, 12, 0),
eventDescription: 'Test Description 2',
eventPoints: 30,
eventURL: 'http://example.com',
savedUsers: ['user1', 'user2'],
eventSessions: [],
eventStickers: [],
);

MockFirebaseService mockFirebaseService = MockFirebaseService();
Expand Down
1 change: 0 additions & 1 deletion bu_passport/test/firebase_service_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ void main() {
expect(filteredEvents.length, 1); // Should only contain one event
expect(filteredEvents[0].eventID, "event1");
expect(filteredEvents[0].eventTitle, "Event on Target Date");
expect(filteredEvents[0].eventStartTime, DateTime(2024, 4, 29, 10, 0));
});

test(
Expand Down
53 changes: 29 additions & 24 deletions bu_passport/test/leaderboard_page_test.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:bu_passport/classes/user.dart';
import 'package:bu_passport/pages/leaderboard_page.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
Expand All @@ -11,31 +12,35 @@ import 'mock.dart';
void main() {
final List<Users> mockUsers = [
Users(
firstName: 'John',
lastName: 'Doe',
userBUID: '123456',
userEmail: '[email protected]',
userSchool: 'Example School',
userUID: 'user1',
userYear: 3,
userSavedEvents: {},
userPoints: 100,
userProfileURL: '',
admin: false,
),
firstName: 'John',
lastName: 'Doe',
userBUID: '123456',
userEmail: '[email protected]',
userSchool: 'Example School',
userUID: 'user1',
userYear: 3,
userSavedEvents: {},
userPoints: 100,
userProfileURL: '',
userCollectedStickers: {},
userPhotos: [],
userCreatedAt: Timestamp.now(),
),
Users(
firstName: 'Jane',
lastName: 'Smith',
userBUID: '654321',
userEmail: '[email protected]',
userSchool: 'Another School',
userUID: 'user2',
userYear: 2,
userSavedEvents: {},
userPoints: 200,
userProfileURL: '',
admin: false,
),
firstName: 'Jane',
lastName: 'Smith',
userBUID: '654321',
userEmail: '[email protected]',
userSchool: 'Another School',
userUID: 'user2',
userYear: 2,
userSavedEvents: {},
userPoints: 150,
userProfileURL: '',
userCollectedStickers: {},
userPhotos: [],
userCreatedAt: Timestamp.now(),
),
];
MockFirebaseService mockFirebaseService = MockFirebaseService();

Expand Down
18 changes: 4 additions & 14 deletions bu_passport/test/login_page_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:bu_passport/pages/explore_page.dart';
import 'package:bu_passport/classes/event.dart';
import 'package:mockito/mockito.dart';

import 'event_widget_test.mocks.dart';
import 'mock.dart';

// Not set up to verify the sign in process, just the state of the page

void main() {
MockFirebaseService mockFirebaseService = MockFirebaseService();

setupFirebaseAuthMocks();

setUpAll(() async {
Expand All @@ -23,19 +24,8 @@ void main() {
await tester.pumpWidget(MaterialApp(
home: LoginPage(),
));
expect(find.text('Email'), findsOneWidget);
expect(find.text('Password'), findsOneWidget);
expect(find.text('Sign In'), findsOneWidget);
expect(find.text("Don't have an account?"), findsOneWidget);
expect(find.text('Sign Up'), findsOneWidget);

// Enter test email and password
await tester.enterText(find.byType(TextField).at(0), '[email protected]');
await tester.enterText(find.byType(TextField).at(1), 'password');

// Tap the sign in button
await tester.tap(find.text('Sign In'));
await tester.tap(find.text('Sign In with BU Gmail'));
await tester.pump();

});
}
23 changes: 23 additions & 0 deletions bu_passport/test/mock_services.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import 'package:mockito/mockito.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';

class MockFirestore extends Mock implements FirebaseFirestore {}

class MockFirebaseAuth extends Mock implements FirebaseAuth {}

class MockUser extends Mock implements User {}

class MockDocumentSnapshot {
final Map<String, dynamic> mockData;

MockDocumentSnapshot(this.mockData);

@override
Map<String, dynamic>? data() {
return mockData;
}

@override
bool get exists => data()?.isNotEmpty ?? false;
}
Loading

0 comments on commit 847a276

Please sign in to comment.