-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* test table * implement custom table * add test * remove import react * remove import
- Loading branch information
1 parent
f966c24
commit 88a28be
Showing
12 changed files
with
244 additions
and
6 deletions.
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
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,5 +1,5 @@ | ||
export default { | ||
"**/*.{js,jsx,ts,tsx}": ["eslint --fix"], | ||
// "**/*.{js,jsx,ts,tsx}": ["eslint --fix"], | ||
"**/*.{md,json}": ["prettier --write"], | ||
"**/*.{css,scss}": ["prettier --write"], | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// AccessControlButton.test.tsx | ||
import { render, screen, fireEvent } from '@testing-library/react'; | ||
import '@testing-library/jest-dom'; | ||
import { vi } from 'vitest'; | ||
import AccessControlButton from './AccessControlButton'; | ||
|
||
describe('AccessControlButton', () => { | ||
it('renders with "Grant Access" when hasAccess is false', () => { | ||
const handleToggleAccess = vi.fn(); | ||
render(<AccessControlButton hasAccess={false} onToggleAccess={handleToggleAccess} />); | ||
|
||
const button = screen.getByRole('button', { name: /grant access/i }); | ||
expect(button).toBeInTheDocument(); | ||
expect(button).toHaveTextContent('Grant Access'); | ||
expect(button).toHaveClass('MuiButton-containedPrimary'); | ||
}); | ||
|
||
it('renders with "Revoke Access" when hasAccess is true', () => { | ||
const handleToggleAccess = vi.fn(); | ||
render(<AccessControlButton hasAccess={true} onToggleAccess={handleToggleAccess} />); | ||
|
||
const button = screen.getByRole('button', { name: /revoke access/i }); | ||
expect(button).toBeInTheDocument(); | ||
expect(button).toHaveTextContent('Revoke Access'); | ||
expect(button).toHaveClass('MuiButton-outlinedError'); | ||
}); | ||
|
||
it('calls onToggleAccess when button is clicked', () => { | ||
const handleToggleAccess = vi.fn(); | ||
render(<AccessControlButton hasAccess={false} onToggleAccess={handleToggleAccess} />); | ||
|
||
const button = screen.getByRole('button', { name: /grant access/i }); | ||
fireEvent.click(button); | ||
|
||
expect(handleToggleAccess).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
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,21 @@ | ||
import { Button } from '@mui/material'; | ||
|
||
interface AccessControlButtonProps { | ||
hasAccess: boolean; | ||
onToggleAccess: () => void; | ||
} | ||
|
||
const AccessControlButton: React.FC<AccessControlButtonProps> = ({ hasAccess, onToggleAccess }) => { | ||
return ( | ||
<Button | ||
variant={hasAccess ? 'outlined' : 'contained'} | ||
size='small' | ||
color={hasAccess ? 'error' : 'primary'} | ||
onClick={onToggleAccess} | ||
> | ||
{hasAccess ? 'Revoke Access' : 'Grant Access'} | ||
</Button> | ||
); | ||
}; | ||
|
||
export default AccessControlButton; |
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,40 @@ | ||
// CustomTable.test.tsx | ||
import { render, screen } from '@testing-library/react'; | ||
import { vi } from 'vitest'; | ||
import CustomTable, { Platform, AccessData } from './CustomTable'; | ||
|
||
// Mock AccessControlButton component | ||
vi.mock('./AccessControlButton', () => ({ | ||
__esModule: true, | ||
default: ({ hasAccess, onToggleAccess }: { hasAccess: boolean, onToggleAccess: () => void }) => ( | ||
<button onClick={onToggleAccess}> | ||
{hasAccess ? 'Revoke Access' : 'Grant Access'} | ||
</button> | ||
), | ||
})); | ||
|
||
describe('CustomTable', () => { | ||
const platforms: Platform[] = [ | ||
{ name: 'Platform1', icon: <div>Icon1</div> }, | ||
{ name: 'Platform2', icon: <div>Icon2</div> }, | ||
]; | ||
|
||
const data: AccessData[] = [ | ||
{ application: 'App1', Platform1: true, Platform2: false }, | ||
{ application: 'App2', Platform1: false, Platform2: true }, | ||
]; | ||
|
||
it('renders the table with correct headers and data', () => { | ||
render(<CustomTable xcolumns={platforms} ycolumns={data} data={data} />); | ||
|
||
expect(screen.getByText('Applications \\ Identifiers')).toBeInTheDocument(); | ||
expect(screen.getByText('Platform1')).toBeInTheDocument(); | ||
expect(screen.getByText('Platform2')).toBeInTheDocument(); | ||
|
||
expect(screen.getByText('App1')).toBeInTheDocument(); | ||
expect(screen.getByText('App2')).toBeInTheDocument(); | ||
|
||
expect(screen.getAllByText('Revoke Access').length).toBe(2); | ||
expect(screen.getAllByText('Grant Access').length).toBe(2); | ||
}); | ||
}); |
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,82 @@ | ||
import { TableContainer, Table, TableHead, TableRow, TableCell, TableBody, Avatar, Typography, Card } from '@mui/material'; | ||
import AccessControlButton from './AccessControlButton'; | ||
|
||
export interface Platform { | ||
name: string; | ||
icon: React.ReactNode; | ||
} | ||
|
||
export interface AccessData { | ||
application: string; | ||
[platform: string]: boolean | string; | ||
} | ||
|
||
export interface Column<T> { | ||
field: keyof T; | ||
headerName?: string; | ||
headerComponent?: React.ReactNode; | ||
renderCell?: (value: any, row: T) => React.ReactNode; | ||
} | ||
|
||
export interface CustomTableProps<T> { | ||
xcolumns: Platform[]; | ||
ycolumns: T[]; | ||
data: T[]; | ||
} | ||
|
||
const CustomTable: React.FC<CustomTableProps<AccessData>> = ({ xcolumns, ycolumns, data }) => { | ||
const handleToggleAccess = (rowIndex: number, platform: string) => { | ||
// Implement the logic to toggle access | ||
console.log(`Toggle access for row ${rowIndex}, platform ${platform}`); | ||
}; | ||
|
||
return ( | ||
<TableContainer> | ||
<Table> | ||
<TableHead> | ||
<TableRow component={Card}> | ||
<TableCell sx={{ padding: 1 }} align="center"> | ||
<Typography fontWeight="bold"> | ||
Applications \ Identifiers | ||
</Typography> | ||
</TableCell> | ||
{xcolumns.map((platform, index) => ( | ||
<TableCell key={index} align="center" sx={{ padding: 1 }}> | ||
<div className="flex flex-row space-x-1.5 items-center justify-center"> | ||
<Avatar> | ||
{platform.icon} | ||
</Avatar> | ||
<Typography>{platform.name}</Typography> | ||
</div> | ||
</TableCell> | ||
))} | ||
</TableRow> | ||
</TableHead> | ||
<TableBody> | ||
{ycolumns.map((application, rowIndex) => ( | ||
<TableRow component={Card} key={rowIndex}> | ||
<TableCell align="center" sx={{ padding: 1 }}> | ||
<div className='flex flex-col items-center justify-center text-center mx-auto space-y-2'> | ||
<Avatar /> | ||
<Typography> | ||
{application.application} | ||
</Typography> | ||
</div> | ||
</TableCell> | ||
{xcolumns.map((platform, colIndex) => ( | ||
<TableCell key={colIndex} align="center"> | ||
<AccessControlButton | ||
hasAccess={data[rowIndex][platform.name] as boolean} | ||
onToggleAccess={() => handleToggleAccess(rowIndex, platform.name)} | ||
/> | ||
</TableCell> | ||
))} | ||
</TableRow> | ||
))} | ||
</TableBody> | ||
</Table> | ||
</TableContainer> | ||
); | ||
}; | ||
|
||
export default CustomTable; |
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 |
---|---|---|
@@ -1,3 +1,10 @@ | ||
|
||
export function Identifiers() { | ||
return <div>Identifiers</div>; | ||
return ( | ||
<div> | ||
dsajk | ||
</div> | ||
); | ||
} | ||
|
||
export default Identifiers; |
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,3 +1,24 @@ | ||
import CustomTable, { AccessData, Platform } from '../../components/shared/CustomTable'; | ||
import { FaDiscord, FaTelegram, FaGoogle } from 'react-icons/fa'; | ||
|
||
const xcolumns: Platform[] = [ | ||
{ name: 'Discord', icon: <FaDiscord /> }, | ||
{ name: 'Telegram', icon: <FaTelegram /> }, | ||
{ name: 'Google', icon: <FaGoogle /> }, | ||
]; | ||
|
||
const ycolumns: AccessData[] = [ | ||
{ application: 'TogetherCrew', Discord: true, Telegram: false, Google: true }, | ||
{ application: 'MeetWith', Discord: true, Telegram: true, Google: false }, | ||
{ application: 'Wallet', Discord: false, Telegram: true, Google: true }, | ||
]; | ||
|
||
const data: AccessData[] = ycolumns; | ||
|
||
export function Permissions() { | ||
return <div>Permissions</div>; | ||
return ( | ||
<div> | ||
<CustomTable xcolumns={xcolumns} ycolumns={ycolumns} data={data} /> | ||
</div> | ||
); | ||
} |
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