-
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(Companies): test for Companies block added #688
Open
niktverd
wants to merge
1
commit into
main
Choose a base branch
from
test/companies_block
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import React from 'react'; | ||
|
||
import {render, screen} from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
|
||
import {ThemeContext} from '../../../context/theme'; | ||
import {CompaniesBlockProps, Theme} from '../../../models'; | ||
import {getQaAttrubutes} from '../../../utils'; | ||
import Companies from '../Companies'; | ||
|
||
const companies: CompaniesBlockProps = { | ||
title: 'Companies Title', | ||
animated: true, | ||
images: { | ||
light: { | ||
desktop: | ||
'https://storage.yandexcloud.net/cloud-www-assets/constructor/storybook/images/logo-svg_12-12_desktop_light.svg', | ||
tablet: 'https://storage.yandexcloud.net/cloud-www-assets/constructor/storybook/images/logo-svg_12-12_tablet_light.svg', | ||
mobile: 'https://storage.yandexcloud.net/cloud-www-assets/constructor/storybook/images/logo-svg_12-12_mobile_light.svg', | ||
alt: 'Page constructor', | ||
}, | ||
dark: { | ||
desktop: | ||
'https://storage.yandexcloud.net/cloud-www-assets/constructor/storybook/images/logo-svg_12-12_desktop_dark.svg', | ||
tablet: 'https://storage.yandexcloud.net/cloud-www-assets/constructor/storybook/images/logo-svg_12-12_tablet_dark.svg', | ||
mobile: 'https://storage.yandexcloud.net/cloud-www-assets/constructor/storybook/images/logo-svg_12-12_mobile_dark.svg', | ||
alt: 'Page constructor', | ||
}, | ||
}, | ||
qa: 'companies-block', | ||
}; | ||
|
||
const qaAttributes = getQaAttrubutes(companies.qa, 'title'); | ||
|
||
describe('Companies', () => { | ||
test('render Companies by default', async () => { | ||
render(<Companies {...companies} />); | ||
|
||
const component = screen.getByTestId(qaAttributes.default); | ||
|
||
expect(component).toBeInTheDocument(); | ||
expect(component).toBeVisible(); | ||
}); | ||
|
||
test('render Companies with title', async () => { | ||
render(<Companies {...companies} />); | ||
|
||
const component = screen.getByTestId(qaAttributes.title); | ||
|
||
expect(component).toHaveTextContent(companies.title); | ||
}); | ||
|
||
test('render Companies with animated', async () => { | ||
const user = userEvent.setup(); | ||
|
||
render( | ||
<div style={{paddingTop: 100000}}> | ||
<Companies {...companies} /> | ||
</div>, | ||
); | ||
|
||
const component = screen.getByTestId(qaAttributes.default); | ||
await user.hover(component); | ||
|
||
expect(component).toHaveClass('animate'); | ||
}); | ||
|
||
test('render Companies without animated', async () => { | ||
const user = userEvent.setup(); | ||
|
||
render( | ||
<div style={{paddingTop: 100000}}> | ||
<Companies {...companies} animated={false} /> | ||
</div>, | ||
); | ||
|
||
const component = screen.getByTestId(qaAttributes.default); | ||
await user.hover(component); | ||
|
||
expect(component).not.toHaveClass('animate'); | ||
}); | ||
|
||
test('render Companies pass className to AnimatedBlock', async () => { | ||
render(<Companies {...companies} />); | ||
|
||
const component = screen.getByTestId(qaAttributes.default); | ||
|
||
expect(component).toHaveClass('pc-companies-block'); | ||
}); | ||
|
||
test.each(new Array<Theme>(Theme.Light, Theme.Dark))( | ||
'render Companies with given %s theme', | ||
async (theme) => { | ||
render( | ||
<ThemeContext.Provider value={{theme}}> | ||
<Companies {...companies} /> | ||
</ThemeContext.Provider>, | ||
); | ||
|
||
const component = screen.getByRole('img'); | ||
|
||
expect(component).toHaveAttribute( | ||
'src', | ||
`https://storage.yandexcloud.net/cloud-www-assets/constructor/storybook/images/logo-svg_12-12_desktop_${theme}.svg`, | ||
); | ||
}, | ||
); | ||
}); |
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.
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.
It is maybe not necessary now, but I get task to move all images that constructor depends on inside project. It means we are trying to avoid adding images from storage.yandexcloud.net now