Skip to content

Commit

Permalink
Update test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
kyledurand committed Jan 8, 2020
1 parent 5b51e61 commit b8cb9d9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
1 change: 0 additions & 1 deletion src/components/Frame/Frame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,6 @@ class Frame extends React.PureComponent<CombinedProps, State> {
} = this.props;

const mobileNavShowing = isNavigationCollapsed && showMobileNavigation;

if (mobileNavShowing && key === 'Escape') {
this.handleNavigationDismiss();
}
Expand Down
26 changes: 18 additions & 8 deletions src/components/Frame/tests/Frame.test.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import React from 'react';
import {CSSTransition} from '@material-ui/react-transition-group';
import {animationFrame} from '@shopify/jest-dom-mocks';
import {documentHasStyle} from 'test-utilities';
import {documentHasStyle, mountWithApp} from 'test-utilities';
// eslint-disable-next-line no-restricted-imports
import {mountWithAppProvider, trigger} from 'test-utilities/legacy';
import {
TrapFocus,
ContextualSaveBar as PolarisContextualSavebar,
Loading as PolarisLoading,
} from 'components';
import Frame from '../Frame';
import Frame, {FrameProps} from '../Frame';
import {
ContextualSaveBar as FrameContextualSavebar,
Loading as FrameLoading,
Expand Down Expand Up @@ -195,25 +195,35 @@ describe('<Frame />', () => {

it('does not call onNavigationDismiss when escape is pressed and screen size is large', () => {
const spy = jest.fn();
const frame = mountWithAppProvider(
const frame = mountWithApp(
<Frame navigation={<div />} onNavigationDismiss={spy} />,
);
trigger(frame.find('div').at(3), 'onKeyDown', {key: 'Escape'});
expect(frame.prop('onNavigationDismiss')).not.toHaveBeenCalled();
frame
.find('div', {id: 'AppFrameNav'})!
.trigger('onKeyDown', {key: 'Escape'});

const {onNavigationDismiss} = frame.props as FrameProps;

expect(onNavigationDismiss).not.toHaveBeenCalled();
});

it('calls onNavigationDismiss when escape is pressed and screen size is small', () => {
const spy = jest.fn();
const frame = mountWithAppProvider(
const frame = mountWithApp(
<Frame
navigation={<div />}
showMobileNavigation
onNavigationDismiss={spy}
/>,
{mediaQuery: {isNavigationCollapsed: true}},
);
trigger(frame.find('div').at(3), 'onKeyDown', {key: 'Escape'});
expect(frame.prop('onNavigationDismiss')).toHaveBeenCalledTimes(1);
frame
.find('div', {id: 'AppFrameNav'})!
.trigger('onKeyDown', {key: 'Escape'});

const {onNavigationDismiss} = frame.props as FrameProps;

expect(onNavigationDismiss).toHaveBeenCalledTimes(1);
});
});

Expand Down

0 comments on commit b8cb9d9

Please sign in to comment.