Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
- правки тестов
  • Loading branch information
krutoo committed Jul 22, 2024
1 parent 1de17e8 commit a4163e6
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 20 deletions.
44 changes: 35 additions & 9 deletions src/common/components/product-info/__test__/product-info.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('ProductInfo', () => {
it('should render all parts', () => {
const { container, queryAllByTestId } = render(
<ProductInfo>
<Parts.Image src='/public/test.png' href='https://sima-land.ru/product'>
<Parts.Image images={[{ src: '/public/test.png' }]} href='https://sima-land.ru/product'>
<Parts.ImageButton
icon={FavoriteSVG}
position={{ x: 'right', y: 'top' }}
Expand Down Expand Up @@ -80,7 +80,7 @@ describe('ProductInfo', () => {
it('should hide parts for unavailable product', () => {
const { queryAllByTestId } = render(
<ProductInfo restriction='unavailable'>
<Parts.Image src='/public/test.png' href='https://sima-land.ru/product'>
<Parts.Image images={[{ src: '/public/test.png' }]} href='https://sima-land.ru/product'>
<Parts.ImageButton
icon={FavoriteSVG}
position={{ x: 'right', y: 'top' }}
Expand Down Expand Up @@ -141,7 +141,11 @@ describe('ProductInfo', () => {
const { queryAllByTestId } = render(
<ProductInfo restriction='adult'>
<Parts.Image
src={['/public/test1.png', '/public/test2.png']}
images={[
//
{ src: '/public/test1.png' },
{ src: '/public/test2.png' },
]}
href='https://sima-land.ru/product'
>
<Parts.ImageButton
Expand Down Expand Up @@ -204,7 +208,10 @@ describe('ProductInfo', () => {
const { container } = render(
<ProductInfo strict={false}>
<Parts.Title href='https://my-site.com'>My product!</Parts.Title>
<Parts.Image src='https://my-site.com/images/1' href='https://my-site.com' />
<Parts.Image
images={[{ src: 'https://my-site.com/images/1' }]}
href='https://my-site.com'
/>
<div>My custom child element!</div>
</ProductInfo>,
);
Expand All @@ -217,7 +224,7 @@ describe('ProductInfo', () => {

const { getByTestId } = render(
<ProductInfo restriction='unavailable'>
<Parts.Image src='/public/test.jpg' href='https://www.sima-land.ru'>
<Parts.Image images={[{ src: '/public/test.jpg' }]} href='https://www.sima-land.ru'>
<Parts.ImageButton
icon={FavoriteSVG}
position={{ x: 'right', y: 'top' }}
Expand Down Expand Up @@ -270,7 +277,7 @@ describe('ProductInfo', () => {
it('should render link to waiting list', () => {
const { getByTestId } = render(
<ProductInfo restriction='unavailable'>
<Parts.Image src='/public/test.jpg' href='https://www.sima-land.ru'>
<Parts.Image images={[{ src: '/public/test.jpg' }]} href='https://www.sima-land.ru'>
<Parts.ImageButton
icon={FavoriteSVG}
position={{ x: 'right', y: 'top' }}
Expand Down Expand Up @@ -325,7 +332,7 @@ describe('ProductInfo', () => {

const { getByTestId } = render(
<ProductInfo restriction='adult'>
<Parts.Image src='/images/product.png' href='https://www.sima-land.ru'>
<Parts.Image images={[{ src: '/images/product.png' }]} href='https://www.sima-land.ru'>
<Parts.ImageButton
icon={FavoriteSVG}
position={{ x: 'right', y: 'top' }}
Expand Down Expand Up @@ -378,7 +385,15 @@ describe('ProductInfo', () => {
it('should render hover slider when src is an array', () => {
const { queryAllByTestId } = render(
<ProductInfo>
<Parts.Image src={['/foo.png', '/bar.png', '/baz.png']} href='https://www.sima-land.ru'>
<Parts.Image
images={[
//
{ src: '/foo.png' },
{ src: '/bar.png' },
{ src: '/baz.png' },
]}
href='https://www.sima-land.ru'
>
<Parts.ImageButton
icon={FavoriteSVG}
position={{ x: 'right', y: 'top' }}
Expand Down Expand Up @@ -429,7 +444,7 @@ describe('ProductInfo', () => {
it('should render cart control loading', () => {
const { container, queryAllByTestId } = render(
<ProductInfo>
<Parts.Image src='/foobar.png' href='https://www.sima-land.ru'>
<Parts.Image images={[{ src: '/foobar.png' }]} href='https://www.sima-land.ru'>
<Parts.ImageButton
icon={FavoriteSVG}
position={{ x: 'right', y: 'top' }}
Expand Down Expand Up @@ -479,4 +494,15 @@ describe('ProductInfo', () => {
expect(container.textContent).not.toContain('По 1 шт');
expect(container.textContent).not.toContain('Комплектация + 50 ₽ при покупке до 20 шт');
});

it('Parts.Image should accept undefined for "images"', () => {
const { queryAllByTestId } = render(
<ProductInfo>
<Parts.Image images={undefined} href='https://www.sima-land.ru' />
</ProductInfo>,
);

expect(queryAllByTestId('product-image-link')).toHaveLength(1);
expect(queryAllByTestId('product-image')).toHaveLength(0);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ describe('ProductCarousel', () => {
<ProductCarousel>
{items.map((item, index) => (
<ProductInfo key={index}>
<Parts.Image src={item.imageSrc} href={item.url} onClick={spies.imageClick} />
<Parts.Image
images={[{ src: item.imageSrc }]}
href={item.url}
onClick={spies.imageClick}
/>

<Parts.Prices
price={item.price}
Expand Down Expand Up @@ -98,7 +102,11 @@ describe('ProductCarousel', () => {
const { container } = render(
<ProductCarousel>
<ProductInfo>
<Parts.Image src={items[0].imageSrc} href={items[0].url} onClick={spies.imageClick} />
<Parts.Image
images={[{ src: items[0].imageSrc }]}
href={items[0].url}
onClick={spies.imageClick}
/>

<Parts.Prices
price={items[0].price}
Expand Down Expand Up @@ -140,7 +148,7 @@ describe('ProductCarousel', () => {
<ProductCarousel>
{items.map((item, index) => (
<ProductInfo key={index}>
<Parts.Image src={item.imageSrc} href={item.url} />
<Parts.Image images={[{ src: item.imageSrc }]} href={item.url} />

<Parts.Prices
price={item.price}
Expand All @@ -167,7 +175,7 @@ describe('ProductCarousel', () => {
<ProductCarousel>
{items.map((item, index) => (
<ProductInfo key={index}>
<Parts.Image src={item.imageSrc} href={item.url} />
<Parts.Image images={[{ src: item.imageSrc }]} href={item.url} />

<Parts.Prices
price={item.price}
Expand All @@ -191,7 +199,7 @@ describe('ProductCarousel', () => {
<ProductCarousel itemSize={{ xs: 3 }}>
{items.map((item, index) => (
<ProductInfo key={index}>
<Parts.Image src={item.imageSrc} href={item.url} />
<Parts.Image images={[{ src: item.imageSrc }]} href={item.url} />

<Parts.Prices
price={item.price}
Expand Down Expand Up @@ -223,7 +231,7 @@ describe('ProductCarousel', () => {
<ProductCarousel itemSize={{ xs: 3 }}>
{items.map((item, index) => (
<ProductInfo key={index}>
<Parts.Image src={item.imageSrc} href={item.url} />
<Parts.Image images={[{ src: item.imageSrc }]} href={item.url} />

<Parts.Prices
price={item.price}
Expand Down Expand Up @@ -326,7 +334,7 @@ describe('intersections', () => {
<ProductCarousel onNeedRequest={spy}>
{items.map((item, index) => (
<ProductInfo key={index}>
<Parts.Image src={item.imageSrc} href={item.url} />
<Parts.Image images={[{ src: item.imageSrc }]} href={item.url} />

<Parts.Prices
price={item.price}
Expand Down Expand Up @@ -358,7 +366,7 @@ describe('intersections', () => {
<ProductCarousel onInViewport={spy}>
{items.map((item, index) => (
<ProductInfo key={index}>
<Parts.Image src={item.imageSrc} href={item.url} />
<Parts.Image images={[{ src: item.imageSrc }]} href={item.url} />

<Parts.Prices
price={item.price}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ describe('ProductSlider', () => {
<ProductSlider>
{items.map((item, index) => (
<ProductInfo key={index}>
<Parts.Image src={item.imageSrc} href={item.url} onClick={spies.imageClick}>
<Parts.Image
images={[{ src: item.imageSrc }]}
href={item.url}
onClick={spies.imageClick}
>
<Parts.ImageButton
icon={FavoriteSVG}
hint='Добавить в избранное'
Expand Down Expand Up @@ -98,7 +102,7 @@ describe('intersections', () => {
<ProductSlider onNeedRequest={spy}>
{items.map((item, index) => (
<ProductInfo key={index}>
<Parts.Image src={item.imageSrc} href={item.url} />
<Parts.Image images={[{ src: item.imageSrc }]} href={item.url} />

<Parts.Prices
price={item.price}
Expand Down Expand Up @@ -130,7 +134,7 @@ describe('intersections', () => {
<ProductSlider onInViewport={spy}>
{items.map((item, index) => (
<ProductInfo key={index}>
<Parts.Image src={item.imageSrc} href={item.url} />
<Parts.Image images={[{ src: item.imageSrc }]} href={item.url} />

<Parts.Prices
price={item.price}
Expand Down

0 comments on commit a4163e6

Please sign in to comment.