Skip to content

Commit

Permalink
Playground integration test run and editing (#25033)
Browse files Browse the repository at this point in the history
* Integration test to load the default example of the default SDK and change the example (#24730) (#24729)

* Fix formatting and README (#24730)

* Support collection v1.17.0 (#24730)

* LoadingIndicator on chaning examples, remove duplicating licenses (#24730)

* Add a missing license header (#24730)

* Integration test for changing SDK and running code (#24779) (#382)

* Integration test for changing SDK and running code (#24779)

* Rename an integration test (#24779)

* Use enum to switch SDK in integration test (#24779)

* Find SDK in a dropdown by key (#24779)

* Add a TODO (#24779)

* Fix exports (#24779)

* Issue24779 integration changing sdk from 24370 (#387)

* Integration test for changing SDK and running code (#24779)

* Rename an integration test (#24779)

* Use enum to switch SDK in integration test (#24779)

* Find SDK in a dropdown by key (#24779)

* Add a TODO (#24779)

* Fix exports (#24779)

* Integration tests miscellaneous UI (#383)

* miscellaneous ui integration tests

* reverted pubspec.lock

* gradle tasks ordered alhpabetically

* integration tests refactoring

* clean code

* integration tests miscellaneous ui fix pr

* rename method

* added layout adaptivity

* A minor cleanup (#24779)

Co-authored-by: Dmitry Repin <[email protected]>

* integration tests run and editing

* example selector test

* minor fixes

* rat

* fix pr

* minor

* minor

* rat

* integration test finder written

* integration test minor fixes

* minor fixes

* removed comment

* minor fixes

* playground integration tests minor fixes

* integration test pumpAnSettleNoException

* integration test shortcut refactor

* integration test another changing shortcuts running

* upgrade to flutter 3.7.1

* workaround comment

* playground frontend updated major versions

* issues 25329 25331 25336

* 25329 extract connectivity extension to separate file

* Upgrade Flutter to 3.7.3 in integration tests (#24730)

* Fix integration test (#24730)

* fix cors issue and added mouse scroll to tags

* Upgrade Flutter in Dockerfile (#24720)

* sorting moved to model

* sorting moved to model

* sorting moved to model

* bugs fix

* issue 25278

* fix pr

* quites fix in en.yaml

* Fix not loading default example (#25528)

* fix compile error

* Refactor output tabs, test embedded playground (#25136) (#439)

* Refactor output tabs, test embedded playground (#25136)

* Clean up (#25136)

* Change example paths to IDs in integration tests

* Panning the graph tab (#25118)

---------

Co-authored-by: Alexey Inkin <[email protected]>
Co-authored-by: alexeyinkin <[email protected]>
  • Loading branch information
3 people authored Mar 9, 2023
1 parent 1c0ea97 commit 48c143d
Show file tree
Hide file tree
Showing 85 changed files with 2,717 additions and 837 deletions.
7 changes: 7 additions & 0 deletions learning/tour-of-beam/frontend/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.0"
os_detect:
dependency: transitive
description:
name: os_detect
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.1"
package_config:
dependency: transitive
description:
Expand Down
10 changes: 5 additions & 5 deletions playground/frontend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ flutter format ./lib
To delete all generated files and re-generate them again and then run tests:

```bash
./gradlew :playground:frontend:playground_components::test
./gradlew :playground:frontend:playground_components:test
./gradlew :playground:frontend:test
```

Expand Down Expand Up @@ -218,7 +218,7 @@ To add a new localization (using `fr` as an example):

#### 1. Linking to a catalog example by path

`https://play.beam.apache.org/?path=SDK_JAVA/PRECOMPILED_OBJECT_TYPE_KATA/AggregationMax&sdk=java`
`https://play.beam.apache.org/?path=SDK_JAVA_AggregationMax&sdk=java`

Handled by `StandardExampleLoader`.

Expand Down Expand Up @@ -311,7 +311,7 @@ are allowed for loading single examples, for instance:
[
{
"sdk": "java",
"path": "SDK_JAVA/PRECOMPILED_OBJECT_TYPE_KATA/AggregationMax"
"path": "SDK_JAVA_AggregationMax"
},
{
"sdk": "go",
Expand All @@ -323,7 +323,7 @@ are allowed for loading single examples, for instance:

Then pass it in`examples` query parameter like this:

`https://play.beam.apache.org/?sdk=go&examples=[{"sdk":"java","path":"SDK_JAVA/PRECOMPILED_OBJECT_TYPE_KATA/AggregationMax"},{"sdk":"go","url":"https://raw.githubusercontent.com/GoogleCloudPlatform/golang-samples/main/iam/snippets/roles_get.go","readonly":"iam_get_role"}]`
`https://play.beam.apache.org/?sdk=go&examples=[{"sdk":"java","path":"SDK_JAVA_AggregationMax"},{"sdk":"go","url":"https://raw.githubusercontent.com/GoogleCloudPlatform/golang-samples/main/iam/snippets/roles_get.go","readonly":"iam_get_role"}]`

This starts with the Go example loaded from the URL.
If SDK is then switched to Java, the `AggregationMax` catalog example is loaded for it.
Expand All @@ -348,7 +348,7 @@ Use the `<iframe>` tag to embed playground with any of the above URL patterns, f

```html
<iframe
src="https://play-dev.beam.apache.org/embedded?path=SDK_JAVA/PRECOMPILED_OBJECT_TYPE_KATA/AggregationMax&sdk=java"
src="https://play-dev.beam.apache.org/embedded?path=SDK_JAVA_AggregationMax&sdk=java"
width="800px"
height="500px"
allow="clipboard-write"
Expand Down
1 change: 1 addition & 0 deletions playground/frontend/assets/translations/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ intents:
newExample: 'New Example'
openGoogleColab: 'Open in Google Colab'
showDatasets: 'Dataset: {fileName}'
showSuggestions: 'Show Suggestions'
viewOnGithub: 'View on GitHub'
usesEmulatedData: 'This examples uses emulated data'
42 changes: 42 additions & 0 deletions playground/frontend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,22 @@ ext.deleteFilesByRegExp = { re ->
}

tasks.register("integrationTest") {
dependsOn("integrationTest_embedded_run")
dependsOn("integrationTest_initial_urls")
dependsOn("integrationTest_standalone_cancel_running_example")
dependsOn("integrationTest_standalone_change_example_sdk_run")
dependsOn("integrationTest_standalone_change_pipeline_options_and_run")
dependsOn("integrationTest_standalone_default_examples")
dependsOn("integrationTest_standalone_editing")
dependsOn("integrationTest_standalone_example_selector")
dependsOn("integrationTest_standalone_miscellaneous_ui")
dependsOn("integrationTest_standalone_run_shortcuts")
}

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

tasks.register("integrationTest_initial_urls") {
Expand All @@ -193,24 +205,54 @@ tasks.register("integrationTest_initial_urls") {
}
}

tasks.register("integrationTest_standalone_cancel_running_example") {
doLast {
runIntegrationTest("standalone_cancel_running_example", "/")
}
}

tasks.register("integrationTest_standalone_change_example_sdk_run") {
doLast {
runIntegrationTest("standalone_change_example_sdk_run", "/")
}
}

tasks.register("integrationTest_standalone_change_pipeline_options_and_run") {
doLast {
runIntegrationTest("standalone_change_pipeline_options_and_run", "/")
}
}

tasks.register("integrationTest_standalone_default_examples") {
doLast {
runIntegrationTest("standalone_default_examples", "/")
}
}

tasks.register("integrationTest_standalone_editing") {
doLast {
runIntegrationTest("standalone_editing", "/")
}
}

tasks.register("integrationTest_standalone_example_selector") {
doLast {
runIntegrationTest("standalone_example_selector", "/")
}
}

tasks.register("integrationTest_standalone_miscellaneous_ui") {
doLast {
runIntegrationTest("standalone_miscellaneous_ui", "/")
}
}

tasks.register("integrationTest_standalone_run_shortcuts") {
doLast {
runIntegrationTest("standalone_run_shortcuts", "/")
}
}

void runIntegrationTest(String path, String url) {
// Run with -PdeviceId=web-server for headless tests.
String deviceId = project.hasProperty("deviceId") ? project.deviceId : "chrome"
Expand Down
23 changes: 23 additions & 0 deletions playground/frontend/integration_test/common/common_finders.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@

import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:playground/modules/actions/components/reset_action.dart';
import 'package:playground/modules/editor/components/pipeline_options_dropdown/pipeline_options_dropdown.dart';
import 'package:playground/modules/editor/components/pipeline_options_dropdown/pipeline_options_dropdown_body.dart';
import 'package:playground/modules/examples/components/description_popover/description_popover.dart';
import 'package:playground/modules/examples/components/description_popover/description_popover_button.dart';
import 'package:playground/modules/examples/example_selector.dart';
Expand Down Expand Up @@ -85,6 +88,26 @@ extension CommonFindersExtension on CommonFinders {
return byType(MoreActions);
}

Finder pipelineOptionsDropdown() {
return find.byType(PipelineOptionsDropdown);
}

Finder pipelineOptionsListTab() {
return find.byKey(PipelineOptionsDropdownBody.optionsTabKey);
}

Finder pipelineOptionsRawTab() {
return find.byKey(PipelineOptionsDropdownBody.rawTabKey);
}

Finder pipelineOptionsSaveAndCloseButton() {
return find.byKey(PipelineOptionsDropdownBody.saveAndCloseButtonKey);
}

Finder resetButton() {
return find.byType(ResetAction);
}

Finder sdkItemInDropdown(Sdk sdk) {
return find.byType(SdkSelectorRow).and(find.byKey(ValueKey(sdk)));
}
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';

final _url = '/embedded?path=${javaMinimalWordCount.dbPath}&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
@@ -0,0 +1,56 @@
/*
* 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';

const kExecutionCancelledText = 'Pipeline cancelled';

void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();

testWidgets('Cancel running example', (WidgetTester wt) async {
await init(wt);

// Cancel unchanged example.
await _runAndCancelExample(wt, const Duration(milliseconds: 300));

final source = wt.findPlaygroundController().source ?? '';
await wt.enterText(find.codeField(), '//comment\n' + source);
await wt.pumpAndSettle();

// Cancel changed example.
await _runAndCancelExample(wt, const Duration(milliseconds: 5000));
});
}

Future<void> _runAndCancelExample(WidgetTester wt, Duration duration) async {
await wt.tap(find.runOrCancelButton());

await wt.pumpAndSettleNoException(timeout: duration);
await wt.tapAndSettle(find.runOrCancelButton());

final playgroundController = wt.findPlaygroundController();
expect(
playgroundController.codeRunner.resultLogOutput,
contains(kExecutionCancelledText),
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import 'common/common.dart';
import 'common/common_finders.dart';
import 'common/widget_tester.dart';

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

void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
Expand All @@ -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);
});
}
Loading

0 comments on commit 48c143d

Please sign in to comment.