Skip to content

Commit

Permalink
Integration test for changing SDK and running code (apache#24779)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeyinkin committed Dec 26, 2022
1 parent 27c870c commit 88be49f
Show file tree
Hide file tree
Showing 21 changed files with 421 additions and 98 deletions.
25 changes: 25 additions & 0 deletions playground/frontend/integration_test/common/common.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import 'package:flutter_test/flutter_test.dart';
import 'package:playground/main.dart' as app;

Future<void> init(WidgetTester wt) async {
app.main();
await wt.pumpAndSettle();
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,24 @@

import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:playground/main.dart' as app;
import 'package:playground/modules/examples/example_selector.dart';

Future<void> init(WidgetTester wt) async {
app.main();
await wt.pumpAndSettle();
}
import 'package:playground/modules/sdk/components/sdk_selector.dart';
import 'package:playground/modules/sdk/components/sdk_selector_row.dart';

extension CommonFindersExtension on CommonFinders {
Finder exampleItemInDropdown(String name) {
return widgetWithText(GestureDetector, name);
}

Finder exampleSelector() {
return byType(ExampleSelector);
}

Finder exampleItemInDropdown(String name) {
return widgetWithText(GestureDetector, name);
Finder sdkItemInDropdown(String name) {
return widgetWithText(SdkSelectorRow, name);
}

Finder sdkSelector() {
return byType(SDKSelector);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import 'package:flutter_test/flutter_test.dart';
import 'package:highlight/languages/java.dart';
import 'package:highlight/languages/python.dart';
import 'package:integration_test/integration_test.dart';
import 'package:playground_components_dev/playground_components_dev.dart';

import 'common/common.dart';
import 'common/common_finders.dart';

const _outputPrefix = 'The processing has started\n';

void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();

/// Runs and expects that the execution is as fast as it should be for cache.
Future<void> runExpectCached(WidgetTester wt) async {
final dateTimeStart = DateTime.now();

await wt.tap(find.runOrCancelButton());
await wt.pumpAndSettle();

expect(
DateTime.now().difference(dateTimeStart),
lessThan(const Duration(milliseconds: 2000)),
);
}

Future<void> expectJavaMinimalWordCount(WidgetTester wt) async {
expect(
wt.findOneCodeController().lastTextSpan!.toPlainText().isAsIfCutFrom(
await Examples.getVisibleTextByPath(
ExamplePaths.javaMinimalWordCount,
java,
),
),
true,
);

expect(find.graphTab(), findsOneWidget);
expect(find.resultTab(), findsOneWidget);
expect(wt.findOutputTabController().index, 0);
}

Future<void> changeToJavaAggregationMax(WidgetTester wt) async {
await wt.tap(find.exampleSelector());
await wt.pumpAndSettle();

await wt.tap(find.exampleItemInDropdown(ExampleNames.aggregationMax));
await wt.pumpAndSettle();

expect(
wt.findOneCodeController().lastTextSpan!.toPlainText().isAsIfCutFrom(
await Examples.getVisibleTextByPath(
ExamplePaths.javaAggregationMax,
java,
),
),
true,
);
}

Future<void> runExpectJavaAggregationMax(WidgetTester wt) async {
await runExpectCached(wt);
expectOutputEndsWith(ExampleOutputs.javaAggregationMaxTail, wt);
}

Future<void> runCustomJava(WidgetTester wt) async {
const text = 'OK';
const code = '''
public class MyClass {
public static void main(String[] args) {
System.out.print("$text");
}
}
''';

await wt.enterText(find.codeField(), code);
await wt.pumpAndSettle();

await wt.tap(find.runOrCancelButton());
await wt.pumpAndSettle();

expectOutput('$_outputPrefix$text', wt);
}

Future<void> switchToPython(WidgetTester wt) async {
await wt.tap(find.sdkSelector());
await wt.pumpAndSettle();

await wt.tap(find.sdkItemInDropdown('Python'));
await wt.pumpAndSettle();

expect(
wt.findOneCodeController().lastTextSpan!.toPlainText().isAsIfCutFrom(
await Examples.getVisibleTextByPath(
ExamplePaths.pythonMinimalWordCountWithMetrics,
python,
),
),
true,
);
}

Future<void> changeToPythonAggregationMean(WidgetTester wt) async {
await wt.tap(find.exampleSelector());
await wt.pumpAndSettle();

await wt.tap(find.exampleItemInDropdown(ExampleNames.aggregationMean));
await wt.pumpAndSettle();

// Cannot test this because the DB examples differ from GitHub now.
// TODO(alexeyinkin): Uncomment when DB is up-to-date.
// expect(
// wt.findOneCodeController().lastTextSpan!.toPlainText().isAsIfCutFrom(
// await Examples.getVisibleTextByPath(
// ExamplePaths.pythonAggregationMean,
// python,
// ),
// ),
// true,
// );
}

Future<void> runExpectPythonAggregationMean(WidgetTester wt) async {
await runExpectCached(wt);
expectOutputContains(ExampleOutputs.pythonAggregationMeanContains, wt);
}

Future<void> runCustomPython(WidgetTester wt) async {
const text = 'OK';
const code = 'print("$text", end="")';

await wt.enterText(find.codeField(), code);
await wt.pumpAndSettle();

await wt.tap(find.runOrCancelButton());
await wt.pumpAndSettle();

expectOutput('$_outputPrefix$text', wt);
}

testWidgets('Change example, change SDK, run', (WidgetTester wt) async {
await init(wt);

await expectJavaMinimalWordCount(wt);
await changeToJavaAggregationMax(wt);
await runExpectJavaAggregationMax(wt);
await runCustomJava(wt);

await switchToPython(wt);
await changeToPythonAggregationMean(wt);
await runExpectPythonAggregationMean(wt);
await runCustomPython(wt);
});
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ enum DropdownAlignment {
class AppDropdownButton extends StatefulWidget {
final Widget buttonText;
final Widget Function(void Function()) createDropdown;
final double height;
final double? height;
final double width;
final Widget? leading;
final bool showArrow;
Expand All @@ -47,8 +47,8 @@ class AppDropdownButton extends StatefulWidget {
super.key,
required this.buttonText,
required this.createDropdown,
required this.height,
required this.width,
this.height,
this.leading,
this.showArrow = true,
this.dropdownAlign = DropdownAlignment.left,
Expand Down
21 changes: 9 additions & 12 deletions playground/frontend/lib/modules/sdk/components/sdk_selector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,23 @@

import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:playground/components/dropdown_button/dropdown_button.dart';
import 'package:playground/constants/sizes.dart';
import 'package:playground/modules/sdk/components/sdk_selector_row.dart';
import 'package:playground_components/playground_components.dart';
import 'package:provider/provider.dart';

const kEmptyExampleName = 'Catalog';
import '../../../components/dropdown_button/dropdown_button.dart';
import '../../../constants/sizes.dart';
import 'sdk_selector_row.dart';

const double kWidth = 150;
const double kHeight = 172;
const double _width = 150;

class SDKSelector extends StatelessWidget {
final Sdk? value;
final ValueChanged<Sdk> onChanged;
final Sdk? value;

const SDKSelector({
Key? key,
required this.value,
required this.onChanged,
}) : super(key: key);
required this.value,
});

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -68,10 +65,10 @@ class SDKSelector extends StatelessWidget {
),
);
}),
const SizedBox(height: kMdSpacing),
],
),
width: kWidth,
height: kHeight,
width: _width,
),
),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ export 'src/widgets/loading_error.dart';
export 'src/widgets/loading_indicator.dart';
export 'src/widgets/logo.dart';
export 'src/widgets/output/output.dart';
export 'src/widgets/output/output_area.dart';
export 'src/widgets/output/output_tab.dart';
export 'src/widgets/output/output_tabs.dart';
export 'src/widgets/reset_button.dart';
export 'src/widgets/run_or_cancel_button.dart';
export 'src/widgets/shortcut_tooltip.dart';
Expand Down
2 changes: 1 addition & 1 deletion playground/frontend/playground_components/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ dependencies:
enum_map: ^0.2.1
equatable: ^2.0.5
flutter: { sdk: flutter }
flutter_code_editor: ^0.2.3
flutter_code_editor: ^0.2.4
flutter_markdown: ^0.6.12
flutter_svg: ^1.0.3
fluttertoast: ^8.1.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@
* limitations under the License.
*/

export 'src/code/java.dart';
export 'src/code/python.dart';

export 'src/common_finders.dart';
export 'src/example_names.dart';
export 'src/example_outputs.dart';
export 'src/example_paths.dart';
export 'src/examples.dart';
export 'src/expect.dart';
export 'src/string.dart';
export 'src/widget_tester.dart';
Loading

0 comments on commit 88be49f

Please sign in to comment.