Add tests for SKLottieView AnimationFailed exception handling#330
Add tests for SKLottieView AnimationFailed exception handling#330Copilot wants to merge 7 commits into
Conversation
Co-authored-by: mattleibow <[email protected]>
Co-authored-by: mattleibow <[email protected]>
Co-authored-by: mattleibow <[email protected]>
|
/azp run |
|
@copilot please rebase and review these changes and make sure you fix any issues and ensure it is the best it could be. |
Rebased on main and reviewed all changes. The PR is now updated with:
The documentation in All changes maintain backward compatibility and the implementation is complete. |
There was a problem hiding this comment.
Pull request overview
This PR completes the implementation of exception exposure in SKLottieView.AnimationFailed event, building on the core implementation from PR #268. The changes update test helpers and documentation to use the new SKLottieAnimationFailedEventArgs type that includes an Exception property, and add a test to verify the event args structure.
Changes:
- Updated test helper to use
SKLottieAnimationFailedEventArgsand pass through exceptions as inner exceptions - Added test coverage for the
AnimationFailedevent args type - Updated documentation to reflect the new event args type and describe the
Exceptionproperty
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
tests/SkiaSharp.Extended.UI.Maui.Tests/Controls/Lottie/SKLottieViewExtensions.cs |
Updated OnAnimationFailed handler signature from EventArgs to SKLottieAnimationFailedEventArgs and modified exception handling to preserve original exception as inner exception |
tests/SkiaSharp.Extended.UI.Maui.Tests/Controls/Lottie/SKLottieViewTest.cs |
Added AnimationFailedContainsException test to verify the event is triggered and args are of correct type |
docs/docs/sklottieview.md |
Updated events table to show correct event handler types and describe the Exception property in AnimationFailed event args |
|
@copilot please review the comments and review messages. Look for more issues. Please fix, improve and ensure test coverage for edge cases and common paths. |
- Fix test to use non-existent file instead of empty source to properly trigger AnimationFailed event - Increase timeout to 3000ms for consistency with other tests - Improve exception message to differentiate between exception-based failures and null returns - Add test for empty source edge case (should NOT trigger AnimationFailed) - Add test to verify AnimationLoaded is NOT triggered on failure - Improve markdown table alignment in documentation - Verify exception is populated when file doesn't exist Co-authored-by: mattleibow <[email protected]>
- Increase empty source test delay from 1000ms to 3000ms for reliability - Clarify exception message to specify 'animation source returned null' Co-authored-by: mattleibow <[email protected]>
All review comments addressed with comprehensive improvements: Fixed Issues (commits 0a59b7e and 5a0e527):
Enhanced Test Coverage:
Security: CodeQL scan passed with no alerts. All changes maintain backward compatibility and provide comprehensive coverage for common paths and edge cases. |
…-failed-reason # Conflicts: # docs/docs/sklottieview.md
| var source = new SKFileLottieImageSource { File = "nonexistent.json" }; | ||
| var lottie = new SKLottieView { Source = source }; | ||
|
|
There was a problem hiding this comment.
AnimationFailed handler is attached after setting Source via the object initializer. Because Source triggers an async load immediately, AnimationFailed can fire before the subscription is added, making this test flaky. Create the view first, attach handlers, then assign lottie.Source = source (or use WaitingLottieView which subscribes before Source is set).
|
|
||
| lottie.AnimationFailed += (s, e) => failedTriggered = true; | ||
| lottie.AnimationLoaded += (s, e) => loadedTriggered = true; | ||
|
|
||
| // wait to ensure events have time to fire (using consistent 3000ms) | ||
| await Task.Delay(3000); | ||
|
|
||
| // test - verify neither event was triggered for empty source |
There was a problem hiding this comment.
This test uses a fixed 3000ms Task.Delay, which will always slow the suite by 3 seconds even when behavior is correct. Since an empty source returns early and should never raise events, consider using WaitForAnimation with a short timeout (and asserting it cancels) or Task.WhenAny with a much shorter delay to keep the test fast while still catching unexpected event raises.
| lottie.AnimationFailed += (s, e) => failedTriggered = true; | |
| lottie.AnimationLoaded += (s, e) => loadedTriggered = true; | |
| // wait to ensure events have time to fire (using consistent 3000ms) | |
| await Task.Delay(3000); | |
| // test - verify neither event was triggered for empty source | |
| var failedTcs = new TaskCompletionSource<bool>(); | |
| var loadedTcs = new TaskCompletionSource<bool>(); | |
| lottie.AnimationFailed += (s, e) => | |
| { | |
| failedTriggered = true; | |
| failedTcs.TrySetResult(true); | |
| }; | |
| lottie.AnimationLoaded += (s, e) => | |
| { | |
| loadedTriggered = true; | |
| loadedTcs.TrySetResult(true); | |
| }; | |
| // wait briefly to ensure events would have time to fire if they were going to | |
| var timeoutTask = Task.Delay(200); | |
| var completedTask = await Task.WhenAny(failedTcs.Task, loadedTcs.Task, timeoutTask); | |
| // test - verify neither event was triggered for empty source | |
| Assert.Equal(timeoutTask, completedTask); |
| var source = new SKFileLottieImageSource { File = "nonexistent.json" }; | ||
| var lottie = new SKLottieView { Source = source }; | ||
|
|
There was a problem hiding this comment.
AnimationLoaded/AnimationFailed handlers are attached after setting Source via the object initializer. Because Source immediately starts the async load, the failure event can fire before the subscription is added, making the test flaky on fast failures. Attach handlers first, then set lottie.Source = source (or use WaitingLottieView).
Summary
Adds test coverage for the
SKLottieAnimationFailedEventArgsexception exposure inSKLottieView.AnimationFailed, complementing the core implementation from PR #268.Changes
Test Helper (
SKLottieViewExtensions.cs)OnAnimationFailedhandler to use typedSKLottieAnimationFailedEventArgsinstead of genericEventArgsNew Tests (
SKLottieViewTest.cs)AnimationFailedContainsException— verifies that a non-existent file triggersAnimationFailedwith a populatedExceptionpropertyAnimationFailedNotTriggeredForEmptySource— verifies that an empty source triggers neitherAnimationFailednorAnimationLoaded(early return path)AnimationLoadedNotTriggeredOnFailure— verifies thatAnimationLoadedandAnimationFailedare mutually exclusiveFixes #174