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 e6566f6 commit 2ea8236
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
6 changes: 5 additions & 1 deletion test/e2e/e2e_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@ 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(() {
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);
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 2ea8236

Please sign in to comment.