Wizard: Filter out empty users from review step (HMS-10691)#4444
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. @@ Coverage Diff @@
## main #4444 +/- ##
=======================================
Coverage 74.76% 74.77%
=======================================
Files 229 229
Lines 7612 7614 +2
Branches 2867 2872 +5
=======================================
+ Hits 5691 5693 +2
Misses 1653 1653
Partials 268 268
... and 1 file with indirect coverage changes Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- The
nonEmptyUsersfilter treats any non-empty string as valid; consider trimmingname,password, andssh_keyso users with only whitespace are still considered empty and excluded from the review. - The logic that defines what constitutes a non-empty user is now embedded in the component; consider extracting this predicate into a shared helper or selector to keep the definition centralized and reusable across the app.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The `nonEmptyUsers` filter treats any non-empty string as valid; consider trimming `name`, `password`, and `ssh_key` so users with only whitespace are still considered empty and excluded from the review.
- The logic that defines what constitutes a non-empty user is now embedded in the component; consider extracting this predicate into a shared helper or selector to keep the definition centralized and reusable across the app.
## Individual Comments
### Comment 1
<location path="src/Components/CreateImageWizard/steps/Review/components/AdvancedSettings/tests/AdvancedSettings.test.tsx" line_range="729-748" />
<code_context>
expect(screen.queryByText('Users')).not.toBeInTheDocument();
});
+ test('does not render users section when only empty users exist', () => {
+ renderWithRedux(
+ <AdvancedSettingsOverview restrictions={createDefaultRestrictions()} />,
+ {
+ imageTypes: ['guest-image'],
+ users: [
+ {
+ name: '',
+ password: '',
+ hasPassword: false,
+ ssh_key: '',
+ groups: [],
+ isAdministrator: false,
+ },
+ ],
+ },
+ );
+
+ expect(screen.queryByText('Users')).not.toBeInTheDocument();
+ });
+
</code_context>
<issue_to_address>
**suggestion (testing):** Add a test case where both empty and non-empty users are present to ensure only non-empty users are rendered and the section still appears.
This test covers the case with only empty users. To more fully exercise the filtering logic, please add a complementary test with a mix of empty and non-empty users that asserts the Users section is rendered and only the non-empty users are shown (e.g., by checking the rendered row count and usernames).
```suggestion
test('does not render users section when only empty users exist', () => {
renderWithRedux(
<AdvancedSettingsOverview restrictions={createDefaultRestrictions()} />,
{
imageTypes: ['guest-image'],
users: [
{
name: '',
password: '',
hasPassword: false,
ssh_key: '',
groups: [],
isAdministrator: false,
},
],
},
);
expect(screen.queryByText('Users')).not.toBeInTheDocument();
});
test('renders users section with only non-empty users when mix of users is provided', () => {
renderWithRedux(
<AdvancedSettingsOverview restrictions={createDefaultRestrictions()} />,
{
imageTypes: ['guest-image'],
users: [
{
// empty user that should be filtered out
name: '',
password: '',
hasPassword: false,
ssh_key: '',
groups: [],
isAdministrator: false,
},
{
// non-empty user that should be rendered
name: 'regular-user',
password: '',
hasPassword: false,
ssh_key: '',
groups: [],
isAdministrator: false,
},
],
},
);
expect(screen.getByText('Users')).toBeInTheDocument();
expect(screen.getByText('regular-user')).toBeInTheDocument();
// Ensure no extra non-empty usernames are rendered
expect(screen.getAllByText('regular-user')).toHaveLength(1);
});
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
e413958 to
80c59bc
Compare
Collaborator
kingsleyzissou
left a comment
There was a problem hiding this comment.
One minor comment, but this looks great
| return state.wizard.users; | ||
| }; | ||
|
|
||
| export const selectNonEmptyUsers = (state: RootState) => { |
When a user was added and then removed, an empty user object remained in the Redux store. The review step displayed it because it only checked users.length === 0, showing a blank row with no meaningful data. Filter out users that have no name, password, SSH key, or stored password before rendering the review section.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
When a user was added and then removed, an empty user object remained in the Redux store.
The review step displayed it because it only checked users.length === 0, showing a blank row with no meaningful data.
Filter out users that have no name, password, SSH key, or stored password before rendering the review section.
ISSUE IN GITHUB: 4423
JIRA: 4423