-
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.
feat(trackerCard): add TrackerCard and use it on TrackerList
- Loading branch information
Showing
7 changed files
with
118 additions
and
32 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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import { subDays } from 'date-fns'; | ||
import TrackerStatus from '../../models/TrackerStatus'; | ||
import formatDate from '../../utils/formatDate'; | ||
import TrackerCard from './TrackerCard'; | ||
|
||
const tracker1 = { | ||
beginDate: subDays(new Date(), 3).toString(), | ||
defaultQuantity: 15, | ||
duration: 13, | ||
name: 'Faire des pompes', | ||
remainingDays: 10, | ||
status: TrackerStatus.active, | ||
unit: 'pompes', | ||
entries: [] | ||
}; | ||
const setup = () => render(<TrackerCard tracker={tracker1} />); | ||
|
||
describe('<TrackerCard />', () => { | ||
it('shows tracker informations', () => { | ||
setup(); | ||
const { beginDate, name, defaultQuantity, remainingDays, unit } = tracker1; | ||
expect(screen.getByText(name)).toBeInTheDocument(); | ||
expect(screen.getByText('Reste ' + remainingDays + ' jours')).toBeInTheDocument(); | ||
expect(screen.getByText('Commencé le ' + formatDate(new Date(beginDate)))).toBeInTheDocument(); | ||
expect(screen.getByText(defaultQuantity + ' ' + unit)).toBeInTheDocument(); | ||
}); | ||
}); |
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,14 +1,53 @@ | ||
import { Card, Typography } from '@mui/material'; | ||
import { FC } from 'react'; | ||
|
||
import SliceStatus from '../../models/SliceStatus'; | ||
import { | ||
Box, | ||
Card, | ||
CardProps, | ||
CardActions, | ||
CardContent, | ||
CardHeader, | ||
IconButton, | ||
Chip | ||
} from '@mui/material'; | ||
import formatDate from '../../utils/formatDate'; | ||
import Tracker from '../../models/Tracker'; | ||
import CheckCircleIcon from '@mui/icons-material/CheckCircle'; | ||
import CheckIcon from '@mui/icons-material/Check'; | ||
import TimerIcon from '@mui/icons-material/Timer'; | ||
import VisibilityOffIcon from '@mui/icons-material/VisibilityOff'; | ||
|
||
interface Props { | ||
tracker: Tracker; | ||
cardProps?: CardProps; | ||
} | ||
const TrackerCard: FC<Props> = ({ tracker }) => { | ||
return <Card></Card>; | ||
const TrackerCard: FC<Props> = ({ tracker, cardProps }) => { | ||
const { beginDate, defaultQuantity, name, remainingDays, unit } = tracker; | ||
return ( | ||
<Card {...cardProps}> | ||
<CardHeader title={name} subheader={`Commencé le ${formatDate(new Date(beginDate))}`} /> | ||
{(defaultQuantity || remainingDays) && ( | ||
<CardContent> | ||
{defaultQuantity && <Chip label={`${defaultQuantity} ${unit}`} />} | ||
{remainingDays && ( | ||
<Chip color="secondary" label={`Reste ${remainingDays} jours`} icon={<TimerIcon />} /> | ||
)} | ||
</CardContent> | ||
)} | ||
<CardActions> | ||
<Box sx={{ display: 'flex', justifyContent: 'space-between', width: '100%' }}> | ||
<IconButton color="success" size="large"> | ||
<CheckIcon fontSize="large" /> | ||
</IconButton> | ||
<IconButton color="success" size="large"> | ||
<CheckCircleIcon fontSize="large" /> | ||
</IconButton> | ||
<IconButton size="large"> | ||
<VisibilityOffIcon fontSize="large" /> | ||
</IconButton> | ||
</Box> | ||
</CardActions> | ||
</Card> | ||
); | ||
}; | ||
|
||
export default TrackerCard; |
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