-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1187-add-rol-column-and-filter (#1211)
* add-column-role * version changed * delete rol useState * change version package.json * change version package.json * change tests * changed tests * types changes * type changes * enmus and changed version * change version ui * version ui changed * version ui changed * version ui changed * version ui changed * version ui changed * Update package.json * Update package-lock.json * Update FiltersWidget.tsx * Update handlers.ts * Update en.json * Update es.json * Update UsersTable.tsx * Update types.tsx * Update RolFilter.tsx * Delete web/package-lock.json * Update RolFilter.tsx * Update RolFilter.test.tsx * Update RolFilter.test.tsx * Update RolFilter.tsx * Update package-lock.json * Update package.json * changes rol * conflict resolved * Update package-lock.json * ColumnDef arguments changed * enums changed * Update SideMenu.tsx * update * update --------- Co-authored-by: Kevin Mamaqi <kevinmamaqi@gmail.com>
- Loading branch information
1 parent
954c8ad
commit c7898b2
Showing
21 changed files
with
224 additions
and
104 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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,51 @@ | ||
import { vi } from 'vitest' | ||
import { fireEvent, render, screen, waitFor } from '../test-utils' | ||
import { RoleFilter } from '../../components/molecules/RoleFilter' | ||
import { UserRole } from '../../types/types' | ||
import { roles } from '../../constants' | ||
|
||
const mockHandleClick = vi.fn() | ||
|
||
afterEach(() => { | ||
vi.restoreAllMocks() | ||
}) | ||
|
||
describe('RolesFilter', () => { | ||
it('renders correctly', () => { | ||
render(<RoleFilter handleRole={mockHandleClick} />) | ||
|
||
waitFor(() => expect(screen.getByText(/rol/i)).toBeInTheDocument()) | ||
}) | ||
|
||
it('renders RoleList options when dropdown is clicked', async () => { | ||
render(<RoleFilter handleRole={mockHandleClick} />) | ||
|
||
const dropdown = screen.getByTestId('dropdown-header') | ||
|
||
fireEvent.click(dropdown) | ||
|
||
const promises = roles.map((role) => | ||
waitFor(() => screen.getByTestId(role.id)) | ||
) | ||
|
||
await Promise.all(promises) | ||
}) | ||
|
||
it('calls handleRole with the correct role when an option is clicked', () => { | ||
render(<RoleFilter handleRole={mockHandleClick} />) | ||
|
||
const dropdown = screen.getByTestId('dropdown-header') | ||
|
||
fireEvent.click(dropdown) | ||
|
||
const roleOption = screen.getByText(/ADMIN/i) | ||
|
||
fireEvent.click(roleOption) | ||
|
||
expect(mockHandleClick).toHaveBeenCalledWith({ | ||
id: UserRole.ADMIN, | ||
name: 'Administrador', | ||
slug: UserRole.ADMIN, | ||
}) | ||
}) | ||
}) |
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
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,60 @@ | ||
import { FC } from 'react' | ||
import styled from 'styled-components' | ||
import { | ||
colors, | ||
dimensions, | ||
Dropdown, | ||
font, | ||
type TDropdownOption, | ||
} from '@itacademy/ui' | ||
import { useTranslation } from 'react-i18next' | ||
import { TRole } from '../../types/types' | ||
import { roles } from '../../constants' | ||
|
||
const StyledDropdown = styled(Dropdown)` | ||
&& button { | ||
width: 210px; | ||
padding: ${dimensions.spacing.xxs}; | ||
font-size: ${font.xs}; | ||
font-weight: 500; | ||
&:hover { | ||
background-color: ${colors.primary}; | ||
color: ${colors.white}; | ||
} | ||
> span { | ||
padding-left: ${dimensions.spacing.xxxs}; | ||
font-weight: 400; | ||
} | ||
} | ||
` | ||
|
||
type TRoleFilter = { | ||
handleRole: (value: TRole | undefined) => void | ||
} | ||
|
||
export const RoleFilter: FC<TRoleFilter> = ({ handleRole }) => { | ||
const { t } = useTranslation() | ||
|
||
const handleSelectedValue = (selectedOption: TDropdownOption | undefined) => { | ||
if (selectedOption) { | ||
const selectedRole = roles.find( | ||
(role: TRole) => role.id === selectedOption.id | ||
) | ||
if (selectedRole) { | ||
handleRole(selectedRole) | ||
} | ||
} else { | ||
handleRole(undefined) | ||
} | ||
} | ||
|
||
return roles && roles.length > 0 ? ( | ||
<StyledDropdown | ||
options={roles} | ||
placeholder={t('Rol')} | ||
onValueChange={handleSelectedValue} | ||
/> | ||
) : null | ||
} |
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 |
---|---|---|
@@ -1,4 +1,6 @@ | ||
export { DateRange, type TDateRange } from './DateRange' | ||
export { ItineraryDropdown } from './ItineraryDropdown' | ||
export { StatusDropdown } from './StatusDropdown' | ||
export { RoleFilter } from './RoleFilter' | ||
|
||
export { Table, type TTable } from './Table' |
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
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
Oops, something went wrong.