fix(#13204): after changing the team type action buttons are not disappearing (#13205)

This commit is contained in:
Sachin Chaurasiya 2023-09-15 14:43:01 +05:30 committed by GitHub
parent 442528267c
commit ae16ce7ad7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 53 additions and 6 deletions

View File

@ -11,9 +11,9 @@
* limitations under the License. * limitations under the License.
*/ */
import { findByTestId, render } from '@testing-library/react'; import { act, findByTestId, render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import React from 'react'; import React from 'react';
import { act } from 'react-test-renderer';
import EntitySummaryDetails from './EntitySummaryDetails'; import EntitySummaryDetails from './EntitySummaryDetails';
const mockData = { const mockData = {
@ -69,4 +69,34 @@ describe('EntitySummaryDetails Component', () => {
expect(EntitySummary).toBeInTheDocument(); expect(EntitySummary).toBeInTheDocument();
}); });
}); });
it('Edit team type should render the appropriate component', async () => {
render(
<EntitySummaryDetails data={{ key: 'TeamType', value: 'Department' }} />
);
const editTeamTypeBtn = screen.getByTestId('edit-TeamType-icon');
await act(async () => {
userEvent.click(editTeamTypeBtn);
});
// should show the team type select box and action buttons
expect(screen.getByTestId('team-type-select')).toBeInTheDocument();
const cancelBtn = screen.getByTestId('cancel-btn');
const saveBtn = screen.getByTestId('save-btn');
expect(cancelBtn).toBeInTheDocument();
expect(saveBtn).toBeInTheDocument();
// should hide the team type select box and action buttons after save
await act(async () => {
userEvent.click(saveBtn);
});
expect(screen.queryByTestId('team-type-select')).toBeNull();
expect(screen.queryByTestId('cancel-btn')).toBeNull();
expect(screen.queryByTestId('save-btn')).toBeNull();
});
}); });

View File

@ -83,6 +83,11 @@ const EntitySummaryDetails = ({
setShowTypeSelector(value); setShowTypeSelector(value);
}, []); }, []);
const handleUpdateTeamType = (type: TeamType) => {
updateTeamType?.(type);
handleShowTypeSelector(false);
};
const ownerDropdown = allowTeamOwner ? ( const ownerDropdown = allowTeamOwner ? (
<UserTeamSelectableList <UserTeamSelectableList
hasPermission={Boolean(updateOwner)} hasPermission={Boolean(updateOwner)}
@ -335,7 +340,7 @@ const EntitySummaryDetails = ({
handleShowTypeSelector={handleShowTypeSelector} handleShowTypeSelector={handleShowTypeSelector}
showGroupOption={showGroupOption ?? false} showGroupOption={showGroupOption ?? false}
teamType={teamType ?? TeamType.Department} teamType={teamType ?? TeamType.Department}
updateTeamType={updateTeamType} updateTeamType={handleUpdateTeamType}
/> />
) : ( ) : (
<> <>

View File

@ -42,7 +42,11 @@ function TeamTypeSelect({
const options = useMemo(() => getTeamTypeOptions(showGroupOption), []); const options = useMemo(() => getTeamTypeOptions(showGroupOption), []);
return ( return (
<Space align="center" className="team-type-select" size={4}> <Space
align="center"
className="team-type-select"
data-testid="team-type-select"
size={4}>
<Select <Select
defaultActiveFirstOption defaultActiveFirstOption
options={options} options={options}
@ -50,8 +54,16 @@ function TeamTypeSelect({
onSelect={handleSelect} onSelect={handleSelect}
/> />
<Space className="edit-team-type-buttons" size={4}> <Space className="edit-team-type-buttons" size={4}>
<Button icon={<CloseOutlined />} onClick={handleCancel} /> <Button
<Button icon={<CheckOutlined />} onClick={handleSubmit} /> data-testid="cancel-btn"
icon={<CloseOutlined />}
onClick={handleCancel}
/>
<Button
data-testid="save-btn"
icon={<CheckOutlined />}
onClick={handleSubmit}
/>
</Space> </Space>
</Space> </Space>
); );