Skip to content

Commit

Permalink
[#146] [RF] Improve Forecast Chart. Localize test data
Browse files Browse the repository at this point in the history
  • Loading branch information
lyskouski committed Aug 21, 2023
1 parent 48a91bb commit 7ac0a44
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
9 changes: 6 additions & 3 deletions test/e2e/e2e_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@ import '_steps/file_runner.dart';
import '_steps/screen_capture.dart';

void main() {
TestWidgetsFlutterBinding.ensureInitialized();
ScreenCapture.enableScreenCapture();

Iterable<File> features = Directory('./test/e2e')
.listSync(recursive: true)
.where((entity) => entity is File && entity.path.endsWith('.feature'))
.cast<File>();

setUpAll(() {
TestWidgetsFlutterBinding.ensureInitialized();
ScreenCapture.enableScreenCapture();
PumpMain.cleanUpData();
});

group('Behavioral Tests', () {
for (var file in features) {
testWidgets(file.path, (WidgetTester tester) async {
Expand Down
20 changes: 20 additions & 0 deletions test/pump_main.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
// Copyright 2023 The terCAD team. All rights reserved.
// Use of this source code is governed by a CC BY-NC-ND 4.0 license that can be found in the LICENSE file.

import 'dart:io';

import 'package:app_finance/_classes/storage/app_data.dart';
import 'package:app_finance/_classes/herald/app_locale.dart';
import 'package:app_finance/_classes/herald/app_theme.dart';
import 'package:app_finance/_classes/gen/generate_with_method_setters.dart';
import 'package:app_finance/_mixins/shared_preferences_mixin.dart';
import 'package:app_finance/main.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/annotations.dart';
import 'package:provider/provider.dart';
Expand All @@ -21,8 +24,11 @@ import 'pump_main.mocks.dart';
import 'pump_main.wrapper.dart';

class PumpMain {
static const path = './coverage/data';

static init(WidgetTester tester, [bool isIntegration = false]) async {
final pumpMain = PumpMain();
wrapProvider(tester, 'plugins.flutter.io/path_provider', '$path/${UniqueKey()}');
await pumpMain.initPref(isIntegration);
await pumpMain.initMain(tester, isIntegration);
}
Expand All @@ -35,6 +41,20 @@ class PumpMain {
return appData;
}

static void cleanUpData() {
final dir = Directory(path);
if (dir.existsSync()) {
dir.deleteSync(recursive: true);
}
}

static void wrapProvider(WidgetTester tester, String channel, String output) {
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
MethodChannel(channel),
(MethodCall methodCall) => Future.value(output),
);
}

Future<void> initPref(bool isIntegration) async {
if (isIntegration) {
SharedPreferencesMixin.pref = await SharedPreferences.getInstance();
Expand Down

0 comments on commit 7ac0a44

Please sign in to comment.