Skip to content

Commit

Permalink
Merge branch 'TestsRevisited' into TestsRevisitedMathias
Browse files Browse the repository at this point in the history
  • Loading branch information
BicaniWolfie authored Dec 4, 2023
2 parents 0214333 + 68b573d commit b272d6d
Show file tree
Hide file tree
Showing 23 changed files with 351 additions and 150 deletions.
15 changes: 7 additions & 8 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void main() {
* Use the "environments.local.json" for running against your local web-api
* For IOS users: change the SERVER_HOST in the environment.local file to "http://localhost:5000"
*/
environment.setFile('assets/environments.dev.json').whenComplete(() {
environment.setFile('assets/environments.local.json').whenComplete(() {
_runApp();
});
}
Expand All @@ -51,9 +51,9 @@ void _runApp() {
lastState = snapshot.data;
//To make sure we only listen to the stream once we take advantage
// of firstTimeLogin bool value
if(firstTimeLogIn== true){
if (firstTimeLogIn == true) {
_api.connectivity.connectivityStream.listen((dynamic event) {
if(event == false){
if (event == false) {
lostConnectionDialog(context);
}
});
Expand All @@ -63,11 +63,10 @@ void _runApp() {
// Show screen dependent on logged in role
switch (_authBloc.loggedInUser.role) {
case Role.Citizen:
return WeekplanSelectorScreen(
DisplayNameModel(
displayName: _authBloc.loggedInUser.displayName,
role: describeEnum(_authBloc.loggedInUser.role),
id: _authBloc.loggedInUser.id));
return WeekplanSelectorScreen(DisplayNameModel(
displayName: _authBloc.loggedInUser.displayName,
role: describeEnum(_authBloc.loggedInUser.role),
id: _authBloc.loggedInUser.id));
default:
return ChooseCitizenScreen();
}
Expand Down
16 changes: 8 additions & 8 deletions lib/widgets/pictogram_text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,14 @@ class PictogramText extends StatelessWidget {
/// accounted for
double textWidth(String text, BuildContext context) {
return (TextPainter(
text: TextSpan(
text: text,
style:
const TextStyle(fontWeight: FontWeight.bold, fontSize: 120)),
maxLines: 1,
textScaleFactor: MediaQuery.of(context).textScaleFactor,
textDirection: TextDirection.ltr)
..layout())
text: TextSpan(
text: text,
style:
const TextStyle(fontWeight: FontWeight.bold, fontSize: 120)),
maxLines: 1,
textScaleFactor: MediaQuery.of(context).textScaleFactor,
textDirection: TextDirection.ltr)
..layout())
.size
.width;
}
Expand Down
11 changes: 5 additions & 6 deletions test/blocs/activity_bloc_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void main() {
MockActivityApi activityApi;

final DisplayNameModel mockUser =
DisplayNameModel(id: '50', displayName: 'testUser202', role: null);
DisplayNameModel(id: '50', displayName: 'testUser202', role: null);

final ActivityModel mockActivity = ActivityModel(
id: 1,
Expand Down Expand Up @@ -52,11 +52,10 @@ void main() {
void setupApiCalls() {
when(weekApi.update(mockUser.id, mockWeekModel.weekYear,
mockWeekModel.weekNumber, mockWeekModel))
.thenAnswer((_) => rx_dart.BehaviorSubject<WeekModel>
.seeded(mockWeekModel));
when(activityApi.update(mockActivity, mockUser.id))
.thenAnswer((_) => rx_dart.BehaviorSubject<ActivityModel>
.seeded(mockActivity));
.thenAnswer(
(_) => rx_dart.BehaviorSubject<WeekModel>.seeded(mockWeekModel));
when(activityApi.update(mockActivity, mockUser.id)).thenAnswer(
(_) => rx_dart.BehaviorSubject<ActivityModel>.seeded(mockActivity));
}

setUp(() {
Expand Down
23 changes: 20 additions & 3 deletions test/blocs/auth_bloc.test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,27 +82,44 @@ void main() {
})
);



///setup at the top to reflect logins of different user roles
const String username = 'Graatand';
const String password = 'password';
test('Should check that authenticate works', async((DoneFn done) {
///TODO: test fails with error message below
///NoSuchMethodError: The method 'listen' was called on null.
/// Receiver: null
/// Tried calling: listen(Closure: (GirafUserModel) => Null)
test('Should check that authenticate works guardian', async((DoneFn done) {
authBloc.mode.skip(1).listen((WeekplanMode mode) {
expect(mode, WeekplanMode.guardian);
done();
});
authBloc.authenticate(username, password);
}));

///setup at the top to reflect logins of different user roles
const String username2 = 'Chris';
test('Should check that authenticate works', async((DoneFn done) {
///TODO: test fails with error message below
///NoSuchMethodError: The method 'listen' was called on null.
/// Receiver: null
/// Tried calling: listen(Closure: (GirafUserModel) => Null)
test('Should check that authenticate works (trustee)', async((DoneFn done) {
authBloc.mode.skip(1).listen((WeekplanMode mode) {
expect(mode, WeekplanMode.trustee);
done();
});
authBloc.authenticate(username2, password);
}));

///setup at the top to reflect logins of different user roles
const String username3 = 'Janne';
test('Should check that authenticate works', async((DoneFn done) {
///TODO: test fails with error message below
///NoSuchMethodError: The method 'listen' was called on null.
/// Receiver: null
/// Tried calling: listen(Closure: (GirafUserModel) => Null)
test('Should check that authenticate works (citizen)', async((DoneFn done) {
authBloc.mode.skip(1).listen((WeekplanMode mode) {
expect(mode, WeekplanMode.citizen);
done();
Expand Down
9 changes: 8 additions & 1 deletion test/blocs/choose_citizen_bloc_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/mockito.dart';
import 'package:weekplanner/blocs/choose_citizen_bloc.dart';

//Creates a mock for the test
class MockUserApi extends Mock implements UserApi {
@override
Stream<GirafUserModel> me() {
Expand All @@ -30,6 +31,7 @@ class MockUserApi extends Mock implements UserApi {
}

void main() {
//Setting up the environment
ChooseCitizenBloc bloc;
Api api;
setUp(() {
Expand All @@ -40,11 +42,16 @@ void main() {

test('Should be able to get UsernameModel from API', async((DoneFn done) {
int _count = 0;
//Set up citizen listener
bloc.citizen.listen((List<DisplayNameModel> response) {
//When "_count" is zero it expects length to be 0, and iterates "_count"
if (_count == 0) {
expect(response.length, 0);
_count++;
} else {
}
//Otherwise it expects the length to be 1,
//and checks if the data matches with the mock made above.
else {
expect(response.length, 1);
final DisplayNameModel rsp = response[0];
expect(rsp.displayName, 'test1');
Expand Down
5 changes: 4 additions & 1 deletion test/blocs/edit_weekplan_bloc_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ import 'package:weekplanner/di.dart';

class MockWeekApi extends Mock implements WeekApi {}

//test functionality for editing a weekplan bloc
void main() {
EditWeekplanBloc bloc;
WeekplansBloc mockWeekplanSelector;
Api api;
//Create mockup pictogram
final PictogramModel mockThumbnail = PictogramModel(
id: 1,
lastEdit: null,
Expand All @@ -26,14 +28,15 @@ void main() {
imageUrl: 'http://any.tld',
imageHash: null);
final DisplayNameModel mockUser =
DisplayNameModel(displayName: 'User', id: '1', role: null);
DisplayNameModel(displayName: 'User', id: '1', role: null);
final WeekModel mockWeek = WeekModel(
thumbnail: mockThumbnail,
days: null,
name: 'Week',
weekNumber: 1,
weekYear: DateTime.now().year + 1);

//set up test, defines what values to return on api calls
setUp(() {
api = Api('any');
api.week = MockWeekApi();
Expand Down
Loading

0 comments on commit b272d6d

Please sign in to comment.