-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8517ee4
commit a0558ef
Showing
12 changed files
with
246 additions
and
117 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 @@ | ||
20.12.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,44 @@ | ||
module.exports = { | ||
extends: ['airbnb', 'airbnb-typescript'], | ||
plugins: ['@typescript-eslint'], | ||
parserOptions: { | ||
ecmaFeatures: { | ||
jsx: true, | ||
experimentalObjectRestSpread: true, | ||
}, | ||
project: './tsconfig.json', | ||
}, | ||
rules: { | ||
'no-underscore-dangle': 0, | ||
'import/no-extraneous-dependencies': 0, | ||
'react/require-extension': 0, | ||
'react/jsx-filename-extension': 0, | ||
'react/destructuring-assignment': 0, | ||
'react/default-props-match-prop-types': 0, | ||
'react/jsx-props-no-spreading': 0, | ||
'react/static-property-placement': 0, | ||
'react/jsx-uses-react': 'off', | ||
'react/react-in-jsx-scope': 'off', | ||
'arrow-body-style': 0, | ||
'prefer-arrow-callback': 0, | ||
'func-names': 0, | ||
'react/forbid-prop-types': 0, | ||
'comma-dangle': 0, | ||
'react/sort-comp': 0, | ||
'react/prop-types': 0, | ||
'arrow-parens': 0, | ||
'import/extensions': [ | ||
'error', | ||
'always', | ||
{ | ||
js: 'never', | ||
jsx: 'never', | ||
ts: 'never', | ||
tsx: 'never', | ||
}, | ||
], | ||
}, | ||
env: { | ||
jest: true, | ||
}, | ||
}; |
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 @@ | ||
import '@testing-library/jest-dom'; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { render } from '@testing-library/react'; | ||
import '@testing-library/jest-dom'; | ||
import AspectRatio from '.'; | ||
|
||
describe('AspectRatio Component (Class)', () => { | ||
it('renders with default props', () => { | ||
const { getByRole } = render(<AspectRatio />); | ||
const div = getByRole('generic'); | ||
|
||
expect(div).toBeInTheDocument(); | ||
expect(div).toHaveClass('react-aspect-ratio-placeholder'); | ||
expect(div).toHaveStyle('--aspect-ratio: (1)'); | ||
}); | ||
|
||
it('renders with custom className and ratio', () => { | ||
const { getByRole } = render(<AspectRatio className="custom-class" ratio={1.5} />); | ||
const div = getByRole('generic'); | ||
|
||
expect(div).toBeInTheDocument(); | ||
expect(div).toHaveClass('custom-class'); | ||
expect(div).toHaveStyle('--aspect-ratio: (1.5)'); | ||
}); | ||
|
||
it('applies custom styles', () => { | ||
const { getByRole } = render(<AspectRatio style={{ backgroundColor: 'blue' }} />); | ||
const div = getByRole('generic'); | ||
|
||
expect(div).toHaveStyle('background-color: blue'); | ||
expect(div).toHaveStyle('--aspect-ratio: (1)'); | ||
}); | ||
|
||
it('renders children correctly', () => { | ||
const { getByText } = render( | ||
<AspectRatio> | ||
<span>Test Child</span> | ||
</AspectRatio> | ||
); | ||
|
||
expect(getByText('Test Child')).toBeInTheDocument(); | ||
}); | ||
|
||
it('updates custom property in componentDidUpdate', () => { | ||
const { getByRole, rerender } = render(<AspectRatio ratio={1} />); | ||
const div = getByRole('generic'); | ||
|
||
// Before update | ||
expect(div.style.getPropertyValue('--aspect-ratio')).toBe('(1)'); | ||
|
||
// Update props | ||
rerender(<AspectRatio ratio={2} />); | ||
expect(div.style.getPropertyValue('--aspect-ratio')).toBe('(2)'); | ||
}); | ||
|
||
it('spreads additional props onto the div', () => { | ||
const { getByRole } = render(<AspectRatio id="custom-id" data-testid="aspect-ratio" />); | ||
const div = getByRole('generic'); | ||
|
||
expect(div).toHaveAttribute('id', 'custom-id'); | ||
expect(div).toHaveAttribute('data-testid', 'aspect-ratio'); | ||
}); | ||
}); |
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,63 @@ | ||
import { render } from '@testing-library/react'; | ||
import '@testing-library/jest-dom/extend-expect'; | ||
import AspectRatio from '.'; | ||
import { createRef } from 'react'; | ||
|
||
describe('AspectRatio Component', () => { | ||
it('renders with default props', () => { | ||
const { container } = render(<AspectRatio />); | ||
const div = container.firstChild; | ||
|
||
expect(div).toBeInTheDocument(); | ||
expect(div).toHaveClass('react-aspect-ratio-placeholder'); | ||
expect(div).toHaveStyle('--aspect-ratio: (1)'); | ||
}); | ||
|
||
it('renders with a custom className and ratio', () => { | ||
const { container } = render( | ||
<AspectRatio className="custom-class" ratio={1.5} /> | ||
); | ||
const div = container.firstChild; | ||
|
||
expect(div).toBeInTheDocument(); | ||
expect(div).toHaveClass('custom-class'); | ||
expect(div).toHaveStyle('--aspect-ratio: (1.5)'); | ||
}); | ||
|
||
it('applies custom style', () => { | ||
const { container } = render( | ||
<AspectRatio style={{ backgroundColor: 'red' }} /> | ||
); | ||
const div = container.firstChild; | ||
|
||
expect(div).toBeInTheDocument(); | ||
expect(div).toHaveStyle('background-color: red'); | ||
expect(div).toHaveStyle('--aspect-ratio: (1)'); | ||
}); | ||
|
||
it('renders children correctly', () => { | ||
const { getByText } = render( | ||
<AspectRatio> | ||
<span>Test Child</span> | ||
</AspectRatio> | ||
); | ||
expect(getByText('Test Child')).toBeInTheDocument(); | ||
}); | ||
|
||
it('forwards the ref correctly', () => { | ||
const ref = createRef<HTMLDivElement>(); | ||
render(<AspectRatio ref={ref} />); | ||
expect(ref.current).not.toBeNull(); | ||
expect(ref.current?.tagName).toBe('DIV'); | ||
}); | ||
|
||
it('spreads additional props onto the div', () => { | ||
const { container } = render( | ||
<AspectRatio id="custom-id" data-testid="aspect-ratio" /> | ||
); | ||
const div = container.firstChild; | ||
|
||
expect(div).toHaveAttribute('id', 'custom-id'); | ||
expect(div).toHaveAttribute('data-testid', 'aspect-ratio'); | ||
}); | ||
}); |
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.