alexeyinkin commented on code in PR #25033: URL: https://github.com/apache/beam/pull/25033#discussion_r1085098862
########## playground/frontend/integration_test/standalone_cancel_running_example_test.dart: ########## @@ -0,0 +1,68 @@ +/* + * 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/playground_components.dart'; +import 'package:playground_components_dev/playground_components_dev.dart'; + +import 'common/common.dart'; + +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() + .snippetEditingController + ?.activeFileController + ?.codeController + .fullText ?? + ''; Review Comment: Check if there is a getter for this. It may be on the Copy button of the embedded playground. ########## playground/frontend/build.gradle: ########## @@ -183,20 +183,41 @@ ext.deleteFilesByRegExp = { re -> } tasks.register("integrationTest") { - dependsOn("integrationTest_standalone_change_example_sdk_run") + // dependsOn("integrationTest_standalone_change_example_sdk_run") - + dependsOn("integrationTest_standalone_cancel_running_example") + dependsOn("integrationTest_standalone_change_pipeline_options_and_run") + dependsOn("integrationTest_standalone_editing") + dependsOn("integrationTest_standalone_example_selector") dependsOn("integrationTest_standalone_miscellaneous_ui") + dependsOn("integrationTest_standalone_run_shortcuts") +} + +tasks.register("integrationTest_standalone_cancel_running_example") { + runIntegrationTest("standalone_cancel_running_example", "/") Review Comment: `doLast` everywhere. ########## playground/frontend/integration_test/standalone_change_pipeline_options_and_run_test.dart: ########## @@ -0,0 +1,152 @@ +/* + * 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/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:integration_test/integration_test.dart'; +import 'package:playground/modules/editor/components/pipeline_options_dropdown/pipeline_options_dropdown_body.dart'; +import 'package:playground/modules/editor/components/pipeline_options_dropdown/pipeline_options_dropdown_input.dart'; +import 'package:playground/modules/editor/components/pipeline_options_dropdown/pipeline_options_text_field.dart'; +import 'package:playground_components/playground_components.dart'; +import 'package:playground_components_dev/playground_components_dev.dart'; + +import 'common/common.dart'; +import 'common/common_finders.dart'; + +void main() { + IntegrationTestWidgetsFlutterBinding.ensureInitialized(); + + testWidgets( + 'Changing pipeline options and press run', + (WidgetTester wt) async { + await init(wt); + + await wt.tapAndSettle(find.appDropdownButtonWithText('Pipeline Options')); + + await _addTwoOptions(wt); + + await wt.tapAndSettle(find.pipelineOptionsRawTab()); + + _checkIfRawTextCorrect('--some test --some2 test2'); + + await wt.tapAndSettle(find.pipelineOptionsListTab()); + + await wt.tap(_getBottomDeleteIcon(wt)); + + await wt.tapAndSettle(find.pipelineOptionsRawTab()); + + _checkIfRawTextCorrect('--some test'); + + await wt.tapAndSettle(find.pipelineOptionsSaveAndCloseButton()); + + await wt.tap(find.runOrCancelButton()); + await Future.delayed(const Duration(milliseconds: 300)); + + await wt.tapAndSettle(find.runOrCancelButton()); + + final playgroundController = wt.findPlaygroundController(); + expect( + playgroundController.codeRunner.resultLogOutput, + contains('--some test'), + ); + expect( + playgroundController.codeRunner.resultLogOutput, + contains(kExecutionCancelledText), + ); + }, + ); +} + +Future<void> _addTwoOptions(WidgetTester wt) async { + await wt.enterText( + _getPipelineOptionsTextField(wt, _Placement.topLeft), + 'some', + ); + await wt.enterText( + _getPipelineOptionsTextField(wt, _Placement.topRight), + 'test', + ); + + await wt.tap(find.byKey(PipelineOptionsDropdownBody.addOptionButtonKey)); + await wt.pumpAndSettle(); + + await wt.enterText( + _getPipelineOptionsTextField(wt, _Placement.bottomLeft), + 'some2', + ); + await wt.enterText( + _getPipelineOptionsTextField(wt, _Placement.bottomRight), + 'test2', + ); +} + +Finder _getPipelineOptionsTextField(WidgetTester wt, _Placement placement) { + final fields = find.byType(PipelineOptionsTextField); + final positions = <_Point>[]; + for (var i = 0; i < fields.evaluate().length; i++) { + final element = fields.at(i); + final position = wt.getCenter(element); + positions.add(_Point(position.dx, position.dy)); + } + + late _Point Function(_Point, _Point) reduceFunc; Review Comment: ```suggestion _Point Function(_Point, _Point) reduceFunc; ``` ########## playground/frontend/integration_test/standalone_editing_test.dart: ########## @@ -0,0 +1,145 @@ +/* + * 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/material.dart'; +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 'common/common_finders.dart'; + +void main() { + IntegrationTestWidgetsFlutterBinding.ensureInitialized(); + + testWidgets('Testing editing code', (WidgetTester wt) async { + await init(wt); + await _checkResetDefaultCode(wt); + await _checkResetEditedCode(wt); + await _checkAutocomplete(wt); + await _checkCodeHighlightedMultipleColors(wt); + await _checkCodeBlockFolding(wt); + }); +} + +Future<void> _checkAutocomplete(WidgetTester wt) async { + await wt.enterText(find.codeField(), '\n\n\n\n\nsdk'); + + final playgroundController = wt.findPlaygroundController(); + await wt.runShortcut( + playgroundController.showAutocompleterShortcut.shortcuts.keys); + await wt.pumpAndSettle(); + + expect(find.text('sdkHttpMetadata'), findsOneWidget); + expect(find.text('sdkHttpMetadataWithoutHeaders'), findsOneWidget); + expect(find.text('sdkHttpResponse'), findsOneWidget); + expect(find.text('sdkHttpResponseWithoutHeaders'), findsOneWidget); + + await wt.tapAndSettle(find.resetButton()); +} + +Future<void> _checkResetDefaultCode(WidgetTester wt) async { Review Comment: ```suggestion Future<void> _checkResetUnchangedCode(WidgetTester wt) async { ``` ########## playground/frontend/integration_test/standalone_change_pipeline_options_and_run_test.dart: ########## @@ -0,0 +1,152 @@ +/* + * 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/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:integration_test/integration_test.dart'; +import 'package:playground/modules/editor/components/pipeline_options_dropdown/pipeline_options_dropdown_body.dart'; +import 'package:playground/modules/editor/components/pipeline_options_dropdown/pipeline_options_dropdown_input.dart'; +import 'package:playground/modules/editor/components/pipeline_options_dropdown/pipeline_options_text_field.dart'; +import 'package:playground_components/playground_components.dart'; +import 'package:playground_components_dev/playground_components_dev.dart'; + +import 'common/common.dart'; +import 'common/common_finders.dart'; + +void main() { + IntegrationTestWidgetsFlutterBinding.ensureInitialized(); + + testWidgets( + 'Changing pipeline options and press run', + (WidgetTester wt) async { + await init(wt); + + await wt.tapAndSettle(find.appDropdownButtonWithText('Pipeline Options')); + + await _addTwoOptions(wt); + + await wt.tapAndSettle(find.pipelineOptionsRawTab()); + + _checkIfRawTextCorrect('--some test --some2 test2'); + + await wt.tapAndSettle(find.pipelineOptionsListTab()); + + await wt.tap(_getBottomDeleteIcon(wt)); + + await wt.tapAndSettle(find.pipelineOptionsRawTab()); + + _checkIfRawTextCorrect('--some test'); + + await wt.tapAndSettle(find.pipelineOptionsSaveAndCloseButton()); + + await wt.tap(find.runOrCancelButton()); + await Future.delayed(const Duration(milliseconds: 300)); + + await wt.tapAndSettle(find.runOrCancelButton()); + + final playgroundController = wt.findPlaygroundController(); + expect( + playgroundController.codeRunner.resultLogOutput, + contains('--some test'), + ); + expect( + playgroundController.codeRunner.resultLogOutput, + contains(kExecutionCancelledText), + ); + }, + ); +} + +Future<void> _addTwoOptions(WidgetTester wt) async { + await wt.enterText( + _getPipelineOptionsTextField(wt, _Placement.topLeft), + 'some', + ); + await wt.enterText( + _getPipelineOptionsTextField(wt, _Placement.topRight), + 'test', + ); + + await wt.tap(find.byKey(PipelineOptionsDropdownBody.addOptionButtonKey)); + await wt.pumpAndSettle(); + + await wt.enterText( + _getPipelineOptionsTextField(wt, _Placement.bottomLeft), + 'some2', + ); + await wt.enterText( + _getPipelineOptionsTextField(wt, _Placement.bottomRight), + 'test2', + ); +} + +Finder _getPipelineOptionsTextField(WidgetTester wt, _Placement placement) { + final fields = find.byType(PipelineOptionsTextField); + final positions = <_Point>[]; + for (var i = 0; i < fields.evaluate().length; i++) { + final element = fields.at(i); + final position = wt.getCenter(element); + positions.add(_Point(position.dx, position.dy)); + } + + late _Point Function(_Point, _Point) reduceFunc; + switch (placement) { + case _Placement.topLeft: + reduceFunc = (a, b) => a.x <= b.x && a.y <= b.y ? a : b; + break; + case _Placement.topRight: + reduceFunc = (a, b) => a.x >= b.x && a.y <= b.y ? a : b; + break; + case _Placement.bottomLeft: + reduceFunc = (a, b) => a.x <= b.x && a.y >= b.y ? a : b; + break; + case _Placement.bottomRight: + reduceFunc = (a, b) => a.x >= b.x && a.y >= b.y ? a : b; + break; + } + final position = positions.reduce(reduceFunc); + return fields.at(positions.indexOf(position)); +} + +enum _Placement { topLeft, topRight, bottomLeft, bottomRight } + +class _Point { + final double x; + final double y; + + _Point(this.x, this.y); +} + +Finder _getBottomDeleteIcon(WidgetTester wt) { + Finder deleteIcons = find.byIcon(Icons.delete_outlined); + + Finder bottomIcon = + wt.getCenter(deleteIcons.at(0)).dy > wt.getCenter(deleteIcons.at(1)).dy + ? deleteIcons.at(0) + : deleteIcons.at(1); + return bottomIcon; +} + +void _checkIfRawTextCorrect(String text) { Review Comment: ```suggestion void _expectRawText(String text) { ``` ########## playground/frontend/integration_test/standalone_change_pipeline_options_and_run_test.dart: ########## @@ -0,0 +1,152 @@ +/* + * 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/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:integration_test/integration_test.dart'; +import 'package:playground/modules/editor/components/pipeline_options_dropdown/pipeline_options_dropdown_body.dart'; +import 'package:playground/modules/editor/components/pipeline_options_dropdown/pipeline_options_dropdown_input.dart'; +import 'package:playground/modules/editor/components/pipeline_options_dropdown/pipeline_options_text_field.dart'; +import 'package:playground_components/playground_components.dart'; +import 'package:playground_components_dev/playground_components_dev.dart'; + +import 'common/common.dart'; +import 'common/common_finders.dart'; + +void main() { + IntegrationTestWidgetsFlutterBinding.ensureInitialized(); + + testWidgets( + 'Changing pipeline options and press run', + (WidgetTester wt) async { + await init(wt); + + await wt.tapAndSettle(find.appDropdownButtonWithText('Pipeline Options')); + + await _addTwoOptions(wt); + + await wt.tapAndSettle(find.pipelineOptionsRawTab()); + + _checkIfRawTextCorrect('--some test --some2 test2'); + + await wt.tapAndSettle(find.pipelineOptionsListTab()); + + await wt.tap(_getBottomDeleteIcon(wt)); + + await wt.tapAndSettle(find.pipelineOptionsRawTab()); + + _checkIfRawTextCorrect('--some test'); + + await wt.tapAndSettle(find.pipelineOptionsSaveAndCloseButton()); + + await wt.tap(find.runOrCancelButton()); + await Future.delayed(const Duration(milliseconds: 300)); + + await wt.tapAndSettle(find.runOrCancelButton()); Review Comment: Add a comment that cancelling is just for speed. ########## playground/frontend/integration_test/standalone_change_pipeline_options_and_run_test.dart: ########## @@ -0,0 +1,152 @@ +/* + * 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/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:integration_test/integration_test.dart'; +import 'package:playground/modules/editor/components/pipeline_options_dropdown/pipeline_options_dropdown_body.dart'; +import 'package:playground/modules/editor/components/pipeline_options_dropdown/pipeline_options_dropdown_input.dart'; +import 'package:playground/modules/editor/components/pipeline_options_dropdown/pipeline_options_text_field.dart'; +import 'package:playground_components/playground_components.dart'; +import 'package:playground_components_dev/playground_components_dev.dart'; + +import 'common/common.dart'; +import 'common/common_finders.dart'; + +void main() { + IntegrationTestWidgetsFlutterBinding.ensureInitialized(); + + testWidgets( + 'Changing pipeline options and press run', + (WidgetTester wt) async { + await init(wt); + + await wt.tapAndSettle(find.appDropdownButtonWithText('Pipeline Options')); + + await _addTwoOptions(wt); + + await wt.tapAndSettle(find.pipelineOptionsRawTab()); + + _checkIfRawTextCorrect('--some test --some2 test2'); + + await wt.tapAndSettle(find.pipelineOptionsListTab()); + + await wt.tap(_getBottomDeleteIcon(wt)); + + await wt.tapAndSettle(find.pipelineOptionsRawTab()); + + _checkIfRawTextCorrect('--some test'); + + await wt.tapAndSettle(find.pipelineOptionsSaveAndCloseButton()); + + await wt.tap(find.runOrCancelButton()); + await Future.delayed(const Duration(milliseconds: 300)); + + await wt.tapAndSettle(find.runOrCancelButton()); + + final playgroundController = wt.findPlaygroundController(); + expect( + playgroundController.codeRunner.resultLogOutput, + contains('--some test'), + ); + expect( + playgroundController.codeRunner.resultLogOutput, + contains(kExecutionCancelledText), + ); + }, + ); +} + +Future<void> _addTwoOptions(WidgetTester wt) async { + await wt.enterText( + _getPipelineOptionsTextField(wt, _Placement.topLeft), + 'some', + ); + await wt.enterText( + _getPipelineOptionsTextField(wt, _Placement.topRight), + 'test', + ); + + await wt.tap(find.byKey(PipelineOptionsDropdownBody.addOptionButtonKey)); + await wt.pumpAndSettle(); + + await wt.enterText( + _getPipelineOptionsTextField(wt, _Placement.bottomLeft), + 'some2', + ); + await wt.enterText( + _getPipelineOptionsTextField(wt, _Placement.bottomRight), + 'test2', + ); +} + +Finder _getPipelineOptionsTextField(WidgetTester wt, _Placement placement) { + final fields = find.byType(PipelineOptionsTextField); + final positions = <_Point>[]; + for (var i = 0; i < fields.evaluate().length; i++) { + final element = fields.at(i); + final position = wt.getCenter(element); + positions.add(_Point(position.dx, position.dy)); + } + + late _Point Function(_Point, _Point) reduceFunc; + switch (placement) { + case _Placement.topLeft: + reduceFunc = (a, b) => a.x <= b.x && a.y <= b.y ? a : b; + break; + case _Placement.topRight: + reduceFunc = (a, b) => a.x >= b.x && a.y <= b.y ? a : b; + break; + case _Placement.bottomLeft: + reduceFunc = (a, b) => a.x <= b.x && a.y >= b.y ? a : b; + break; + case _Placement.bottomRight: + reduceFunc = (a, b) => a.x >= b.x && a.y >= b.y ? a : b; + break; + } + final position = positions.reduce(reduceFunc); + return fields.at(positions.indexOf(position)); +} + +enum _Placement { topLeft, topRight, bottomLeft, bottomRight } + +class _Point { + final double x; + final double y; + + _Point(this.x, this.y); +} + +Finder _getBottomDeleteIcon(WidgetTester wt) { Review Comment: ```suggestion Finder _getDeleteIcon(int index, WidgetTester wt) { ``` ########## playground/frontend/integration_test/standalone_example_selector_test.dart: ########## @@ -0,0 +1,174 @@ +/* + * 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/modules/examples/components/example_list/example_item_actions.dart'; +import 'package:playground/modules/examples/components/filter/tag_bubble.dart'; +import 'package:playground/modules/examples/components/filter/type_bubble.dart'; +import 'package:playground/modules/examples/components/search_field/search_field.dart'; +import 'package:playground/modules/examples/examples_dropdown_content.dart'; +import 'package:playground/pages/standalone_playground/notifiers/example_selector_state.dart'; +import 'package:playground_components/playground_components.dart'; +import 'package:playground_components_dev/playground_components_dev.dart'; +import 'package:provider/provider.dart'; + +import 'common/common.dart'; +import 'common/common_finders.dart'; + +void main() { + IntegrationTestWidgetsFlutterBinding.ensureInitialized(); + + testWidgets('Example selector test', (WidgetTester wt) async { + await init(wt); + await _checkFilteringExamplesByTypes(wt); + await _checkFilteringExamplesByTags(wt); + await _checkFilteringExamplesBySearchString(wt); + await _checkViewDescription(wt); + }); +} + +Future<void> _checkFilteringExamplesByTypes(WidgetTester wt) async { + await wt.tapAndSettle(find.exampleSelector()); + final allExamplesCount = _getExamplesCount(wt); + await wt.tapAndSettle(find.widgetWithText(TypeBubble, ExampleType.test.name)); + + final filteredExamplesCount = _getExamplesCount(wt); + + expect(allExamplesCount, isNot(filteredExamplesCount)); + + final categoriesWithExamples = _getCategoriesWithExamples(wt); + for (final example in categoriesWithExamples.expand((e) => e.examples)) { + expect(example.type, ExampleType.test); + } + + await wt.tapAndSettle(find.exampleSelector()); +} + +Future<void> _checkFilteringExamplesByTags(WidgetTester wt) async { + await wt.tapAndSettle(find.exampleSelector()); + + final allExamplesCount = _getExamplesCount(wt); + final sortedTags = _getSortedTags(wt); + await wt.tapAndSettle(find.widgetWithText(TagBubble, sortedTags[0])); + final filteredExamplesCount = _getExamplesCount(wt); + + expect(_areCategoriesContainsTag(wt, [sortedTags[0]]), isTrue); + expect(allExamplesCount, isNot(filteredExamplesCount)); Review Comment: Unnecessary. ########## playground/frontend/integration_test/standalone_example_selector_test.dart: ########## @@ -0,0 +1,174 @@ +/* + * 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/modules/examples/components/example_list/example_item_actions.dart'; +import 'package:playground/modules/examples/components/filter/tag_bubble.dart'; +import 'package:playground/modules/examples/components/filter/type_bubble.dart'; +import 'package:playground/modules/examples/components/search_field/search_field.dart'; +import 'package:playground/modules/examples/examples_dropdown_content.dart'; +import 'package:playground/pages/standalone_playground/notifiers/example_selector_state.dart'; +import 'package:playground_components/playground_components.dart'; +import 'package:playground_components_dev/playground_components_dev.dart'; +import 'package:provider/provider.dart'; + +import 'common/common.dart'; +import 'common/common_finders.dart'; + +void main() { + IntegrationTestWidgetsFlutterBinding.ensureInitialized(); + + testWidgets('Example selector test', (WidgetTester wt) async { + await init(wt); + await _checkFilteringExamplesByTypes(wt); + await _checkFilteringExamplesByTags(wt); + await _checkFilteringExamplesBySearchString(wt); + await _checkViewDescription(wt); + }); +} + +Future<void> _checkFilteringExamplesByTypes(WidgetTester wt) async { + await wt.tapAndSettle(find.exampleSelector()); + final allExamplesCount = _getExamplesCount(wt); + await wt.tapAndSettle(find.widgetWithText(TypeBubble, ExampleType.test.name)); + + final filteredExamplesCount = _getExamplesCount(wt); + + expect(allExamplesCount, isNot(filteredExamplesCount)); + + final categoriesWithExamples = _getCategoriesWithExamples(wt); + for (final example in categoriesWithExamples.expand((e) => e.examples)) { + expect(example.type, ExampleType.test); + } + + await wt.tapAndSettle(find.exampleSelector()); +} + +Future<void> _checkFilteringExamplesByTags(WidgetTester wt) async { + await wt.tapAndSettle(find.exampleSelector()); + + final allExamplesCount = _getExamplesCount(wt); + final sortedTags = _getSortedTags(wt); + await wt.tapAndSettle(find.widgetWithText(TagBubble, sortedTags[0])); + final filteredExamplesCount = _getExamplesCount(wt); + + expect(_areCategoriesContainsTag(wt, [sortedTags[0]]), isTrue); + expect(allExamplesCount, isNot(filteredExamplesCount)); + + await wt.tapAndSettle(find.widgetWithText(TagBubble, sortedTags[1])); + final nextFilteredExamplesCount = _getExamplesCount(wt); + + expect(_areCategoriesContainsTag(wt, [sortedTags[0], sortedTags[1]]), isTrue); + expect(filteredExamplesCount, isNot(nextFilteredExamplesCount)); + + await wt.tapAndSettle(find.exampleSelector()); +} + +List<String> _getSortedTags(WidgetTester wt) { + final categoriesWithExamples = _getCategoriesWithExamples(wt); + final tags = categoriesWithExamples + .expand((e) => e.examples) + .expand((e) => e.tags); + final tagsMap = <String, int>{}; + for (final tag in tags) { + tagsMap[tag] = tagsMap[tag] == null ? 1 : tagsMap[tag]! + 1; + } + final tagsMapList = tagsMap.entries.toList()..sort((a, b) => b.value.compareTo(a.value)); + return tagsMapList.map((e) => e.key).toList(); +} + +bool _areCategoriesContainsTag(WidgetTester wt, List<String> tags) { + final categoriesWithExamples = _getCategoriesWithExamples(wt); + final examples = categoriesWithExamples.expand((e) => e.examples); + + if (examples.isEmpty) { + return true; + } + + for (final example in examples) { + for (final tag in tags) { + if (!example.tags.contains(tag)) { + return false; + } + } + } + return true; +} + +int _getExamplesCount(WidgetTester wt) { + final categories = _getCategoriesWithExamples(wt); + + if (categories.isEmpty) { + return 0; + } + + return categories + .map((e) => e.examples.length) + .reduce((value, element) => value + element); Review Comment: ```suggestion .reduce((a, b) => a + b); ``` ########## playground/frontend/playground_components/lib/src/util/logical_keyboard_key.dart: ########## @@ -0,0 +1,27 @@ +/* + * 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 'native_platform.dart'; + +extension LogicalKeyboardKeyExtension on LogicalKeyboardKey { Review Comment: ```suggestion class LogicalKeyboardKeyExtension { ``` ########## playground/frontend/playground_components/lib/src/controllers/playground_controller.dart: ########## @@ -252,7 +253,13 @@ class PlaygroundController with ChangeNotifier { Future<void> reset() async { await codeRunner.cancelRun(); snippetEditingController?.reset(); - codeRunner.clearResult(); + notifyListeners(); + } + + void showAutocompleter() { Review Comment: ```suggestion void showSuggestions() { ``` ########## playground/frontend/integration_test/standalone_example_selector_test.dart: ########## @@ -0,0 +1,174 @@ +/* + * 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/modules/examples/components/example_list/example_item_actions.dart'; +import 'package:playground/modules/examples/components/filter/tag_bubble.dart'; +import 'package:playground/modules/examples/components/filter/type_bubble.dart'; +import 'package:playground/modules/examples/components/search_field/search_field.dart'; +import 'package:playground/modules/examples/examples_dropdown_content.dart'; +import 'package:playground/pages/standalone_playground/notifiers/example_selector_state.dart'; +import 'package:playground_components/playground_components.dart'; +import 'package:playground_components_dev/playground_components_dev.dart'; +import 'package:provider/provider.dart'; + +import 'common/common.dart'; +import 'common/common_finders.dart'; + +void main() { + IntegrationTestWidgetsFlutterBinding.ensureInitialized(); + + testWidgets('Example selector test', (WidgetTester wt) async { + await init(wt); + await _checkFilteringExamplesByTypes(wt); + await _checkFilteringExamplesByTags(wt); + await _checkFilteringExamplesBySearchString(wt); + await _checkViewDescription(wt); + }); +} + +Future<void> _checkFilteringExamplesByTypes(WidgetTester wt) async { + await wt.tapAndSettle(find.exampleSelector()); + final allExamplesCount = _getExamplesCount(wt); + await wt.tapAndSettle(find.widgetWithText(TypeBubble, ExampleType.test.name)); + + final filteredExamplesCount = _getExamplesCount(wt); + + expect(allExamplesCount, isNot(filteredExamplesCount)); + + final categoriesWithExamples = _getCategoriesWithExamples(wt); + for (final example in categoriesWithExamples.expand((e) => e.examples)) { + expect(example.type, ExampleType.test); + } + + await wt.tapAndSettle(find.exampleSelector()); +} + +Future<void> _checkFilteringExamplesByTags(WidgetTester wt) async { + await wt.tapAndSettle(find.exampleSelector()); + + final allExamplesCount = _getExamplesCount(wt); + final sortedTags = _getSortedTags(wt); + await wt.tapAndSettle(find.widgetWithText(TagBubble, sortedTags[0])); + final filteredExamplesCount = _getExamplesCount(wt); + + expect(_areCategoriesContainsTag(wt, [sortedTags[0]]), isTrue); + expect(allExamplesCount, isNot(filteredExamplesCount)); + + await wt.tapAndSettle(find.widgetWithText(TagBubble, sortedTags[1])); + final nextFilteredExamplesCount = _getExamplesCount(wt); + + expect(_areCategoriesContainsTag(wt, [sortedTags[0], sortedTags[1]]), isTrue); + expect(filteredExamplesCount, isNot(nextFilteredExamplesCount)); + + await wt.tapAndSettle(find.exampleSelector()); +} + +List<String> _getSortedTags(WidgetTester wt) { + final categoriesWithExamples = _getCategoriesWithExamples(wt); + final tags = categoriesWithExamples + .expand((e) => e.examples) + .expand((e) => e.tags); + final tagsMap = <String, int>{}; + for (final tag in tags) { + tagsMap[tag] = tagsMap[tag] == null ? 1 : tagsMap[tag]! + 1; + } + final tagsMapList = tagsMap.entries.toList()..sort((a, b) => b.value.compareTo(a.value)); + return tagsMapList.map((e) => e.key).toList(); +} + +bool _areCategoriesContainsTag(WidgetTester wt, List<String> tags) { + final categoriesWithExamples = _getCategoriesWithExamples(wt); + final examples = categoriesWithExamples.expand((e) => e.examples); + + if (examples.isEmpty) { + return true; + } Review Comment: Delete or explain. ########## playground/frontend/playground_components/lib/src/repositories/code_repository.dart: ########## @@ -32,18 +32,28 @@ const kTimeoutErrorText = const kUnknownErrorText = 'Something went wrong. Please try again later or create a GitHub issue'; const kProcessingStartedText = 'The processing has started\n'; +const kProcessingStartedOptionsText = + 'The processing has started with pipeline options: '; Review Comment: ```suggestion 'The processing has been started with the pipeline options: '; ``` ########## playground/frontend/integration_test/standalone_cancel_running_example_test.dart: ########## @@ -0,0 +1,68 @@ +/* + * 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/playground_components.dart'; +import 'package:playground_components_dev/playground_components_dev.dart'; + +import 'common/common.dart'; + +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() + .snippetEditingController + ?.activeFileController + ?.codeController + .fullText ?? + ''; + 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()); + try { + await wt.pumpAndSettle( + const Duration(milliseconds: 100), + EnginePhase.sendSemanticsUpdate, + duration, + ); + } catch (e) { + //ignore Review Comment: Explain. ########## playground/frontend/integration_test/standalone_change_pipeline_options_and_run_test.dart: ########## @@ -0,0 +1,152 @@ +/* + * 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/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:integration_test/integration_test.dart'; +import 'package:playground/modules/editor/components/pipeline_options_dropdown/pipeline_options_dropdown_body.dart'; +import 'package:playground/modules/editor/components/pipeline_options_dropdown/pipeline_options_dropdown_input.dart'; +import 'package:playground/modules/editor/components/pipeline_options_dropdown/pipeline_options_text_field.dart'; +import 'package:playground_components/playground_components.dart'; +import 'package:playground_components_dev/playground_components_dev.dart'; + +import 'common/common.dart'; +import 'common/common_finders.dart'; + +void main() { + IntegrationTestWidgetsFlutterBinding.ensureInitialized(); + + testWidgets( + 'Changing pipeline options and press run', + (WidgetTester wt) async { + await init(wt); + + await wt.tapAndSettle(find.appDropdownButtonWithText('Pipeline Options')); + + await _addTwoOptions(wt); + + await wt.tapAndSettle(find.pipelineOptionsRawTab()); + + _checkIfRawTextCorrect('--some test --some2 test2'); + + await wt.tapAndSettle(find.pipelineOptionsListTab()); + + await wt.tap(_getBottomDeleteIcon(wt)); + + await wt.tapAndSettle(find.pipelineOptionsRawTab()); + + _checkIfRawTextCorrect('--some test'); + + await wt.tapAndSettle(find.pipelineOptionsSaveAndCloseButton()); + + await wt.tap(find.runOrCancelButton()); + await Future.delayed(const Duration(milliseconds: 300)); + + await wt.tapAndSettle(find.runOrCancelButton()); + + final playgroundController = wt.findPlaygroundController(); + expect( + playgroundController.codeRunner.resultLogOutput, + contains('--some test'), + ); + expect( + playgroundController.codeRunner.resultLogOutput, + contains(kExecutionCancelledText), + ); + }, + ); +} + +Future<void> _addTwoOptions(WidgetTester wt) async { + await wt.enterText( + _getPipelineOptionsTextField(wt, _Placement.topLeft), + 'some', + ); + await wt.enterText( + _getPipelineOptionsTextField(wt, _Placement.topRight), + 'test', + ); + + await wt.tap(find.byKey(PipelineOptionsDropdownBody.addOptionButtonKey)); + await wt.pumpAndSettle(); + + await wt.enterText( + _getPipelineOptionsTextField(wt, _Placement.bottomLeft), + 'some2', + ); + await wt.enterText( + _getPipelineOptionsTextField(wt, _Placement.bottomRight), + 'test2', + ); +} + +Finder _getPipelineOptionsTextField(WidgetTester wt, _Placement placement) { + final fields = find.byType(PipelineOptionsTextField); + final positions = <_Point>[]; + for (var i = 0; i < fields.evaluate().length; i++) { + final element = fields.at(i); + final position = wt.getCenter(element); + positions.add(_Point(position.dx, position.dy)); + } + + late _Point Function(_Point, _Point) reduceFunc; + switch (placement) { + case _Placement.topLeft: + reduceFunc = (a, b) => a.x <= b.x && a.y <= b.y ? a : b; + break; + case _Placement.topRight: + reduceFunc = (a, b) => a.x >= b.x && a.y <= b.y ? a : b; + break; + case _Placement.bottomLeft: + reduceFunc = (a, b) => a.x <= b.x && a.y >= b.y ? a : b; + break; + case _Placement.bottomRight: + reduceFunc = (a, b) => a.x >= b.x && a.y >= b.y ? a : b; + break; + } Review Comment: Check if there is a line widget. Create one if not. Make a function that returns a row widget by index. Then look for a text field in that row at index `0` or `1`. ########## playground/frontend/integration_test/standalone_change_pipeline_options_and_run_test.dart: ########## @@ -0,0 +1,152 @@ +/* + * 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/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:integration_test/integration_test.dart'; +import 'package:playground/modules/editor/components/pipeline_options_dropdown/pipeline_options_dropdown_body.dart'; +import 'package:playground/modules/editor/components/pipeline_options_dropdown/pipeline_options_dropdown_input.dart'; +import 'package:playground/modules/editor/components/pipeline_options_dropdown/pipeline_options_text_field.dart'; +import 'package:playground_components/playground_components.dart'; +import 'package:playground_components_dev/playground_components_dev.dart'; + +import 'common/common.dart'; +import 'common/common_finders.dart'; + +void main() { + IntegrationTestWidgetsFlutterBinding.ensureInitialized(); + + testWidgets( + 'Changing pipeline options and press run', + (WidgetTester wt) async { + await init(wt); + + await wt.tapAndSettle(find.appDropdownButtonWithText('Pipeline Options')); Review Comment: ```suggestion await wt.openPipelineOptions(); ``` ? ########## playground/frontend/integration_test/standalone_editing_test.dart: ########## @@ -0,0 +1,145 @@ +/* + * 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/material.dart'; +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 'common/common_finders.dart'; + +void main() { + IntegrationTestWidgetsFlutterBinding.ensureInitialized(); + + testWidgets('Testing editing code', (WidgetTester wt) async { + await init(wt); + await _checkResetDefaultCode(wt); + await _checkResetEditedCode(wt); + await _checkAutocomplete(wt); + await _checkCodeHighlightedMultipleColors(wt); + await _checkCodeBlockFolding(wt); + }); +} + +Future<void> _checkAutocomplete(WidgetTester wt) async { + await wt.enterText(find.codeField(), '\n\n\n\n\nsdk'); Review Comment: Explain. ########## playground/frontend/integration_test/standalone_editing_test.dart: ########## @@ -0,0 +1,145 @@ +/* + * 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/material.dart'; +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 'common/common_finders.dart'; + +void main() { + IntegrationTestWidgetsFlutterBinding.ensureInitialized(); + + testWidgets('Testing editing code', (WidgetTester wt) async { + await init(wt); + await _checkResetDefaultCode(wt); + await _checkResetEditedCode(wt); + await _checkAutocomplete(wt); + await _checkCodeHighlightedMultipleColors(wt); + await _checkCodeBlockFolding(wt); + }); +} + +Future<void> _checkAutocomplete(WidgetTester wt) async { + await wt.enterText(find.codeField(), '\n\n\n\n\nsdk'); + + final playgroundController = wt.findPlaygroundController(); + await wt.runShortcut( + playgroundController.showAutocompleterShortcut.shortcuts.keys); + await wt.pumpAndSettle(); + + expect(find.text('sdkHttpMetadata'), findsOneWidget); + expect(find.text('sdkHttpMetadataWithoutHeaders'), findsOneWidget); + expect(find.text('sdkHttpResponse'), findsOneWidget); + expect(find.text('sdkHttpResponseWithoutHeaders'), findsOneWidget); + + await wt.tapAndSettle(find.resetButton()); +} + +Future<void> _checkResetDefaultCode(WidgetTester wt) async { + final playgroundController = wt.findPlaygroundController(); + + final code = playgroundController.source; + + expect(code, isNotNull); + + await wt.tapAndSettle(find.resetButton()); + + expect(playgroundController.source, code); +} + +Future<void> _checkResetEditedCode(WidgetTester wt) async { + final playgroundController = wt.findPlaygroundController(); + final code = playgroundController.source; + + await wt.enterText(find.codeField(), 'print("Hello World!'); + await wt.pumpAndSettle(); + + expect(playgroundController.source, isNot(code)); + + await wt.tapAndSettle(find.resetButton()); + + expect(playgroundController.source, code); +} + +Future<void> _checkCodeHighlightedMultipleColors(WidgetTester wt) async { + final codeController = wt.findOneCodeController(); + final colors = <Color>{}; + var textSpan = codeController.lastTextSpan; + _collectTextSpanTreeTextColors(textSpan, colors); + + expect(colors.length, greaterThan(1)); +} + +void _collectTextSpanTreeTextColors(InlineSpan? span, Set<Color> colors) { + if (span is TextSpan) { + if (span.style?.color != null) { + colors.add(span.style!.color!); + } + if (span.children != null) { + for (final child in span.children!) { + _collectTextSpanTreeTextColors(child, colors); + } + } + } +} + +Future<void> _checkCodeBlockFolding(WidgetTester wt) async { + const code = ''' +public class MyClass { + public static void main(String[] args) { + System.out.print("Hello World!"); + } +} +'''; + + await wt.enterText(find.codeField(), code); + await wt.pumpAndSettle(); + + await wt.tapAndSettle(_getTopToggle(wt)); + + const foldedCode = ''' +public class MyClass { +'''; + + expect(wt.findOneCodeController().text, foldedCode); + + await wt.tapAndSettle(_getFoldToggles()); + + expect(wt.findOneCodeController().text, code); +} + +Finder _getTopToggle(WidgetTester wt) { Review Comment: ```suggestion Finder _getToggle(int iconIndex, WidgetTester wt) { ``` Make a general finder that returns the `n`th item by its coordinates. It accepts 3 parameters: 1. The previous finder. 2. The index. 3. `Axis`. ########## playground/frontend/integration_test/standalone_example_selector_test.dart: ########## @@ -0,0 +1,174 @@ +/* + * 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/modules/examples/components/example_list/example_item_actions.dart'; +import 'package:playground/modules/examples/components/filter/tag_bubble.dart'; +import 'package:playground/modules/examples/components/filter/type_bubble.dart'; +import 'package:playground/modules/examples/components/search_field/search_field.dart'; +import 'package:playground/modules/examples/examples_dropdown_content.dart'; +import 'package:playground/pages/standalone_playground/notifiers/example_selector_state.dart'; +import 'package:playground_components/playground_components.dart'; +import 'package:playground_components_dev/playground_components_dev.dart'; +import 'package:provider/provider.dart'; + +import 'common/common.dart'; +import 'common/common_finders.dart'; + +void main() { + IntegrationTestWidgetsFlutterBinding.ensureInitialized(); + + testWidgets('Example selector test', (WidgetTester wt) async { + await init(wt); + await _checkFilteringExamplesByTypes(wt); + await _checkFilteringExamplesByTags(wt); + await _checkFilteringExamplesBySearchString(wt); + await _checkViewDescription(wt); + }); +} + +Future<void> _checkFilteringExamplesByTypes(WidgetTester wt) async { + await wt.tapAndSettle(find.exampleSelector()); + final allExamplesCount = _getExamplesCount(wt); + await wt.tapAndSettle(find.widgetWithText(TypeBubble, ExampleType.test.name)); + + final filteredExamplesCount = _getExamplesCount(wt); + + expect(allExamplesCount, isNot(filteredExamplesCount)); Review Comment: Unnecessary. ########## playground/frontend/integration_test/standalone_example_selector_test.dart: ########## @@ -0,0 +1,174 @@ +/* + * 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/modules/examples/components/example_list/example_item_actions.dart'; +import 'package:playground/modules/examples/components/filter/tag_bubble.dart'; +import 'package:playground/modules/examples/components/filter/type_bubble.dart'; +import 'package:playground/modules/examples/components/search_field/search_field.dart'; +import 'package:playground/modules/examples/examples_dropdown_content.dart'; +import 'package:playground/pages/standalone_playground/notifiers/example_selector_state.dart'; +import 'package:playground_components/playground_components.dart'; +import 'package:playground_components_dev/playground_components_dev.dart'; +import 'package:provider/provider.dart'; + +import 'common/common.dart'; +import 'common/common_finders.dart'; + +void main() { + IntegrationTestWidgetsFlutterBinding.ensureInitialized(); + + testWidgets('Example selector test', (WidgetTester wt) async { + await init(wt); + await _checkFilteringExamplesByTypes(wt); + await _checkFilteringExamplesByTags(wt); + await _checkFilteringExamplesBySearchString(wt); + await _checkViewDescription(wt); + }); +} + +Future<void> _checkFilteringExamplesByTypes(WidgetTester wt) async { + await wt.tapAndSettle(find.exampleSelector()); + final allExamplesCount = _getExamplesCount(wt); + await wt.tapAndSettle(find.widgetWithText(TypeBubble, ExampleType.test.name)); + + final filteredExamplesCount = _getExamplesCount(wt); + + expect(allExamplesCount, isNot(filteredExamplesCount)); + + final categoriesWithExamples = _getCategoriesWithExamples(wt); + for (final example in categoriesWithExamples.expand((e) => e.examples)) { + expect(example.type, ExampleType.test); + } + + await wt.tapAndSettle(find.exampleSelector()); +} + +Future<void> _checkFilteringExamplesByTags(WidgetTester wt) async { + await wt.tapAndSettle(find.exampleSelector()); + + final allExamplesCount = _getExamplesCount(wt); + final sortedTags = _getSortedTags(wt); + await wt.tapAndSettle(find.widgetWithText(TagBubble, sortedTags[0])); + final filteredExamplesCount = _getExamplesCount(wt); + + expect(_areCategoriesContainsTag(wt, [sortedTags[0]]), isTrue); + expect(allExamplesCount, isNot(filteredExamplesCount)); + + await wt.tapAndSettle(find.widgetWithText(TagBubble, sortedTags[1])); + final nextFilteredExamplesCount = _getExamplesCount(wt); + + expect(_areCategoriesContainsTag(wt, [sortedTags[0], sortedTags[1]]), isTrue); + expect(filteredExamplesCount, isNot(nextFilteredExamplesCount)); + + await wt.tapAndSettle(find.exampleSelector()); +} + +List<String> _getSortedTags(WidgetTester wt) { + final categoriesWithExamples = _getCategoriesWithExamples(wt); + final tags = categoriesWithExamples + .expand((e) => e.examples) + .expand((e) => e.tags); + final tagsMap = <String, int>{}; + for (final tag in tags) { + tagsMap[tag] = tagsMap[tag] == null ? 1 : tagsMap[tag]! + 1; + } + final tagsMapList = tagsMap.entries.toList()..sort((a, b) => b.value.compareTo(a.value)); + return tagsMapList.map((e) => e.key).toList(); Review Comment: ```suggestion return tagsMapList.keys.toList(); ``` ########## playground/frontend/integration_test/standalone_example_selector_test.dart: ########## @@ -0,0 +1,174 @@ +/* + * 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/modules/examples/components/example_list/example_item_actions.dart'; +import 'package:playground/modules/examples/components/filter/tag_bubble.dart'; +import 'package:playground/modules/examples/components/filter/type_bubble.dart'; +import 'package:playground/modules/examples/components/search_field/search_field.dart'; +import 'package:playground/modules/examples/examples_dropdown_content.dart'; +import 'package:playground/pages/standalone_playground/notifiers/example_selector_state.dart'; +import 'package:playground_components/playground_components.dart'; +import 'package:playground_components_dev/playground_components_dev.dart'; +import 'package:provider/provider.dart'; + +import 'common/common.dart'; +import 'common/common_finders.dart'; + +void main() { + IntegrationTestWidgetsFlutterBinding.ensureInitialized(); + + testWidgets('Example selector test', (WidgetTester wt) async { + await init(wt); + await _checkFilteringExamplesByTypes(wt); + await _checkFilteringExamplesByTags(wt); + await _checkFilteringExamplesBySearchString(wt); + await _checkViewDescription(wt); + }); +} + +Future<void> _checkFilteringExamplesByTypes(WidgetTester wt) async { + await wt.tapAndSettle(find.exampleSelector()); + final allExamplesCount = _getExamplesCount(wt); + await wt.tapAndSettle(find.widgetWithText(TypeBubble, ExampleType.test.name)); + + final filteredExamplesCount = _getExamplesCount(wt); + + expect(allExamplesCount, isNot(filteredExamplesCount)); + + final categoriesWithExamples = _getCategoriesWithExamples(wt); + for (final example in categoriesWithExamples.expand((e) => e.examples)) { + expect(example.type, ExampleType.test); + } + + await wt.tapAndSettle(find.exampleSelector()); +} + +Future<void> _checkFilteringExamplesByTags(WidgetTester wt) async { + await wt.tapAndSettle(find.exampleSelector()); + + final allExamplesCount = _getExamplesCount(wt); + final sortedTags = _getSortedTags(wt); + await wt.tapAndSettle(find.widgetWithText(TagBubble, sortedTags[0])); + final filteredExamplesCount = _getExamplesCount(wt); + + expect(_areCategoriesContainsTag(wt, [sortedTags[0]]), isTrue); + expect(allExamplesCount, isNot(filteredExamplesCount)); + + await wt.tapAndSettle(find.widgetWithText(TagBubble, sortedTags[1])); + final nextFilteredExamplesCount = _getExamplesCount(wt); + + expect(_areCategoriesContainsTag(wt, [sortedTags[0], sortedTags[1]]), isTrue); + expect(filteredExamplesCount, isNot(nextFilteredExamplesCount)); + + await wt.tapAndSettle(find.exampleSelector()); +} + +List<String> _getSortedTags(WidgetTester wt) { + final categoriesWithExamples = _getCategoriesWithExamples(wt); + final tags = categoriesWithExamples + .expand((e) => e.examples) + .expand((e) => e.tags); + final tagsMap = <String, int>{}; + for (final tag in tags) { + tagsMap[tag] = tagsMap[tag] == null ? 1 : tagsMap[tag]! + 1; Review Comment: ```suggestion tagsMap[tag] = (tagsMap[tag] ?? 0) + 1; ``` Also change this line in the widget. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
