-
Notifications
You must be signed in to change notification settings - Fork 1
Support new showWidget and hideWidget events #157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,3 +32,4 @@ CLAUDE.md | |
| .swiftpm/ | ||
| **/Flutter/ephemeral/ | ||
| **/xcshareddata/swiftpm/ | ||
| ios/didomi_sdk/Package.resolved | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| import 'dart:io'; | ||
|
|
||
| import 'package:didomi_sdk/didomi_sdk.dart'; | ||
| import 'package:didomi_sdk/events/event_listener.dart'; | ||
| import 'package:didomi_sdk/events/show_widget_event.dart'; | ||
| import 'package:didomi_sdk_example/testapps/sample_for_notice_tests.dart' as app; | ||
| import 'package:flutter/cupertino.dart'; | ||
| import 'package:flutter_test/flutter_test.dart'; | ||
| import 'package:integration_test/integration_test.dart'; | ||
|
|
||
| import 'util/initialize_helper.dart'; | ||
|
|
||
| /// Coverage note: | ||
| /// | ||
| /// onShowWidget / onHideWidget are emitted by the Web SDK from inside a | ||
| /// WebView-rendered experience. The notice served by this example app's | ||
| /// configuration is natively rendered and contains no widget, and there is no | ||
| /// Dart-side API to trigger a widget, so real widget event delivery cannot be | ||
| /// produced here. | ||
| /// | ||
| /// This test therefore covers what is verifiable automatically: | ||
| /// - the new listener fields exist, are assignable and are accepted by | ||
| /// addEventListener; | ||
| /// - registering them does not disturb the normal event flow (onReady still | ||
| /// fires, no error is reported); | ||
| /// - no widget event is spuriously emitted against a non-widget config, which | ||
| /// would indicate a wire-string or dispatch mistake; | ||
| /// - both native handlers still build and register — a missing Kotlin override | ||
| /// or a Swift typo regresses here. | ||
| /// | ||
| /// Asserting a real onShowWidget payload requires a Didomi configuration whose | ||
| /// experience is web-rendered and serves a widget. See the manual verification | ||
| /// steps in the pull request description. | ||
| void main() { | ||
| IntegrationTestWidgetsFlutterBinding.ensureInitialized(); | ||
|
|
||
| final initializeBtnFinder = find.byKey(Key("initializeSmall")); | ||
| final setupUIBtnFinder = find.byKey(Key("setupUI")); | ||
| final showNoticeBtnFinder = find.byKey(Key("showNotice")); | ||
|
|
||
| bool isError = false; | ||
| bool isReady = false; | ||
| bool widgetWasShown = false; | ||
| bool widgetWasHidden = false; | ||
| ShowWidgetEvent? lastShowWidgetEvent; | ||
|
|
||
| final listener = EventListener(); | ||
| listener.onError = (String message) { | ||
| isError = true; | ||
| }; | ||
| listener.onReady = () { | ||
| isReady = true; | ||
| }; | ||
| listener.onShowWidget = (ShowWidgetEvent event) { | ||
| widgetWasShown = true; | ||
| lastShowWidgetEvent = event; | ||
| }; | ||
| listener.onHideWidget = () { | ||
| widgetWasHidden = true; | ||
| }; | ||
|
|
||
| DidomiSdk.addEventListener(listener); | ||
|
|
||
| group("Widget events", () { | ||
| testWidgets("No widget event before initialization", (WidgetTester tester) async { | ||
| // Start app | ||
| app.main(); | ||
| await tester.pumpAndSettle(); | ||
|
|
||
| assert(isError == false); | ||
| assert(isReady == false); | ||
| assert(widgetWasShown == false); | ||
| assert(widgetWasHidden == false); | ||
| assert(lastShowWidgetEvent == null); | ||
| }); | ||
|
|
||
| testWidgets("Widget event listeners do not disrupt the event flow", (WidgetTester tester) async { | ||
| // Start app | ||
| app.main(); | ||
| await tester.pumpAndSettle(); | ||
|
|
||
| await InitializeHelper.initialize(tester, initializeBtnFinder); | ||
|
|
||
| assert(isError == false); | ||
| assert(isReady == true); | ||
|
|
||
| if (Platform.isIOS) { | ||
| await tester.tap(setupUIBtnFinder); | ||
| await tester.pumpAndSettle(); | ||
| } | ||
|
|
||
| await tester.tap(showNoticeBtnFinder); | ||
| await tester.pumpAndSettle(); | ||
|
|
||
| // Events coming from the native SDK are not flushed by pumpAndSettle. | ||
| await Future.delayed(Duration(seconds: 1)); | ||
|
|
||
| // The notice served by this config is native and holds no widget, | ||
| // so no widget event must have been emitted. | ||
| assert(isError == false); | ||
| assert(widgetWasShown == false); | ||
| assert(widgetWasHidden == false); | ||
| assert(lastShowWidgetEvent == null); | ||
| }); | ||
| }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| /** A widget was displayed. */ | ||
| class ShowWidgetEvent { | ||
| // Identifier of the widget that was displayed, as resolved by the Rules Engine | ||
| String? widgetId; | ||
|
|
||
| // Name of the layer at which the widget was displayed | ||
| String? layerName; | ||
|
|
||
| ShowWidgetEvent(this.widgetId, this.layerName); | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.