Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions packages/@react-aria/aria-modal-polyfill/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,27 @@ import {ActionButton, Button} from '@react-spectrum/button';
import {Content} from '@react-spectrum/view';
import {Dialog, DialogTrigger} from '@react-spectrum/dialog';
import {Item, Menu, MenuTrigger, Section} from '@react-spectrum/menu';
import MatchMediaMock from 'jest-matchmedia-mock';
import {Provider} from '@react-spectrum/provider';
import React from 'react';
import {theme} from '@react-spectrum/theme-default';
import {watchModals} from '../';

describe('watchModals', () => {
let matchMedia;
beforeAll(() => {
jest.useFakeTimers('legacy');
});

afterAll(() => {
jest.useRealTimers();
jest.clearAllMocks();
});

beforeEach(() => {
matchMedia = new MatchMediaMock();
jest.spyOn(window, 'requestAnimationFrame').mockImplementation(cb => cb());
});

afterEach(() => {
jest.runAllTimers();
matchMedia.clear();
window.requestAnimationFrame.mockRestore();
});

Expand Down Expand Up @@ -227,7 +225,7 @@ describe('watchModals', () => {
]}
];
// menu should be a tray
matchMedia.useMediaQuery('(max-width: 700px)');
jest.spyOn(window.screen, 'width', 'get').mockImplementation(() => 700);
watchModals();
let {getByLabelText, getByRole, queryByRole} = render(
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ describe('useSelectableCollection', () => {
`('always uses toggle for $type', ({prepare, actions: [start, end]}) => {
prepare();
it('uses toggle mode when the interaction is touch', () => {
jest.spyOn(window.screen, 'width', 'get').mockImplementation(() => 600);
jest.spyOn(window.screen, 'width', 'get').mockImplementation(() => 700);
let {getAllByRole} = render(
<List selectionMode="multiple" selectionBehavior="replace">
<Item>Paco de Lucia</Item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1409,7 +1409,7 @@ describe('SearchAutocomplete', function () {

describe('mobile searchAutocomplete', function () {
beforeEach(() => {
jest.spyOn(window.screen, 'width', 'get').mockImplementation(() => 600);
jest.spyOn(window.screen, 'width', 'get').mockImplementation(() => 700);
});

afterEach(() => {
Expand Down
2 changes: 1 addition & 1 deletion packages/@react-spectrum/combobox/test/ComboBox.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3600,7 +3600,7 @@ describe('ComboBox', function () {

describe('mobile combobox', function () {
beforeEach(() => {
jest.spyOn(window.screen, 'width', 'get').mockImplementation(() => 600);
jest.spyOn(window.screen, 'width', 'get').mockImplementation(() => 700);
});

afterEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {theme} from '@react-spectrum/theme-default';
describe('ContextualHelp', function () {
beforeAll(() => {
jest.useFakeTimers();
jest.spyOn(window.screen, 'width', 'get').mockImplementation(() => 1024);
});
afterAll(() => {
jest.clearAllMocks();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ function render(el) {
}

describe('DatePickerBase', function () {
beforeAll(() => {
jest.spyOn(window.screen, 'width', 'get').mockImplementation(() => 1024);
});

afterAll(() => {
jest.clearAllMocks();
});

describe('basics', function () {
it.each`
Name | Component | numSegments
Expand Down
5 changes: 2 additions & 3 deletions packages/@react-spectrum/dialog/src/DialogTrigger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {OverlayTriggerState, useOverlayTriggerState} from '@react-stately/overla
import {PressResponder} from '@react-aria/interactions';
import React, {Fragment, ReactElement, useEffect, useRef} from 'react';
import {SpectrumDialogClose, SpectrumDialogProps, SpectrumDialogTriggerProps} from '@react-types/dialog';
import {useMediaQuery} from '@react-spectrum/utils';
import {useIsMobileDevice} from '@react-spectrum/utils';
import {useOverlayTrigger} from '@react-aria/overlays';

function DialogTrigger(props: SpectrumDialogTriggerProps) {
Expand All @@ -37,8 +37,7 @@ function DialogTrigger(props: SpectrumDialogTriggerProps) {
let [trigger, content] = children as [ReactElement, SpectrumDialogClose];

// On small devices, show a modal or tray instead of a popover.
// TODO: DNA variable?
let isMobile = useMediaQuery('(max-width: 700px)');
let isMobile = useIsMobileDevice();
if (isMobile) {
// handle cases where desktop popovers need a close button for the mobile modal view
if (type !== 'modal' && mobileType === 'modal') {
Expand Down
13 changes: 5 additions & 8 deletions packages/@react-spectrum/dialog/test/DialogTrigger.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {Content} from '@react-spectrum/view';
import {Dialog, DialogTrigger} from '../';
import {Heading} from '@react-spectrum/text';
import {Item, Menu, MenuTrigger} from '@react-spectrum/menu';
import MatchMediaMock from 'jest-matchmedia-mock';
import {Provider} from '@react-spectrum/provider';
import React from 'react';
import {TextField} from '@react-spectrum/textfield';
Expand All @@ -26,10 +25,9 @@ import userEvent from '@testing-library/user-event';


describe('DialogTrigger', function () {
let matchMedia;
let warnMock;
let windowSpy;
beforeAll(() => {
jest.spyOn(window.screen, 'width', 'get').mockImplementation(() => 1024);
jest.useFakeTimers('legacy');
});
afterAll(() => {
Expand All @@ -38,7 +36,7 @@ describe('DialogTrigger', function () {
});

beforeEach(() => {
matchMedia = new MatchMediaMock();
windowSpy = jest.spyOn(window.screen, 'width', 'get').mockImplementation(() => 1024);
// this needs to be a setTimeout so that the dialog can be removed from the dom before the callback is invoked
jest.spyOn(window, 'requestAnimationFrame').mockImplementation(cb => setTimeout(() => cb(), 0));
if (process.env.STRICT_MODE) {
Expand All @@ -57,7 +55,6 @@ describe('DialogTrigger', function () {
});
}

matchMedia.clear();
window.requestAnimationFrame.mockRestore();

if (process.env.STRICT_MODE && warnMock.mock.calls.length > 0) {
Expand Down Expand Up @@ -187,7 +184,7 @@ describe('DialogTrigger', function () {
});

it('should trigger a modal instead of a popover on mobile', function () {
matchMedia.useMediaQuery('(max-width: 700px)');
windowSpy.mockImplementation(() => 700);
let {getByRole, queryByRole, getByTestId} = render(
<Provider theme={theme}>
<DialogTrigger type="popover">
Expand All @@ -214,7 +211,7 @@ describe('DialogTrigger', function () {
});

it('should trigger a tray instead of a popover on mobile if mobileType="tray"', function () {
matchMedia.useMediaQuery('(max-width: 700px)');
windowSpy.mockImplementation(() => 700);
let {getByRole, queryByRole, getByTestId} = render(
<Provider theme={theme}>
<DialogTrigger type="popover" mobileType="tray">
Expand Down Expand Up @@ -696,7 +693,7 @@ describe('DialogTrigger', function () {
});

it('mobile type modals should be closable by clicking outside the modal', async function () {
matchMedia.useMediaQuery('(max-width: 700px)');
windowSpy.mockImplementation(() => 700);
function Test({defaultOpen, onOpenChange}) {
return (
<Provider theme={theme}>
Expand Down
9 changes: 3 additions & 6 deletions packages/@react-spectrum/form/test/Form.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {Content, Header} from '@react-spectrum/view';
import {ContextualHelp} from '@react-spectrum/contextualhelp';
import {Form} from '../';
import {Item, Picker} from '@react-spectrum/picker';
import MatchMediaMock from 'jest-matchmedia-mock';
import {Provider} from '@react-spectrum/provider';
import React from 'react';
import {render, triggerPress} from '@react-spectrum/test-utils';
Expand All @@ -26,13 +25,13 @@ import userEvent from '@testing-library/user-event';
import {within} from '@testing-library/dom';

describe('Form', function () {
let matchMedia;
beforeAll(() => {
jest.useFakeTimers();
jest.spyOn(window.screen, 'width', 'get').mockImplementation(() => 700);
});

beforeEach(() => {
matchMedia = new MatchMediaMock();
afterAll(() => {
jest.clearAllMocks();
});

it('should render a form', () => {
Expand Down Expand Up @@ -199,8 +198,6 @@ describe('Form', function () {
});

it('contextual help should not be disabled nor should its dismiss button be disabled', () => {
matchMedia.useMediaQuery('(max-width: 700px)');

let {getByRole, getByLabelText} = render(
<Provider theme={theme}>
<Form aria-label="Test" isDisabled>
Expand Down