Repository: adobe/react-spectrum
File: packages/@react-spectrum/list/test/ListViewDnd.test.js (JavaScript)

Code before:
  let onDragMove = jest.fn();
  let onDragEnd = jest.fn();
  let onDrop = jest.fn();
  let onReorder = jest.fn();
  let onInsert = jest.fn();
  let onItemDrop = jest.fn();
  let onRootDrop = jest.fn();
  let getDropOperation = jest.fn();
  let mockUtilityOptions = {
    onInsert: async (e) => onInsert(e),
    onReorder: async (e) => onReorder(e),
    onItemDrop: async (e) => onItemDrop(e),
    onRootDrop: async (e) => onRootDrop(e)
  };
  let user;

  let checkSelection = (onSelectionChange, selectedKeys) => {
    expect(onSelectionChange).toHaveBeenCalledTimes(1);
    expect(new Set(onSelectionChange.mock.calls[0][0])).toEqual(new Set(selectedKeys));
  };

  beforeAll(function () {
    user = userEvent.setup({delay: null, pointerMap});
    // offsetWidth = jest.spyOn(window.HTMLElement.prototype, 'clientWidth', 'get').mockImplementation(() => 1000);
    // offsetHeight = jest.spyOn(window.HTMLElement.prototype, 'clientHeight', 'get').mockImplementation(() => 1000);
    // scrollHeight = jest.spyOn(window.HTMLElement.prototype, 'scrollHeight', 'get').mockImplementation(() => 40);
    jest.useFakeTimers();
  });

  afterEach(function () {
    fireEvent.keyDown(document.activeElement, {key: 'Escape'});
    fireEvent.keyUp(document.activeElement, {key: 'Escape'});
    jest.clearAllMocks();
  });

  afterAll(function () {
    // offsetWidth.mockReset();
    // offsetHeight.mockReset();
    // scrollHeight.mockReset();
  });

  let render = (children, locale = 'en-US', scale = 'medium') => {
    let tree = renderComponent(
      <Provider theme={theme} scale={scale} locale={locale}>
        {children}
      </Provider>
  );
    // Allow for Virtualizer layout to update
    act(() => {jest.runAllTimers();});
    return {
      ...tree,

Review comment (suggestion):
The DnD tests can be run if we mock the following lines:
https://github.com/adobe/react-spectrum/blob/7c7e84624629d4963ff500cbd75a3412cb3a9e8f/packages/%40react-aria/virtualizer/src/useVirtualizerItem.ts#L48 to a defined value
and
https://github.com/adobe/react-spectrum/blob/7c7e84624629d4963ff500cbd75a3412cb3a9e8f/packages/%40react-stately/virtualizer/src/Virtualizer.ts#L145 changing the `offset.x` value to something that isn't NaN so that https://github.com/adobe/react-spectrum/blob/7c7e84624629d4963ff500cbd75a3412cb3a9e8f/packages/%40react-stately/layout/src/ListLayout.ts#L558 doesn't resolve to NaN. 

The `offset.x` needs to be non-zero for reasons that aren't clear to me yet, changing https://github.com/adobe/react-spectrum/blob/7c7e84624629d4963ff500cbd75a3412cb3a9e8f/packages/%40react-stately/virtualizer/src/Virtualizer.ts#L526 to provide a non Nan/non-zero `contentOffsetX` value to `_setContentOffset` has the same effect as changing line 145


Code after:
  let onDragMove = jest.fn();
  let onDragEnd = jest.fn();
  let onDrop = jest.fn();
  let onReorder = jest.fn();
  let onInsert = jest.fn();
  let onItemDrop = jest.fn();
  let onRootDrop = jest.fn();
  let getDropOperation = jest.fn();
  let mockUtilityOptions = {
    onInsert: async (e) => onInsert(e),
    onReorder: async (e) => onReorder(e),
    onItemDrop: async (e) => onItemDrop(e),
    onRootDrop: async (e) => onRootDrop(e)
  };
  let user;

  let checkSelection = (onSelectionChange, selectedKeys) => {
    expect(onSelectionChange).toHaveBeenCalledTimes(1);
    expect(new Set(onSelectionChange.mock.calls[0][0])).toEqual(new Set(selectedKeys));
  };

  beforeAll(function () {
    user = userEvent.setup({delay: null, pointerMap});
    offsetWidth = jest.spyOn(window.HTMLElement.prototype, 'clientWidth', 'get').mockImplementation(() => 1000);
    offsetHeight = jest.spyOn(window.HTMLElement.prototype, 'clientHeight', 'get').mockImplementation(() => 1000);
    scrollHeight = jest.spyOn(window.HTMLElement.prototype, 'scrollHeight', 'get').mockImplementation(() => 40);
    jest.useFakeTimers();
  });

  afterEach(function () {
    fireEvent.keyDown(document.activeElement, {key: 'Escape'});
    fireEvent.keyUp(document.activeElement, {key: 'Escape'});
    jest.clearAllMocks();
  });

  afterAll(function () {
    offsetWidth.mockReset();
    offsetHeight.mockReset();
    scrollHeight.mockReset();
  });

  let render = (children, locale = 'en-US', scale = 'medium') => {
    let tree = renderComponent(
      <Provider theme={theme} scale={scale} locale={locale}>
        {children}
      </Provider>
  );
    // Allow for Virtualizer layout to update
    act(() => {jest.runAllTimers();});
    return {
      ...tree,