Skip to content

Commit 24a5aa2

Browse files
committed
Fix some test coverage
1 parent bf73e54 commit 24a5aa2

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

src/internal/components/sortable-area/keyboard-sensor/index.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export type KeyboardAndUAPCoordinateGetter = (
3131
) => Coordinates | void;
3232

3333
type KeyboardAndUAPSensorOptions = KeyboardSensorOptions & {
34-
coordinateGetter?: KeyboardAndUAPCoordinateGetter;
34+
coordinateGetter: KeyboardAndUAPCoordinateGetter;
3535
onActivation?({ event }: { event: KeyboardEvent | MouseEvent }): void;
3636
};
3737

@@ -131,10 +131,6 @@ export class KeyboardAndUAPSensor implements SensorInstance {
131131
this.referenceCoordinates = currentCoordinates;
132132
}
133133

134-
if (!coordinateGetter) {
135-
return;
136-
}
137-
138134
const newCoordinates = coordinateGetter(event, {
139135
active,
140136
context: context.current,

src/list/__tests__/list-sortable.test.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,17 @@ describe('List - Sortable', () => {
135135
await expectAnnouncement('Item moved from position 1 to position 2 of 3');
136136
});
137137

138+
test('ignores other keys', async () => {
139+
const { wrapper } = renderSortableList();
140+
const dragHandle = wrapper.findItemByIndex(1)!.findDragHandle()!.getElement();
141+
pressKey(dragHandle, 'Space');
142+
await expectAnnouncement('Picked up item at position 1 of 3');
143+
pressKey(dragHandle, 'D');
144+
pressKey(dragHandle, 'Space');
145+
expect(wrapper.findItemByIndex(1)!.getElement()).toHaveTextContent('Item 1');
146+
expect(wrapper.findItemByIndex(2)!.getElement()).toHaveTextContent('Item 2');
147+
});
148+
138149
test('can move an item with UAP buttons', async () => {
139150
const { wrapper } = renderSortableList();
140151
const dragHandle = wrapper.findItemByIndex(1)!.findDragHandle()!.getElement();
@@ -157,4 +168,14 @@ describe('List - Sortable', () => {
157168
expect(wrapper.findItemByIndex(2)!.getElement()).toHaveTextContent('Item 1');
158169
await expectAnnouncement('Item moved from position 1 to position 2 of 3');
159170
});
171+
172+
test('non-primary pointer events do not activate UAP', () => {
173+
const { wrapper } = renderSortableList();
174+
const dragHandle = wrapper.findItemByIndex(1)!.findDragHandle()!;
175+
const dragWrapper = new InternalDragHandleWrapper(document.body);
176+
expect(dragWrapper.findVisibleDirectionButtonBlockEnd()).toBeFalsy();
177+
178+
dragHandle.click({ button: 1 });
179+
expect(dragWrapper.findVisibleDirectionButtonBlockEnd()).toBeFalsy();
180+
});
160181
});

0 commit comments

Comments
 (0)