environments/review-pin-avatar-gltngk/deployments/1819
Chewbacca 2 years ago
parent b6afb8ae01
commit 51146574d4

@ -8,7 +8,7 @@ import { render, screen, waitFor } from '../../../jest/test-helpers';
import FeedCarousel from '../feed-carousel'; import FeedCarousel from '../feed-carousel';
jest.mock('../../../hooks/useDimensions', () => ({ jest.mock('../../../hooks/useDimensions', () => ({
useDimensions: () => [{ scrollWidth: 190 }, null, { width: 100 }], useDimensions: () => [{ scrollWidth: 190 }, null, { width: 300 }],
})); }));
(window as any).ResizeObserver = class ResizeObserver { (window as any).ResizeObserver = class ResizeObserver {
@ -21,27 +21,6 @@ jest.mock('../../../hooks/useDimensions', () => ({
describe('<FeedCarousel />', () => { describe('<FeedCarousel />', () => {
let store: any; let store: any;
describe('with "carousel" disabled', () => {
beforeEach(() => {
store = {
instance: {
version: '2.7.2 (compatible; Pleroma 2.4.52-1337-g4779199e.gleasonator+soapbox)',
pleroma: ImmutableMap({
metadata: ImmutableMap({
features: [],
}),
}),
},
};
});
it('should render nothing', () => {
render(<FeedCarousel />, undefined, store);
expect(screen.queryAllByTestId('feed-carousel')).toHaveLength(0);
});
});
describe('with "carousel" enabled', () => { describe('with "carousel" enabled', () => {
beforeEach(() => { beforeEach(() => {
store = { store = {
@ -167,15 +146,15 @@ describe('<FeedCarousel />', () => {
render(<FeedCarousel />, undefined, store); render(<FeedCarousel />, undefined, store);
await waitFor(() => { await waitFor(() => {
expect(screen.getByTestId('next-page')).toBeInTheDocument(); expect(screen.getByTestId('prev-page')).toHaveAttribute('disabled');
expect(screen.queryAllByTestId('prev-page')).toHaveLength(0); expect(screen.getByTestId('next-page')).not.toHaveAttribute('disabled');
}); });
await user.click(screen.getByTestId('next-page')); await user.click(screen.getByTestId('next-page'));
await waitFor(() => { await waitFor(() => {
expect(screen.getByTestId('prev-page')).toBeInTheDocument(); expect(screen.getByTestId('prev-page')).not.toHaveAttribute('disabled');
expect(screen.queryAllByTestId('next-page')).toHaveLength(0); expect(screen.getByTestId('next-page')).toHaveAttribute('disabled');
}); });
}); });
}); });

@ -83,7 +83,7 @@ const CarouselItem = React.forwardRef((
}); });
const FeedCarousel = () => { const FeedCarousel = () => {
const { data: avatars, isFetching, isError } = useCarouselAvatars(); const { data: avatars, isFetching, isFetched, isError } = useCarouselAvatars();
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
const [_ref, setContainerRef, { width }] = useDimensions(); const [_ref, setContainerRef, { width }] = useDimensions();
@ -141,6 +141,10 @@ const FeedCarousel = () => {
); );
} }
if (isFetched && avatars.length === 0) {
return null;
}
return ( return (
<div <div
className='rounded-xl bg-white dark:bg-primary-900 shadow-lg dark:shadow-none overflow-hidden' className='rounded-xl bg-white dark:bg-primary-900 shadow-lg dark:shadow-none overflow-hidden'

Loading…
Cancel
Save