Skip to content

Commit

Permalink
Merge pull request #86 from sima-land/85-product-carousel-fix
Browse files Browse the repository at this point in the history
#85  ProductCarousel: исправить ошибку при удалении контента при показанной всплывающей карточке
  • Loading branch information
krutoo authored Feb 22, 2022
2 parents 263b8b7 + be94cd5 commit e72e170
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/desktop/components/product-carousel/__test__/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { HoverCard } from '../hover-card';
import { Carousel } from '@sima-land/ui-nucleons/carousel';
import { Parts, ProductInfo } from '../../../../common/components/product-info';
import { LayerProvider } from '@sima-land/ui-nucleons/helpers/layer';
import { Stepper } from '@sima-land/ui-nucleons/stepper';

jest.mock('@sima-land/ui-nucleons/hooks/media', () => {
const original = jest.requireActual('@sima-land/ui-nucleons/hooks/media');
Expand Down Expand Up @@ -269,4 +270,40 @@ describe('<ProductCarousel />', () => {
expect(button.style.zIndex).toBe('22');
});
});

it('should handle removing content when hover card is shown', () => {
const TestComponent = ({ withContent }: { withContent?: boolean }) => (
<ProductCarousel withHoverCard>
{(withContent ? items : []).map((item, index) => (
<ProductInfo key={index}>
<Parts.Image src={item.imageSrc} href={item.url} />

<Parts.Prices
price={item.price}
oldPrice={item.oldPrice}
currencyGrapheme={item.currencyGrapheme}
/>

<Parts.Title href={item.url}>{item.name}</Parts.Title>

<Parts.Footer>
<Parts.CartControl stepText='По 5 шт'>
<Stepper defaultValue={3} size='s' style={{ width: '122px' }} />
</Parts.CartControl>
</Parts.Footer>
</ProductInfo>
))}
</ProductCarousel>
);

const { queryAllByTestId, getAllByTestId, rerender } = render(<TestComponent withContent />);

expect(queryAllByTestId('product-card:hover-card')).toHaveLength(0);
fireEvent.mouseEnter(getAllByTestId('product-carousel:item')[0]);
expect(queryAllByTestId('product-card:hover-card')).toHaveLength(1);

expect(() => {
rerender(<TestComponent withContent={false} />);
}).not.toThrow();
});
});
1 change: 1 addition & 0 deletions src/desktop/components/product-carousel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ export const ProductCarousel = ({
{/* ВАЖНО: чтобы размонтировать всплывающую карточку строго каждый раз используем массив и key */}
{withHoverCard &&
activeItemIndex !== null &&
items[activeItemIndex] &&
[items[activeItemIndex]].map(item => (
<HoverCard
key={activeItemIndex}
Expand Down

0 comments on commit e72e170

Please sign in to comment.