Skip to content

Commit

Permalink
Fix merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
snowystinger committed Sep 25, 2024
1 parent 1944f5a commit 73a868c
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 125 deletions.
2 changes: 1 addition & 1 deletion packages/@react-aria/test-utils/src/combobox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {act, waitFor, within} from '@testing-library/react';
import {BaseTesterOpts, UserOpts} from './user';

export interface ComboBoxOptions extends UserOpts, BaseTesterOpts {
user: any,
user?: any,
trigger?: HTMLElement
}

Expand Down
2 changes: 1 addition & 1 deletion packages/@react-aria/test-utils/src/gridlist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {BaseTesterOpts, UserOpts} from './user';
import {pressElement} from './events';

export interface GridListOptions extends UserOpts, BaseTesterOpts {
user: any
user?: any
}
export class GridListTester {
private user;
Expand Down
30 changes: 19 additions & 11 deletions packages/@react-aria/test-utils/src/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {BaseTesterOpts, UserOpts} from './user';
import {triggerLongPress} from './events';

export interface MenuOptions extends UserOpts, BaseTesterOpts {
user: any,
user?: any,
isSubmenu?: boolean
}
export class MenuTester {
Expand Down Expand Up @@ -56,10 +56,9 @@ export class MenuTester {
open = async (opts: {needsLongPress?: boolean, interactionType?: UserOpts['interactionType'], direction?: 'up' | 'down'} = {}) => {
let {
needsLongPress,
interactionType = this._interactionType
interactionType = this._interactionType,
direction
} = opts;

let trigger = this.trigger;
let isDisabled = trigger.hasAttribute('disabled');
if (interactionType === 'mouse' || interactionType === 'touch') {
Expand Down Expand Up @@ -114,7 +113,7 @@ export class MenuTester {
menuSelectionMode?: 'single' | 'multiple',
needsLongPress?: boolean,
closesOnSelect?: boolean,
interactionType = this._interactionType,
interactionType?: UserOpts['interactionType'],
keyboardActivation?: 'Space' | 'Enter'
}) => {
let {
Expand All @@ -123,18 +122,23 @@ export class MenuTester {
needsLongPress,
closesOnSelect = true,
option,
interactionType = this._interactionType
interactionType = this._interactionType,
keyboardActivation = 'Enter'
} = opts;
let trigger = this.trigger;
if (!trigger.getAttribute('aria-controls')) {

if (!trigger.getAttribute('aria-controls') && !trigger.hasAttribute('aria-expanded')) {
await this.open({needsLongPress});
}

let menu = this.menu;
if (menu) {
if (!option && optionText) {
option = within(menu).getByText(optionText).closest('[role=menuitem], [role=menuitemradio], [role=menuitemcheckbox]');
// @ts-ignore
option = (within(menu!).getByText(optionText).closest('[role=menuitem], [role=menuitemradio], [role=menuitemcheckbox]'))!;
}
if (!option) {
throw new Error('No option found in the menu.');
}

if (interactionType === 'keyboard') {
Expand Down Expand Up @@ -179,6 +183,7 @@ export class MenuTester {
needsLongPress,
interactionType = this._interactionType
} = opts;

let trigger = this.trigger;
let isDisabled = trigger.hasAttribute('disabled');
if (!trigger.getAttribute('aria-controls') && !isDisabled) {
Expand Down Expand Up @@ -216,12 +221,12 @@ export class MenuTester {

keyboardNavigateToOption = async (opts: {option: HTMLElement}) => {
let {option} = opts;
let options = this.getOptions();
let options = this.options;
let targetIndex = options.indexOf(option);
if (targetIndex === -1) {
throw new Error('Option provided is not in the menu');
}
if (document.activeElement === this.getMenu()) {
if (document.activeElement === this.menu) {
await this.user.keyboard('[ArrowDown]');
}
let currIndex = options.indexOf(document.activeElement as HTMLElement);
Expand Down Expand Up @@ -257,15 +262,18 @@ export class MenuTester {
};

get trigger() {
if (!this._trigger) {
throw new Error('No trigger element found for menu.');
}
return this._trigger;
}

get menu() {
let menuId = this.trigger.getAttribute('aria-controls');
let menuId = (this.trigger!).getAttribute('aria-controls');
return menuId ? document.getElementById(menuId) : undefined;
}

get options(): HTMLElement[] | never[] {
get options(): HTMLElement[] {
let menu = this.menu;
let options: HTMLElement[] = [];
if (menu) {
Expand Down
2 changes: 1 addition & 1 deletion packages/@react-aria/test-utils/src/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {BaseTesterOpts, UserOpts} from './user';

export interface SelectOptions extends UserOpts, BaseTesterOpts {
// TODO: I think the type grabbed from the testing library dist for UserEvent is breaking the build, will need to figure out a better place to grab from
user: any
user?: any
}
export class SelectTester {
private user;
Expand Down
2 changes: 1 addition & 1 deletion packages/@react-aria/test-utils/src/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {act, fireEvent, waitFor, within} from '@testing-library/react';
import {BaseTesterOpts, UserOpts} from './user';
import {pressElement, triggerLongPress} from './events';
export interface TableOptions extends UserOpts, BaseTesterOpts {
user: any,
user?: any,
advanceTimer: UserOpts['advanceTimer']
}

Expand Down
Loading

0 comments on commit 73a868c

Please sign in to comment.