Skip to content

Commit

Permalink
Merge branch 'master' into replace-user-type-with-user-keyboard
Browse files Browse the repository at this point in the history
  • Loading branch information
WesCossick authored Jan 30, 2023
2 parents ca402da + 3b216e0 commit 764884a
Showing 1 changed file with 10 additions and 93 deletions.
103 changes: 10 additions & 93 deletions src/use-dropdown-menu.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Imports
import React, { useState } from 'react';
import useDropdownMenu, { DropdownMenuOptions } from './use-dropdown-menu';
import { fireEvent, render, screen } from '@testing-library/react';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { UserEvent } from '@testing-library/user-event/dist/types/setup/setup';

Expand Down Expand Up @@ -183,14 +183,7 @@ it('Moves the focus to the next element in the menu after pressing the down arro

expect(screen.getByText('1 Item')).toHaveFocus();

fireEvent(
screen.getByText('1 Item'),
new KeyboardEvent('keydown', {
key: 'ArrowDown',
bubbles: true,
cancelable: true,
})
);
await user.keyboard('{ArrowDown}');

expect(screen.getByText('2 Item')).toHaveFocus();
});
Expand All @@ -204,25 +197,11 @@ it('Moves the focus to the previous element in the menu after pressing the up ar

expect(screen.getByText('1 Item')).toHaveFocus();

fireEvent(
screen.getByText('1 Item'),
new KeyboardEvent('keydown', {
key: 'ArrowDown',
bubbles: true,
cancelable: true,
})
);
await user.keyboard('{ArrowDown}');

expect(screen.getByText('2 Item')).toHaveFocus();

fireEvent(
screen.getByText('2 Item'),
new KeyboardEvent('keydown', {
key: 'ArrowUp',
bubbles: true,
cancelable: true,
})
);
await user.keyboard('{ArrowUp}');

expect(screen.getByText('1 Item')).toHaveFocus();
});
Expand All @@ -236,14 +215,7 @@ it('Wraps the focus to the last element when pressing the up arrow at the beginn

expect(screen.getByText('1 Item')).toHaveFocus();

fireEvent(
screen.getByText('1 Item'),
new KeyboardEvent('keydown', {
key: 'ArrowUp',
bubbles: true,
cancelable: true,
})
);
await user.keyboard('{ArrowUp}');

expect(screen.getByText('4 Item')).toHaveFocus();
});
Expand All @@ -257,25 +229,11 @@ it('Wraps the focus to the first element when pressing the down arrow at the end

expect(screen.getByText('1 Item')).toHaveFocus();

fireEvent(
screen.getByText('1 Item'),
new KeyboardEvent('keydown', {
key: 'ArrowUp',
bubbles: true,
cancelable: true,
})
);
await user.keyboard('{ArrowUp}');

expect(screen.getByText('4 Item')).toHaveFocus();

fireEvent(
screen.getByText('4 Item'),
new KeyboardEvent('keydown', {
key: 'ArrowDown',
bubbles: true,
cancelable: true,
})
);
await user.keyboard('{ArrowDown}');

expect(screen.getByText('1 Item')).toHaveFocus();
});
Expand Down Expand Up @@ -350,50 +308,9 @@ it('Can navigate to a dynamically-added item', async () => {

await user.click(screen.getByText('Primary'));

fireEvent(
screen.getByText('Primary'),
new KeyboardEvent('keydown', {
key: 'ArrowDown',
bubbles: true,
cancelable: true,
})
);

fireEvent(
screen.getByText('1 Item'),
new KeyboardEvent('keydown', {
key: 'ArrowDown',
bubbles: true,
cancelable: true,
})
);

fireEvent(
screen.getByText('2 Item'),
new KeyboardEvent('keydown', {
key: 'ArrowDown',
bubbles: true,
cancelable: true,
})
);

fireEvent(
screen.getByText('3 Item'),
new KeyboardEvent('keydown', {
key: 'ArrowDown',
bubbles: true,
cancelable: true,
})
);

fireEvent(
screen.getByText('4 Item'),
new KeyboardEvent('keydown', {
key: 'ArrowDown',
bubbles: true,
cancelable: true,
})
);
for (let i = 0; i < 4; i += 1) {
await user.keyboard('{ArrowDown}');
}

expect(screen.getByText('5 Item')).toHaveFocus();
});
Expand Down

0 comments on commit 764884a

Please sign in to comment.