Jacob314/add radio button keys (#10083)

This commit is contained in:
Jacob Richman
2025-09-28 14:50:47 -07:00
committed by GitHub
parent 1bd75f060d
commit 62ba330612
26 changed files with 263 additions and 112 deletions

View File

@@ -35,16 +35,20 @@ describe('BaseSelectionList', () => {
const mockOnHighlight = vi.fn();
const mockRenderItem = vi.fn();
// Define standard test items
const items = [
{ value: 'A', label: 'Item A' },
{ value: 'B', label: 'Item B', disabled: true },
{ value: 'C', label: 'Item C' },
{ value: 'A', label: 'Item A', key: 'A' },
{ value: 'B', label: 'Item B', disabled: true, key: 'B' },
{ value: 'C', label: 'Item C', key: 'C' },
];
// Helper to render the component with default props
const renderComponent = (
props: Partial<BaseSelectionListProps<string, { label: string }>> = {},
props: Partial<
BaseSelectionListProps<
string,
{ value: string; label: string; disabled?: boolean; key: string }
>
> = {},
activeIndex: number = 0,
) => {
vi.mocked(useSelectionList).mockReturnValue({
@@ -53,12 +57,16 @@ describe('BaseSelectionList', () => {
});
mockRenderItem.mockImplementation(
(item: (typeof items)[0], context: RenderItemContext) => (
<Text color={context.titleColor}>{item.label}</Text>
),
(
item: { value: string; label: string; disabled?: boolean; key: string },
context: RenderItemContext,
) => <Text color={context.titleColor}>{item.label}</Text>,
);
const defaultProps: BaseSelectionListProps<string, { label: string }> = {
const defaultProps: BaseSelectionListProps<
string,
{ value: string; label: string; disabled?: boolean; key: string }
> = {
items,
onSelect: mockOnSelect,
onHighlight: mockOnHighlight,
@@ -216,6 +224,7 @@ describe('BaseSelectionList', () => {
const longList = Array.from({ length: 15 }, (_, i) => ({
value: `Item ${i + 1}`,
label: `Item ${i + 1}`,
key: `Item ${i + 1}`,
}));
// We must increase maxItemsToShow (default 10) to see the 10th item and beyond
@@ -249,19 +258,22 @@ describe('BaseSelectionList', () => {
const longList = Array.from({ length: 10 }, (_, i) => ({
value: `Item ${i + 1}`,
label: `Item ${i + 1}`,
key: `Item ${i + 1}`,
}));
const MAX_ITEMS = 3;
const renderScrollableList = (initialActiveIndex: number = 0) => {
// Define the props used for the initial render and subsequent rerenders
const componentProps: BaseSelectionListProps<string, { label: string }> =
{
items: longList,
maxItemsToShow: MAX_ITEMS,
onSelect: mockOnSelect,
onHighlight: mockOnHighlight,
renderItem: mockRenderItem,
};
const componentProps: BaseSelectionListProps<
string,
{ value: string; label: string; key: string }
> = {
items: longList,
maxItemsToShow: MAX_ITEMS,
onSelect: mockOnSelect,
onHighlight: mockOnHighlight,
renderItem: mockRenderItem,
};
vi.mocked(useSelectionList).mockReturnValue({
activeIndex: initialActiveIndex,
@@ -428,6 +440,7 @@ describe('BaseSelectionList', () => {
const longList = Array.from({ length: 10 }, (_, i) => ({
value: `Item ${i + 1}`,
label: `Item ${i + 1}`,
key: `Item ${i + 1}`,
}));
const MAX_ITEMS = 3;