Skip to content

Commit

Permalink
Update testing classes
Browse files Browse the repository at this point in the history
Update of testing classes to include the changes to read the question catalog
  • Loading branch information
yulieth9109 committed Aug 25, 2023
1 parent cc69b61 commit d6101db
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
21 changes: 17 additions & 4 deletions test/parse_json_test.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:async';

import 'package:flutter_test/flutter_test.dart';
import 'package:open_stop/models/question_catalog/question_catalog.dart';
import 'package:open_stop/models/question_catalog/question_catalog_reader.dart';
Expand All @@ -7,16 +9,27 @@ void main() async {
// https://stackoverflow.com/questions/49480080/flutter-load-assets-for-tests
TestWidgetsFlutterBinding.ensureInitialized();

late final QuestionCatalog questionJson;
late QuestionCatalog questionCatalog;

setUpAll(() async {
final QuestionCatalogReader questionCatalogReader = QuestionCatalogReader();
questionJson = await questionCatalogReader.read(false);
final mainCatalogDirectory = 'assets/question_catalog';
final questionCatalogReader = QuestionCatalogReader(
assetPaths: [ mainCatalogDirectory,],
);

final completer = Completer<QuestionCatalogChange>();

questionCatalogReader.questionCatalog.listen((questionCatalogChange) {
completer.complete(questionCatalogChange);
});

final questionCatalogChange = await completer.future;
questionCatalog = questionCatalogChange.catalog;
});

test('test if the question_catalog.json can be parsed successfully to its corresponding models', () {
expect(
questionJson,
questionCatalog,
isInstanceOf<QuestionCatalog>()
);
});
Expand Down
16 changes: 11 additions & 5 deletions test/widget_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,26 @@ void main() {
AppWorkerInterface.spawn(),
SharedPreferences.getInstance(),
]);

final QuestionCatalogReader questionCatalogReader = QuestionCatalogReader();
final questionC = await questionCatalogReader.read(false);

GetIt.I.registerSingleton<AppWorkerInterface>(futures[0] as AppWorkerInterface);
GetIt.I.registerSingleton<PreferencesService>(
PreferencesService(preferences: futures[1] as SharedPreferences),
);

const mainCatalogDirectory = 'assets/question_catalog';

final questionCatalogReader = QuestionCatalogReader(
assetPaths: [mainCatalogDirectory],
);

questionCatalogReader.questionCatalog.listen((questionCatalogChange) {
GetIt.I.get<AppWorkerInterface>().updateQuestionCatalog(questionCatalogChange);
});

final assets = await Future.wait([
rootBundle.load('assets/datasets/map_feature_collection.json')
]);

GetIt.I.get<AppWorkerInterface>(). updateQuestionCatalog( questionCatalog: questionC, onlyLanguageChange: false);

GetIt.I.get<AppWorkerInterface>().passAssets(assets);
});

Expand Down

0 comments on commit d6101db

Please sign in to comment.