Skip to content
This repository has been archived by the owner on May 24, 2024. It is now read-only.

Commit

Permalink
Revert jest changes
Browse files Browse the repository at this point in the history
  • Loading branch information
swetasingh9714 committed Jun 21, 2023
1 parent 82207ef commit d92980a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 56 deletions.
8 changes: 3 additions & 5 deletions packages/terra-form-select/src/single/Frame.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { injectIntl } from 'react-intl';
import uniqueid from 'lodash.uniqueid';
import * as KeyCode from 'keycode-js';
import Dropdown from '../shared/_Dropdown';
import { Menu } from './Menu';
import Menu from './Menu';
import FrameUtil from '../shared/_FrameUtil';
import SharedUtil from '../shared/_SharedUtil';
import styles from '../shared/_Frame.module.scss';
Expand Down Expand Up @@ -503,8 +503,6 @@ class Frame extends React.Component {
refCallback: this.setSelectMenuRef,
};

const SelectMenu = injectIntl(Menu);

return (
<div
{...customProps}
Expand Down Expand Up @@ -550,9 +548,9 @@ class Frame extends React.Component {
refCallback={(ref) => { this.dropdown = ref; }}
style={FrameUtil.dropdownStyle(dropdownAttrs, this.state)} // eslint-disable-line react/forbid-component-props
>
<SelectMenu {...menuProps}>
<Menu {...menuProps}>
{children}
</SelectMenu>
</Menu>
</Dropdown>
)}
</div>
Expand Down
2 changes: 1 addition & 1 deletion packages/terra-form-select/src/single/Menu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const defaultProps = {
refCallback: undefined,
};

export class Menu extends React.Component {
class Menu extends React.Component {
static getActiveOptionFromProps(props, children, state) {
const { active } = state;
const { value } = props;
Expand Down
51 changes: 1 addition & 50 deletions packages/terra-form-select/tests/jest/Menu.test.jsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
import React from 'react';
import ThemeContextProvider from 'terra-theme-context/lib/ThemeContextProvider';
import { injectIntl } from 'react-intl';

/* eslint-disable-next-line import/no-extraneous-dependencies */
import { shallowWithIntl, mountWithIntl } from 'terra-enzyme-intl';
import Option from '../../src/shared/_Option';
import SharedUtil from '../../src/shared/_SharedUtil';
import ComboboxMenu from '../../src/combobox/Menu';
import { Menu } from '../../src/single/Menu';
import SingleSelectMenu from '../../src/single/Menu';

jest.mock('../../src/shared/_SharedUtil');

describe('Menu', () => {
it('should render a default Menu', () => {
const liveRegion = { current: document.createElement('div') };
const SingleSelectMenu = injectIntl(Menu);

const menu = <SingleSelectMenu onSelect={() => {}} visuallyHiddenComponent={liveRegion} value="value" />;
const wrapper = shallowWithIntl(menu);
Expand All @@ -24,7 +21,6 @@ describe('Menu', () => {
it('should render a Menu with no results and update the live region appropriately', () => {
const liveRegion = { current: document.createElement('div') };
const mockIntl = { formatMessage: id => (`No Results for ${id.id}`) };
const SingleSelectMenu = injectIntl(Menu);

const menu = (
<SingleSelectMenu onSelect={() => {}} visuallyHiddenComponent={liveRegion} intl={mockIntl} value="value" searchValue="asdf">
Expand All @@ -45,7 +41,6 @@ describe('Menu', () => {

it('should not error when visuallyHiddenComponent is not provided', () => {
const mockIntl = { formatMessage: id => (`No Results for ${id.id}`) };
const SingleSelectMenu = injectIntl(Menu);

const menu = (
<SingleSelectMenu onSelect={() => {}} intl={mockIntl} value="value" searchValue="asdf">
Expand All @@ -66,7 +61,6 @@ describe('Menu', () => {
it('should not error when visuallyHiddenComponent has null for current', () => {
const liveRegion = { current: null };
const mockIntl = { formatMessage: id => (`No Results for ${id.id}`) };
const SingleSelectMenu = injectIntl(Menu);

const menu = (
<SingleSelectMenu onSelect={() => {}} intl={mockIntl} visuallyHiddenComponent={liveRegion} value="value" searchValue="asdf">
Expand Down Expand Up @@ -106,7 +100,6 @@ describe('Menu', () => {

it('correctly applies the theme context className', () => {
const liveRegion = { current: document.createElement('div') };
const SingleSelectMenu = injectIntl(Menu);

const wrapper = mountWithIntl(
<ThemeContextProvider theme={{ className: 'orion-fusion-theme' }}>
Expand All @@ -117,46 +110,4 @@ describe('Menu', () => {
);
expect(wrapper).toMatchSnapshot();
});

it('should call focus on select component when select is closed via key event while not using safari browser', () => {
jest.spyOn(SharedUtil, 'isSafari').mockReturnValue(false);
const liveRegion = { current: document.createElement('div') };

const mockSelect = document.createElement('div');
mockSelect.focus = jest.spyOn(mockSelect, 'focus');

const menu = (
<Menu onSelect={() => {}} visuallyHiddenComponent={liveRegion} intl={{}} value="value" searchValue="" select={mockSelect}>
<Option value="value" display="display" />
</Menu>
);

const wrapper = mountWithIntl(menu);
wrapper.setState({ closedViaKeyEvent: true });
wrapper.unmount();
expect(mockSelect.focus).toHaveBeenCalled();
});

it('should call focus on select component when select is closed via key event while using safari browser', () => {
jest.spyOn(SharedUtil, 'isSafari').mockReturnValue(true);
const liveRegion = { current: document.createElement('div') };

const mockSelect = document.createElement('div');
mockSelect.focus = jest.spyOn(mockSelect, 'focus');

const menu = (
<Menu onSelect={() => {}} visuallyHiddenComponent={liveRegion} intl={{}} value="value" searchValue="" select={mockSelect}>
<Option value="value" display="display" />
</Menu>
);

const wrapper = mountWithIntl(menu);
wrapper.setState({ closedViaKeyEvent: true });

jest.useFakeTimers();
wrapper.unmount();
jest.advanceTimersByTime(400);

expect(mockSelect.focus).toHaveBeenCalled();
});
});

0 comments on commit d92980a

Please sign in to comment.