-
Notifications
You must be signed in to change notification settings - Fork 377
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
[ui-storagebrowser] adds change owner and group action #3973
Merged
+602
−5
Merged
Changes from 1 commit
Commits
Show all changes
4 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
Next
Next commit
[ui-storagebrowser] adds change owner and group action
commit 9ea68e261b48f71ab4b5d9f4c0caf7f331d68323
There are no files selected for viewing
This file contains 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
59 changes: 59 additions & 0 deletions
59
...irectoryPage/StorageBrowserActions/ChangeOwnerAndGroupModal/ChangeOwnerAndGroupModal.scss
This file contains 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,59 @@ | ||
// Licensed to Cloudera, Inc. under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. Cloudera, Inc. 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. | ||
|
||
@use 'variables' as vars; | ||
|
||
.antd.cuix { | ||
.change-owner-group { | ||
display: flex; | ||
flex-direction: column; | ||
flex: 1; | ||
gap: 8px; | ||
|
||
&__header-note { | ||
padding: 8px; | ||
background-color: vars.$fluidx-gray-200; | ||
margin-bottom: 8px; | ||
} | ||
|
||
&__form { | ||
display: flex; | ||
flex-direction: column; | ||
flex: 1; | ||
gap: 16px; | ||
} | ||
|
||
&__entity { | ||
display: flex; | ||
flex-direction: column; | ||
} | ||
|
||
&__dropdown { | ||
display: grid; | ||
grid-template-columns: 1fr 1fr; | ||
grid-gap: 8px; | ||
} | ||
|
||
&__checkbox { | ||
display: flex; | ||
gap: 8px; | ||
} | ||
|
||
&__label { | ||
color: vars.$fluidx-gray-700; | ||
} | ||
} | ||
} |
297 changes: 297 additions & 0 deletions
297
...toryPage/StorageBrowserActions/ChangeOwnerAndGroupModal/ChangeOwnerAndGroupModal.test.tsx
This file contains 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,297 @@ | ||
// Licensed to Cloudera, Inc. under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. Cloudera, Inc. 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 React from 'react'; | ||
import { render, fireEvent, waitFor } from '@testing-library/react'; | ||
import '@testing-library/jest-dom'; | ||
import userEvent from '@testing-library/user-event'; | ||
import ChangeOwnerAndGroupModal from './ChangeOwnerAndGroupModal'; | ||
import { StorageDirectoryTableData } from '../../../../../reactComponents/FileChooser/types'; | ||
|
||
const mockFiles: StorageDirectoryTableData[] = [ | ||
{ | ||
name: 'file1.txt', | ||
size: '0 Byte', | ||
type: 'file', | ||
permission: 'rwxrwxrwx', | ||
mtime: '2021-01-01 00:00:00', | ||
path: 'test/path/file1.txt', | ||
user: 'user1', | ||
group: 'group1', | ||
replication: 1 | ||
} | ||
]; | ||
|
||
const mockSave = jest.fn(); | ||
jest.mock('../../../../../utils/hooks/useSaveData/useSaveData', () => ({ | ||
__esModule: true, | ||
default: jest.fn(() => ({ | ||
save: mockSave, | ||
loading: false | ||
})) | ||
})); | ||
|
||
const mockOnSuccess = jest.fn(); | ||
const mockOnError = jest.fn(); | ||
const mockOnClose = jest.fn(); | ||
|
||
const users = ['user1', 'user2', 'user3']; | ||
const groups = ['group1', 'group2', 'group3']; | ||
|
||
describe('ChangeOwnerAndGroupModal Component', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should render correctly and show the modal', () => { | ||
const { getByText } = render( | ||
<ChangeOwnerAndGroupModal | ||
isOpen={true} | ||
superUser="hadoop-superuser" | ||
superGroup="hdfs-supergroup" | ||
users={users} | ||
groups={groups} | ||
files={mockFiles} | ||
setLoading={jest.fn()} | ||
onSuccess={mockOnSuccess} | ||
onError={mockOnError} | ||
onClose={mockOnClose} | ||
/> | ||
); | ||
|
||
expect(getByText('Change Onwer / Group')).toBeInTheDocument(); | ||
expect(getByText('Submit')).toBeInTheDocument(); | ||
expect(getByText('Cancel')).toBeInTheDocument(); | ||
expect(getByText('User')).toBeInTheDocument(); | ||
expect(getByText('Group')).toBeInTheDocument(); | ||
expect(getByText('Recursive')).toBeInTheDocument(); | ||
expect( | ||
getByText( | ||
'Note: Only the Hadoop superuser, "{{superuser}}" or the HDFS supergroup, "{{supergroup}}" on this file system, may change the owner of a file.' | ||
) | ||
).toBeInTheDocument(); | ||
}); | ||
|
||
it('should show input fields for custom user when "Others" is selected', async () => { | ||
const { getAllByRole, getByText, getByPlaceholderText } = render( | ||
<ChangeOwnerAndGroupModal | ||
isOpen={true} | ||
superUser="hadoop-superuser" | ||
superGroup="hdfs-supergroup" | ||
users={users} | ||
groups={groups} | ||
files={mockFiles} | ||
setLoading={jest.fn()} | ||
onSuccess={mockOnSuccess} | ||
onError={mockOnError} | ||
onClose={mockOnClose} | ||
/> | ||
); | ||
|
||
const [userSelect] = getAllByRole('combobox'); | ||
|
||
await userEvent.click(userSelect); | ||
fireEvent.click(getByText('others')); | ||
fireEvent.change(userSelect, { target: { value: 'others' } }); | ||
|
||
const userInput = getByPlaceholderText('Enter user'); | ||
expect(userInput).toBeInTheDocument(); | ||
|
||
fireEvent.change(userInput, { target: { value: 'customUser' } }); | ||
expect(userInput).toHaveValue('customUser'); | ||
}); | ||
|
||
it('should show input fields for custom group when "Others" is selected', async () => { | ||
const { getAllByRole, getByText, getByPlaceholderText } = render( | ||
<ChangeOwnerAndGroupModal | ||
isOpen={true} | ||
superUser="hadoop-superuser" | ||
superGroup="hdfs-supergroup" | ||
users={users} | ||
groups={groups} | ||
files={mockFiles} | ||
setLoading={jest.fn()} | ||
onSuccess={mockOnSuccess} | ||
onError={mockOnError} | ||
onClose={mockOnClose} | ||
/> | ||
); | ||
|
||
const groupSelect = getAllByRole('combobox')[1]; | ||
|
||
await userEvent.click(groupSelect); | ||
fireEvent.click(getByText('others')); | ||
fireEvent.change(groupSelect, { target: { value: 'others' } }); | ||
|
||
const groupInput = getByPlaceholderText('Enter group'); | ||
expect(groupInput).toBeInTheDocument(); | ||
|
||
fireEvent.change(groupInput, { target: { value: 'customGroup' } }); | ||
expect(groupInput).toHaveValue('customGroup'); | ||
}); | ||
|
||
it('should toggle the recursive checkbox', () => { | ||
const { getByRole } = render( | ||
<ChangeOwnerAndGroupModal | ||
isOpen={true} | ||
superUser="hadoop-superuser" | ||
superGroup="hdfs-supergroup" | ||
users={users} | ||
groups={groups} | ||
files={mockFiles} | ||
setLoading={jest.fn()} | ||
onSuccess={mockOnSuccess} | ||
onError={mockOnError} | ||
onClose={mockOnClose} | ||
/> | ||
); | ||
|
||
const recursiveCheckbox = getByRole('checkbox'); | ||
expect(recursiveCheckbox).not.toBeChecked(); | ||
fireEvent.click(recursiveCheckbox); | ||
expect(recursiveCheckbox).toBeChecked(); | ||
fireEvent.click(recursiveCheckbox); | ||
expect(recursiveCheckbox).not.toBeChecked(); | ||
}); | ||
|
||
it('should call handleChangeOwner when the form is submitted', async () => { | ||
const { getByText } = render( | ||
<ChangeOwnerAndGroupModal | ||
isOpen={true} | ||
superUser="hadoop-superuser" | ||
superGroup="hdfs-supergroup" | ||
users={users} | ||
groups={groups} | ||
files={mockFiles} | ||
setLoading={jest.fn()} | ||
onSuccess={mockOnSuccess} | ||
onError={mockOnError} | ||
onClose={mockOnClose} | ||
/> | ||
); | ||
|
||
fireEvent.click(getByText('Submit')); | ||
|
||
await waitFor(() => { | ||
expect(mockSave).toHaveBeenCalledTimes(1); | ||
expect(mockSave).toHaveBeenCalledWith(expect.any(FormData)); | ||
}); | ||
}); | ||
|
||
it('should call onSuccess when the request is successful', async () => { | ||
mockSave.mockImplementationOnce(() => { | ||
mockOnSuccess(); | ||
}); | ||
|
||
const { getByText } = render( | ||
<ChangeOwnerAndGroupModal | ||
isOpen={true} | ||
superUser="hadoop-superuser" | ||
superGroup="hdfs-supergroup" | ||
users={users} | ||
groups={groups} | ||
files={mockFiles} | ||
setLoading={jest.fn()} | ||
onSuccess={mockOnSuccess} | ||
onError={mockOnError} | ||
onClose={mockOnClose} | ||
/> | ||
); | ||
|
||
fireEvent.click(getByText('Submit')); | ||
|
||
await waitFor(() => { | ||
expect(mockOnSuccess).toHaveBeenCalledTimes(1); | ||
}); | ||
}); | ||
|
||
it('should call onError when the request fails', async () => { | ||
mockSave.mockImplementationOnce(() => { | ||
mockOnError(new Error()); | ||
}); | ||
|
||
const { getByText } = render( | ||
<ChangeOwnerAndGroupModal | ||
isOpen={true} | ||
superUser="hadoop-superuser" | ||
superGroup="hdfs-supergroup" | ||
users={users} | ||
groups={groups} | ||
files={mockFiles} | ||
setLoading={jest.fn()} | ||
onSuccess={mockOnSuccess} | ||
onError={mockOnError} | ||
onClose={mockOnClose} | ||
/> | ||
); | ||
|
||
fireEvent.click(getByText('Submit')); | ||
|
||
await waitFor(() => { | ||
expect(mockOnError).toHaveBeenCalledTimes(1); | ||
}); | ||
}); | ||
|
||
it('should call onClose when the modal is closed', () => { | ||
const { getByText } = render( | ||
<ChangeOwnerAndGroupModal | ||
isOpen={true} | ||
superUser="hadoop-superuser" | ||
superGroup="hdfs-supergroup" | ||
users={users} | ||
groups={groups} | ||
files={mockFiles} | ||
setLoading={jest.fn()} | ||
onSuccess={mockOnSuccess} | ||
onError={mockOnError} | ||
onClose={mockOnClose} | ||
/> | ||
); | ||
|
||
fireEvent.click(getByText('Cancel')); | ||
expect(mockOnClose).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('should disable submit button when other option is selected and input not provided', async () => { | ||
const { getAllByRole, getAllByText, getByPlaceholderText, getByRole } = render( | ||
<ChangeOwnerAndGroupModal | ||
isOpen={true} | ||
superUser="hadoop-superuser" | ||
superGroup="hdfs-supergroup" | ||
users={users} | ||
groups={groups} | ||
files={mockFiles} | ||
setLoading={jest.fn()} | ||
onSuccess={mockOnSuccess} | ||
onError={mockOnError} | ||
onClose={mockOnClose} | ||
/> | ||
); | ||
|
||
const [userSelect] = getAllByRole('combobox'); | ||
|
||
await userEvent.click(userSelect); | ||
fireEvent.click(getAllByText('others')[0]); | ||
fireEvent.change(userSelect, { target: { value: 'others' } }); | ||
|
||
const submitButton = getByRole('button', { name: /submit/i }); | ||
expect(submitButton).toBeDisabled(); | ||
|
||
const userInput = getByPlaceholderText('Enter user'); | ||
fireEvent.change(userInput, { target: { value: 'customUser' } }); | ||
expect(submitButton).toBeEnabled(); | ||
}); | ||
}); |
Oops, something went wrong.
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.
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.
nit: we prefix classes with hue-