Skip to content

Commit

Permalink
Refactor output tabs, test running and dark mode in Embedded playgrou…
Browse files Browse the repository at this point in the history
…nd (apache#25136)
  • Loading branch information
alexeyinkin committed Jan 27, 2023
1 parent 6f4316c commit 6e5f8de
Show file tree
Hide file tree
Showing 44 changed files with 1,390 additions and 695 deletions.
7 changes: 7 additions & 0 deletions playground/frontend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,19 @@ ext.deleteFilesByRegExp = { re ->
}

tasks.register("integrationTest") {
dependsOn("integrationTest_embedded_run")
dependsOn("integrationTest_initial_urls")
dependsOn("integrationTest_standalone_change_example_sdk_run")
dependsOn("integrationTest_standalone_default_examples")
dependsOn("integrationTest_standalone_miscellaneous_ui")
}

tasks.register("integrationTest_embedded_run") {
doLast {
runIntegrationTest("embedded_run", "/")
}
}

tasks.register("integrationTest_initial_urls") {
doLast {
runIntegrationTest("initial_urls", "/")
Expand Down
42 changes: 42 additions & 0 deletions playground/frontend/integration_test/embedded_run_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* 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:integration_test/integration_test.dart';
import 'package:playground_components_dev/playground_components_dev.dart';

import 'common/common.dart';
import 'miscellaneous_ui/toggle_brightness_mode_test.dart';

const _url = '/embedded?path=SDK_JAVA%2FPRECOMPILED_OBJECT_TYPE_EXAMPLE%2FMinimalWordCount&sdk=java';

void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
testWidgets('Embedded run', (WidgetTester wt) async {
await init(wt);

await _openJavaMinimalWordCount(wt);
await wt.runExpectCached(javaMinimalWordCount);
await wt.modifyRunExpectReal(javaMinimalWordCount);
await checkToggleBrightnessMode(wt);
});
}

Future<void> _openJavaMinimalWordCount(WidgetTester wt) async {
await wt.navigateAndSettle(_url);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,13 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:playground_components_dev/playground_components_dev.dart';

Future<void> checkToggleBrightnessMode(WidgetTester wt) async {
Brightness getBrightness() {
return Theme.of(wt.element(find.toggleThemeButton())).brightness;
}

Future<void> toggleTheme() async {
await wt.tap(find.toggleThemeButton());
await wt.pumpAndSettle();
}

final startBrightness = getBrightness();
final startBrightness = wt.getBrightness();
final invertedBrightness =
startBrightness == Brightness.light ? Brightness.dark : Brightness.light;

await toggleTheme();
expect(getBrightness(), invertedBrightness);
await toggleTheme();
expect(getBrightness(), startBrightness);
await wt.toggleTheme();
expect(wt.getBrightness(), invertedBrightness);

await wt.toggleTheme();
expect(wt.getBrightness(), startBrightness);
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ void main() {
);
}

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

Future<void> runCustomJava(WidgetTester wt) async {
const text = 'OK';
const code = '''
Expand All @@ -66,7 +61,7 @@ public class MyClass {
await wt.tap(find.runOrCancelButton());
await wt.pumpAndSettle();

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

Future<void> switchToPython(WidgetTester wt) async {
Expand Down Expand Up @@ -100,14 +95,6 @@ public class MyClass {
// );
}

Future<void> runExpectPythonAggregationMean(WidgetTester wt) async {
await wt.runExpectCached();

for (final str in pythonAggregationMean.outputContains!) {
expectOutputContains(str, wt);
}
}

Future<void> runCustomPython(WidgetTester wt) async {
const text = 'OK';
const code = 'print("$text", end="")';
Expand All @@ -118,19 +105,19 @@ public class MyClass {
await wt.tap(find.runOrCancelButton());
await wt.pumpAndSettle();

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

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

await changeToJavaAggregationMax(wt);
await runExpectJavaAggregationMax(wt);
await wt.runExpectCached(javaAggregationMax);
await runCustomJava(wt);

await switchToPython(wt);
await changeToPythonAggregationMean(wt);
await runExpectPythonAggregationMean(wt);
await wt.runExpectCached(pythonAggregationMean);
await runCustomPython(wt);
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:playground_components/playground_components.dart';
import 'package:playground_components_dev/playground_components_dev.dart';

import 'common/common.dart';
Expand All @@ -40,8 +41,8 @@ void main() {
}

await _expectExample(example, wt);
await _runCached(example, wt);
await _runReal(example, wt);
await wt.runExpectCached(example);
await wt.modifyRunExpectReal(example);
}
});
}
Expand All @@ -61,33 +62,5 @@ Future<void> _expectExample(ExampleDescriptor example, WidgetTester wt) async {
}

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

Future<void> _runCached(ExampleDescriptor example, WidgetTester wt) async {
await wt.runExpectCached();
_expectOutput(example, wt);
}

Future<void> _runReal(ExampleDescriptor example, WidgetTester wt) async {
// Add a character into the first comment.
// This relies on that the position 10 is inside a license comment.
final controller = wt.findOneCodeController();
final text = controller.fullText;
controller.fullText = text.substring(0, 10) + '+' + text.substring(10);

await wt.runExpectReal();
_expectOutput(example, wt);
}

void _expectOutput(ExampleDescriptor example, WidgetTester wt) {
if (example.outputTail != null) {
expectOutputEndsWith(example.outputTail, wt);
} else if (example.outputContains != null) {
for (final str in example.outputContains!) {
expectOutputContains(str, wt);
}
} else {
throw AssertionError('No pattern to check example output: ${example.path}');
}
expect(wt.findOutputTabController().currentKey, OutputTabEnum.result);
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export 'src/controllers/example_loaders/examples_loader.dart';
export 'src/controllers/playground_controller.dart';
export 'src/controllers/public_notifier.dart';
export 'src/enums/complexity.dart';
export 'src/enums/output_tab.dart';
export 'src/models/category_with_examples.dart';
export 'src/models/example.dart';
export 'src/models/example_base.dart';
Expand Down Expand Up @@ -65,9 +66,7 @@ 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/overlay/body.dart';
export 'src/widgets/overlay/dismissible.dart';
export 'src/widgets/overlay/opener.dart';
Expand All @@ -78,6 +77,7 @@ export 'src/widgets/shortcuts_manager.dart';
export 'src/widgets/snippet_editor.dart';
export 'src/widgets/split_view.dart';
export 'src/widgets/tab_header.dart';
export 'src/widgets/tabs/tab_bar.dart';
export 'src/widgets/toasts/toast_listener.dart';
export 'src/widgets/toggle_theme_button.dart';
export 'src/widgets/toggle_theme_icon_button.dart';
Loading

0 comments on commit 6e5f8de

Please sign in to comment.