Skip to content

Commit

Permalink
chore: update naming; move qa attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisVershkov committed Apr 16, 2024
1 parent b6046be commit 8d491eb
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 11 deletions.
6 changes: 2 additions & 4 deletions src/components/List/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ import AutoSizer from 'react-virtualized-auto-sizer';
import type {VariableSizeListProps} from 'react-window';
import {VariableSizeList} from 'react-window';

import {SelectLoadingIndicator} from '../Select/components/SelectList/SelectLoadingIndicator';
import {TextInput} from '../controls';
import {MobileContext} from '../mobile';
import {useDirection} from '../theme';
import {block} from '../utils/cn';
import {getUniqId} from '../utils/common';

import {ListLoadingIndicator} from './ListLoadingIndicator';
import {ListItem, SimpleContainer, defaultRenderItem} from './components';
import {listNavigationIgnoredKeys} from './constants';
import type {ListItemData, ListItemProps, ListProps} from './types';
Expand Down Expand Up @@ -260,9 +260,7 @@ export class List<T = unknown> extends React.Component<ListProps<T>, ListState<T
const {onLoadMore} = this.props;

if (isObject(item) && 'value' in item && item.value === this.loadingItem.value) {
return (
<SelectLoadingIndicator onIntersect={itemIndex === 0 ? undefined : onLoadMore} />
);
return <ListLoadingIndicator onIntersect={itemIndex === 0 ? undefined : onLoadMore} />;
}

return this.props.renderItem
Expand Down
4 changes: 2 additions & 2 deletions src/components/List/ListLoadingIndicator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import {Loader} from '../Loader';
import {block} from '../utils/cn';

const b = block('list');
export const SelectLoadingIndicator = (props: {onIntersect?: () => void}) => {
export const ListLoadingIndicator = (props: {onIntersect?: () => void}) => {
const ref = React.useRef<HTMLDivElement | null>(null);

useIntersection({element: ref.current, onIntersect: props?.onIntersect});

return (
<div ref={ref} className={b('loading-indicator')}>
<Loader />
<Loader qa={'list-loader'} />
</div>
);
};
8 changes: 4 additions & 4 deletions src/components/List/__tests__/List.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ describe('base List', () => {
it('should render loading indicator', () => {
setup({virtualized: false, onLoadMore: mockOnLoadMorFn, loading: true});

const loader = screen.getByTestId('loader');
const loader = screen.getByTestId('list-loader');
expect(loader).toBeInTheDocument();
});
it('should call onLoadMore callback when loading indicator is visible', () => {
setup({virtualized: false, onLoadMore: mockOnLoadMorFn, loading: true});

const loader = screen.getByTestId('loader');
const loader = screen.getByTestId('list-loader');

expect(loader).toBeVisible();
expect(mockOnLoadMorFn).toHaveBeenCalled();
Expand All @@ -54,14 +54,14 @@ describe('virtualized List', () => {
it('should render loading indicator', () => {
setup({virtualized: true, onLoadMore: mockOnLoadMorFn, loading: true});

const loader = screen.getByTestId('loader');
const loader = screen.getByTestId('list-loader');
expect(loader).toBeInTheDocument();
});

it('should call onLoadMore callback when loading indicator is visible', () => {
setup({virtualized: true, onLoadMore: mockOnLoadMorFn, loading: true});

const loader = screen.getByTestId('loader');
const loader = screen.getByTestId('list-loader');
expect(loader).toBeVisible();
expect(mockOnLoadMorFn).toHaveBeenCalled();
});
Expand Down
2 changes: 1 addition & 1 deletion src/components/Loader/Loader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface LoaderProps extends QAProps {
size?: LoaderSize;
}

export function Loader({size = 's', className, qa = 'loader'}: LoaderProps) {
export function Loader({size = 's', className, qa}: LoaderProps) {
return (
<div className={b({size}, className)} data-qa={qa}>
<div className={b('left')} />
Expand Down

0 comments on commit 8d491eb

Please sign in to comment.