-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test(Image): test for Image added #361
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
591aeed
test(Image): test for Image added
niktverd 4364ab5
fixup! test(Image): test for Image added
niktverd 956651a
fixup! fixup! test(Image): test for Image added
niktverd dff88af
fixup! fixup! fixup! test(Image): test for Image added
niktverd 97d9752
fixup! fixup! fixup! fixup! test(Image): test for Image added
niktverd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,131 @@ | ||
import React from 'react'; | ||
|
||
import {render, screen} from '@testing-library/react'; | ||
|
||
import { | ||
testCustomClassName, | ||
testCustomStyle, | ||
testOnClick, | ||
} from '../../../../test-utils/shared/common'; | ||
import {testSourceProps} from '../../../../test-utils/shared/image'; | ||
import Image, {ImageProps} from '../Image'; | ||
import i18n from '../i18n'; | ||
|
||
const qaId = 'image-component'; | ||
|
||
const imageSrc = | ||
'https://storage.yandexcloud.net/cloud-www-assets/constructor/storybook/images/img-gray.png'; | ||
|
||
describe('Image', () => { | ||
test('Render Image by default', async () => { | ||
render(<Image src={imageSrc} qa={qaId} />); | ||
|
||
const component = screen.getByTestId(qaId); | ||
expect(component).toBeInTheDocument(); | ||
expect(component).toBeVisible(); | ||
}); | ||
|
||
test('add image as src prop', () => { | ||
yuberdysheva marked this conversation as resolved.
Show resolved
Hide resolved
|
||
testSourceProps<ImageProps>({ | ||
component: Image, | ||
props: {src: imageSrc, qa: qaId}, | ||
}); | ||
}); | ||
|
||
test('add image as desktop prop', () => { | ||
testSourceProps<ImageProps>({ | ||
component: Image, | ||
props: {desktop: imageSrc, qa: qaId}, | ||
}); | ||
}); | ||
|
||
test('add image as tablet prop', () => { | ||
testSourceProps<ImageProps>({ | ||
component: Image, | ||
props: {desktop: imageSrc, tablet: imageSrc, qa: qaId}, | ||
}); | ||
}); | ||
|
||
test('add image as mobile prop', () => { | ||
testSourceProps<ImageProps>({ | ||
component: Image, | ||
props: {desktop: imageSrc, mobile: imageSrc, qa: qaId}, | ||
}); | ||
}); | ||
|
||
test('add image as src prop with disabledCompress', () => { | ||
testSourceProps<ImageProps>({ | ||
component: Image, | ||
props: {src: imageSrc, qa: qaId, disableCompress: true}, | ||
}); | ||
}); | ||
|
||
test('add image as desktop prop with disabledCompress', () => { | ||
testSourceProps<ImageProps>({ | ||
component: Image, | ||
props: {desktop: imageSrc, qa: qaId, disableCompress: true}, | ||
}); | ||
}); | ||
|
||
test('add image as tablet prop with disabledCompress', () => { | ||
testSourceProps<ImageProps>({ | ||
component: Image, | ||
props: {desktop: imageSrc, tablet: imageSrc, qa: qaId, disableCompress: true}, | ||
}); | ||
}); | ||
|
||
test('add image as mobile prop with disabledCompress', () => { | ||
testSourceProps<ImageProps>({ | ||
component: Image, | ||
props: {desktop: imageSrc, mobile: imageSrc, qa: qaId, disableCompress: true}, | ||
}); | ||
}); | ||
|
||
test('add className', () => { | ||
testCustomClassName<ImageProps>({ | ||
component: Image, | ||
props: {src: imageSrc, qa: qaId}, | ||
options: {customClassNameProp: 'containerClassName'}, | ||
}); | ||
}); | ||
|
||
test('add className to image', () => { | ||
const className = 'custom-class-name'; | ||
|
||
render(<Image className={className} src={imageSrc} qa={qaId} />); | ||
|
||
const component = screen.getByRole('img'); | ||
expect(component).toHaveClass(className); | ||
}); | ||
|
||
test('add style', () => { | ||
testCustomStyle<ImageProps>({ | ||
component: Image, | ||
props: {src: imageSrc, qa: qaId}, | ||
options: {role: 'img'}, | ||
}); | ||
}); | ||
|
||
test('render default "alt"', () => { | ||
render(<Image src={imageSrc} qa={qaId} />); | ||
|
||
const component = screen.getByRole('img'); | ||
expect(component).toHaveAttribute('alt', i18n('img-alt')); | ||
}); | ||
|
||
test('render custom "alt"', () => { | ||
const alt = 'defined-alt'; | ||
render(<Image src={imageSrc} alt={alt} qa={qaId} />); | ||
|
||
const component = screen.getByRole('img'); | ||
expect(component).toHaveAttribute('alt', alt); | ||
}); | ||
|
||
test('call onClick', async () => { | ||
testOnClick<ImageProps>({ | ||
component: Image, | ||
props: {src: imageSrc, qa: qaId}, | ||
options: {role: 'img'}, | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hope I understand you