generated from muratkeremozcan/react-cypress-ts-vite-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from cesarhenrq/qa
4765 feat/base card
- Loading branch information
Showing
6 changed files
with
104 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import { render, screen } from '@testing-library/react'; | ||
import { expect } from '@jest/globals'; | ||
import '@testing-library/jest-dom/extend-expect'; | ||
|
||
import BaseCard from './BaseCard'; | ||
|
||
describe('<BaseCard />', () => { | ||
let container: HTMLElement; | ||
|
||
beforeEach(() => { | ||
container = render( | ||
<BaseCard> | ||
<div>Test</div> | ||
</BaseCard>, | ||
).container; | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(container).toBeDefined(); | ||
}); | ||
|
||
it('should render with: background-color: white as default', () => { | ||
(expect as any)(container).toHaveStyle('background-color: + white'); | ||
}); | ||
|
||
it('should render with: padding: 2rem as default', () => { | ||
(expect as any)(container).toHaveStyle('padding: + 2rem'); | ||
}); | ||
|
||
it('should render with: border: 1px solid var(--gray) as default', () => { | ||
(expect as any)(container).toHaveStyle('border: + 1px solid var(--gray)'); | ||
}); | ||
|
||
it('should render children', () => { | ||
const element = screen.getByText('Test'); | ||
|
||
expect(element).toBeDefined(); | ||
}); | ||
|
||
it('should render with: background-color: var(--purple) when prop is passed', () => { | ||
container = render( | ||
<BaseCard backgroundColor="purple"> | ||
<div>Test</div> | ||
</BaseCard>, | ||
).container; | ||
|
||
(expect as any)(container).toHaveStyle('background-color: + var(--purple)'); | ||
}); | ||
|
||
it('should render with: padding: var(--font-size-small) when prop is passed', () => { | ||
container = render( | ||
<BaseCard padding="small"> | ||
<div>Test</div> | ||
</BaseCard>, | ||
).container; | ||
|
||
(expect as any)(container).toHaveStyle('padding: + var(--font-size-small)'); | ||
}); | ||
|
||
it('should render with: border: 1px solid var(--purple) when prop is passed', () => { | ||
container = render( | ||
<BaseCard borderColor="purple"> | ||
<div>Test</div> | ||
</BaseCard>, | ||
).container; | ||
|
||
(expect as any)(container).toHaveStyle('border: + 1px solid var(--purple)'); | ||
}); | ||
}); |
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,11 @@ | ||
import * as S from './styles'; | ||
|
||
const BaseCard = ({ children, ...styleProps }: BaseCardProps) => { | ||
return ( | ||
<S.BaseCard {...styleProps} className="base-card"> | ||
{children} | ||
</S.BaseCard> | ||
); | ||
}; | ||
|
||
export default BaseCard; |
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 @@ | ||
export { default } from './BaseCard'; |
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,15 @@ | ||
import styled from 'styled-components'; | ||
|
||
export const BaseCard = styled.div< | ||
Pick<BaseCardProps, 'padding' | 'borderColor' | 'backgroundColor'> | ||
>` | ||
display: flex; | ||
border-radius: 1rem; | ||
padding: ${({ padding }) => | ||
padding ? `var(--font-size-${padding})` : 'var(--font-size-large)'}; | ||
box-shadow: 0px 1rem 2rem rgba(207.7, 207.7, 207.7, 0.2); | ||
border: ${({ borderColor }) => | ||
borderColor ? `1px solid var(--${borderColor})` : '1px solid var(--gray)'}; | ||
background-color: ${({ backgroundColor }) => | ||
backgroundColor ? `var(--${backgroundColor})` : 'var(--white)'}; | ||
`; |
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,6 @@ | ||
type BaseCardProps = { | ||
padding?: 'large' | 'xmedium' | 'small'; | ||
borderColor?: 'purple'; | ||
backgroundColor?: 'purple' | 'white'; | ||
children: React.ReactNode; | ||
}; |