Skip to content

Commit

Permalink
Issue24779 integration changing sdk from 24370 (#387)
Browse files Browse the repository at this point in the history
* Integration test for changing SDK and running code (apache#24779)

* Rename an integration test (apache#24779)

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

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

* Add a TODO (apache#24779)

* Fix exports (apache#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 (apache#24779)

Co-authored-by: Dmitry Repin <[email protected]>
  • Loading branch information
alexeyinkin and Malarg authored Jan 4, 2023
1 parent cc8a998 commit 9c16c66
Show file tree
Hide file tree
Showing 24 changed files with 634 additions and 32 deletions.
5 changes: 5 additions & 0 deletions playground/frontend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,17 @@ ext.deleteFilesByRegExp = { re ->

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

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

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

void runIntegrationTest(String path, String url) {
exec {
executable("flutter")
Expand Down
14 changes: 14 additions & 0 deletions playground/frontend/integration_test/common/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,17 @@ Future<void> init(WidgetTester wt) async {
app.main();
await wt.pumpAndSettle();
}

void expectHasDescendant(Finder ancestor, Finder descendant) {
expect(
find.descendant(of: ancestor, matching: descendant),
findsOneWidget,
);
}

void expectSimilar(double a, double b) {
Matcher closeToFraction(num value, double fraction) =>
closeTo(value, value * fraction);
Matcher onePerCentTolerance(num value) => closeToFraction(value, 0.01);
expect(a, onePerCentTolerance(b));
}
56 changes: 56 additions & 0 deletions playground/frontend/integration_test/common/common_finders.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,37 @@

import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.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';
import 'package:playground/modules/sdk/components/sdk_selector.dart';
import 'package:playground/modules/sdk/components/sdk_selector_row.dart';
import 'package:playground/modules/shortcuts/components/shortcuts_modal.dart';
import 'package:playground/pages/standalone_playground/widgets/editor_textarea_wrapper.dart';
import 'package:playground/pages/standalone_playground/widgets/feedback/feedback_dropdown_content.dart';
import 'package:playground/pages/standalone_playground/widgets/feedback/playground_feedback.dart';
import 'package:playground/pages/standalone_playground/widgets/more_actions.dart';
import 'package:playground_components/playground_components.dart';
import 'package:playground_components/src/widgets/drag_handle.dart';
import 'package:playground_components_dev/playground_components_dev.dart';

extension CommonFindersExtension on CommonFinders {
Finder codeTextAreaWrapper() {
return byType(CodeTextAreaWrapper);
}

Finder descriptionPopoverButton() {
return byType(DescriptionPopoverButton);
}

Finder descriptionPopover() {
return byType(DescriptionPopover);
}

Finder dragHandle() {
return byType(DragHandle);
}

Finder exampleItemInDropdown(String name) {
return widgetWithText(GestureDetector, name);
}
Expand All @@ -33,11 +57,43 @@ extension CommonFindersExtension on CommonFinders {
return byType(ExampleSelector);
}

Finder feedbackDropdownCancelButton() {
return find.byKey(FeedbackDropdownContent.cancelButtonKey);
}

Finder feedbackDropdownContent() {
return byType(FeedbackDropdownContent);
}

Finder feedbackDropdownSendButton() {
return find.byKey(FeedbackDropdownContent.sendButtonKey);
}

Finder feedbackDropdownTextField() {
return find.byKey(FeedbackDropdownContent.textFieldKey);
}

Finder feedbackThumbDown() {
return find.byKey(PlaygroundFeedback.thumbDownKey);
}

Finder feedbackThumbUp() {
return find.byKey(PlaygroundFeedback.thumbUpKey);
}

Finder moreActions() {
return byType(MoreActions);
}

Finder sdkItemInDropdown(Sdk sdk) {
return find.byType(SdkSelectorRow).and(find.byKey(ValueKey(sdk)));
}

Finder sdkSelector() {
return byType(SDKSelector);
}

Finder shortcutsModal() {
return byType(ShortcutsModal);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* 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/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:playground_components_dev/playground_components_dev.dart';

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

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

expect(find.descriptionPopover(), findsOneWidget);

final example = wt.findPlaygroundController().selectedExample!;

expectHasDescendant(find.descriptionPopover(), find.text(example.name));
expectHasDescendant(
find.descriptionPopover(),
find.text(example.description),
);

// //TODO Check contains github and colab links,
// //when https://github.com/apache/beam/pull/24820 will be merged

await wt.sendKeyEvent(LogicalKeyboardKey.escape);
await wt.pumpAndSettle();

expect(find.descriptionPopover(), findsNothing);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
* 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/modules/analytics/analytics_event.dart';
import 'package:playground/modules/analytics/analytics_events.dart';
import 'package:playground/modules/analytics/analytics_service.dart';

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

Future<void> checkEnjoyPlayground(WidgetTester wt) async {
await _checkEnjoyingAndSendFeedback(wt);
await _checkNotEnjoyingAndSendFeedback(wt);
await _checkNotEnjoyingAndClose(wt);
}

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

expect(find.feedbackDropdownContent(), findsOneWidget);

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

expect(find.feedbackDropdownContent(), findsNothing);
}

Future<void> _checkEnjoyingAndSendFeedback(WidgetTester wt) async {
expect(find.feedbackDropdownContent(), findsNothing);

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

expect(find.feedbackDropdownContent(), findsOneWidget);

const text = 'This is enjoying text';
await wt.enterText(find.feedbackDropdownTextField(), text);
await wt.pumpAndSettle();

expect(find.text(text), findsOneWidget);

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

final context = wt.element(find.feedbackThumbUp());
final lastSentEvent = AnalyticsService.get(context).lastSentEvent;
expect(
lastSentEvent,
AnalyticsEvent(
category: kFeedbackCategory,
action: kClickSendFeedbackEvent,
label: text,
),
);

expect(find.feedbackDropdownContent(), findsNothing);
}

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

expect(find.feedbackDropdownContent(), findsOneWidget);

const text = 'This is not enjoying text';
await wt.enterText(find.feedbackDropdownTextField(), text);
await wt.pumpAndSettle();

expect(find.text(text), findsOneWidget);

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

final context = wt.element(find.feedbackThumbDown());
final lastSentEvent = AnalyticsService.get(context).lastSentEvent;
expect(
lastSentEvent,
AnalyticsEvent(
category: kFeedbackCategory,
action: kClickSendFeedbackEvent,
label: text,
),
);

expect(find.feedbackDropdownContent(), findsNothing);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* 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/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:playground/modules/output/models/output_placement.dart';
import 'package:playground_components_dev/playground_components_dev.dart';

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

Future<void> checkOutputPlacement(WidgetTester wt) async {
Offset getCodeAreaCenter() => wt.getCenter(find.codeTextAreaWrapper());
Offset getOutputCenter() => wt.getCenter(find.outputWidget());

await wt.tap(find.byKey(const ValueKey(OutputPlacement.left)));
await wt.pumpAndSettle();
expect(getCodeAreaCenter().dx > getOutputCenter().dx, true);
expectSimilar(getCodeAreaCenter().dy, getOutputCenter().dy);

await wt.tap(find.byKey(const ValueKey(OutputPlacement.right)));
await wt.pumpAndSettle();
expect(getCodeAreaCenter().dx < getOutputCenter().dx, true);
expectSimilar(getCodeAreaCenter().dy, getOutputCenter().dy);

await wt.tap(find.byKey(const ValueKey(OutputPlacement.bottom)));
await wt.pumpAndSettle();
expect(getCodeAreaCenter().dy < getOutputCenter().dy, true);
expectSimilar(getCodeAreaCenter().dx, getOutputCenter().dx);
}
Loading

0 comments on commit 9c16c66

Please sign in to comment.