-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[cross_file] [web] Separate "Save As" implementation details from XFile web class #10396
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
[cross_file] [web] Separate "Save As" implementation details from XFile web class #10396
Conversation
…le web class - resolve #91400
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request refactors the "Save As" functionality for the web implementation by moving it from the XFile class into a dedicated helper file. This is a positive change that improves separation of concerns and makes the XFile class cleaner. My review includes suggestions to enhance the new testing mechanism to prevent test pollution and a minor code simplification for better maintainability.
| helpers.anchorElementOverride = (_, __) => mockAnchor; | ||
|
|
||
| final XFile file = XFile.fromData( | ||
| bytes, | ||
| name: textFile.name, | ||
| overrides: overrides, | ||
| ); | ||
| final XFile file = XFile.fromData(bytes, name: textFile.name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Modifying a global variable (helpers.anchorElementOverride) in a test can lead to test pollution, where one test's state affects another. It's crucial to clean up this state after the test runs. You can use addTearDown to ensure the override is reset.
Additionally, the test may create a DOM element that should also be cleaned up to prevent side effects between tests.
addTearDown(() {
helpers.anchorElementOverride = null;
html.document.querySelector('#$crossFileDomElementId')?.remove();
});
helpers.anchorElementOverride = (_, __) => mockAnchor;
final XFile file = XFile.fromData(bytes, name: textFile.name);| /// Override for creating anchor elements for testing purposes | ||
| CreateAnchorElement? anchorElementOverride; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using a global variable for testing can lead to test pollution. It's good practice to:
- Annotate it with
@visibleForTestingto signal its intended use. This requires importingpackage:meta/meta.dartat the top of the file. - Add a comment reminding developers to clean it up in their tests using
tearDownoraddTearDown.
/// Override for creating anchor elements for testing purposes.
///
/// This should be reset to `null` in a `tearDown` block to avoid test pollution.
@visibleForTesting
CreateAnchorElement? anchorElementOverride;| while (target.children.length > 0) { | ||
| target.removeChild(target.children.item(0)!); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixes #91400
Replace this paragraph with a description of what this PR is changing or adding, and why. Consider including before/after screenshots.
List which issues are fixed by this PR. You must list at least one issue.
Pre-Review Checklist
[shared_preferences]pubspec.yamlwith an appropriate new version according to the [pub versioning philosophy], or I have commented below to indicate which [version change exemption] this PR falls under[^1].CHANGELOG.mdto add a description of the change, [following repository CHANGELOG style], or I have commented below to indicate which [CHANGELOG exemption] this PR falls under[^1].///).