Skip to content

Commit

Permalink
[Menu] Fix menu tests
Browse files Browse the repository at this point in the history
[skip ci]
  • Loading branch information
eps1lon committed Feb 15, 2019
1 parent 0bed6e9 commit 87273f5
Showing 1 changed file with 26 additions and 19 deletions.
45 changes: 26 additions & 19 deletions packages/material-ui/src/Menu/Menu.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import React from 'react';
import { spy, stub } from 'sinon';
import { assert } from 'chai';
import ReactDOM from 'react-dom';
import { createShallow, createMount, getClasses, unwrap } from '@material-ui/core/test-utils';
import { createShallow, createMount, getClasses } from '@material-ui/core/test-utils';
import Popover from '../Popover';
import Menu from './Menu';
import MenuList from '../MenuList';

describe('<Menu />', () => {
let shallow;
Expand All @@ -25,8 +26,8 @@ describe('<Menu />', () => {
});

it('should render a Popover', () => {
const wrapper = shallow(<Menu {...defaultProps} />);
assert.strictEqual(wrapper.type(), Popover);
const wrapper = mount(<Menu {...defaultProps} />);
assert.strictEqual(wrapper.find(Popover).exists(), true);
});

it('should fire Popover transition event callbacks', () => {
Expand All @@ -47,20 +48,23 @@ describe('<Menu />', () => {
});

it('should pass `classes.paper` to the Popover', () => {
const wrapper = shallow(<Menu {...defaultProps} />);
assert.strictEqual(wrapper.props().PaperProps.classes.root, classes.paper);
const wrapper = mount(<Menu {...defaultProps} />);
assert.strictEqual(wrapper.find(Popover).props().PaperProps.classes.root, classes.paper);
});

describe('prop: PopoverClasses', () => {
it('should be able to change the Popover style', () => {
const wrapper = shallow(<Menu {...defaultProps} PopoverClasses={{ foo: 'bar' }} />);
assert.strictEqual(wrapper.props().classes.foo, 'bar');
const wrapper = mount(<Menu {...defaultProps} PopoverClasses={{ paper: 'bar' }} />);
assert.strictEqual(wrapper.find(Popover).props().classes.paper, 'bar');
});
});

it('should pass the instance function `getContentAnchorEl` to Popover', () => {
const wrapper = shallow(<Menu {...defaultProps} />);
assert.strictEqual(wrapper.props().getContentAnchorEl, wrapper.instance().getContentAnchorEl);
const wrapper = mount(<Menu {...defaultProps} />);
assert.strictEqual(
wrapper.find(Popover).props().getContentAnchorEl,
wrapper.find('Menu').instance().getContentAnchorEl,
);
});

it('should pass onClose prop to Popover', () => {
Expand All @@ -84,23 +88,27 @@ describe('<Menu />', () => {

describe('list node', () => {
let wrapper;
let list;

before(() => {
wrapper = shallow(<Menu {...defaultProps} className="test-class" data-test="hi" />);
list = wrapper.childAt(0);
wrapper = mount(<Menu {...defaultProps} className="test-class" data-test="hi" open />);
});

it('should render a MenuList inside the Popover', () => {
assert.strictEqual(list.name(), 'MenuList');
assert.strictEqual(
wrapper
.find(Popover)
.find(MenuList)
.exists(),
true,
);
});

it('should spread other props on the list', () => {
assert.strictEqual(wrapper.props()['data-test'], 'hi');
it('should spread other props on the Popover', () => {
assert.strictEqual(wrapper.find(Popover).props()['data-test'], 'hi');
});

it('should have the user classes', () => {
assert.strictEqual(wrapper.hasClass('test-class'), true);
assert.strictEqual(wrapper.find(Popover).hasClass('test-class'), true);
});
});

Expand Down Expand Up @@ -132,9 +140,8 @@ describe('<Menu />', () => {
let findDOMNodeStub;

before(() => {
const MenuNaked = unwrap(Menu);
wrapper = mount(<MenuNaked {...defaultProps} theme={{}} classes={classes} />);
instance = wrapper.instance();
wrapper = mount(<Menu {...defaultProps} theme={{}} classes={classes} />);
instance = wrapper.find('Menu').instance();

selectedItemFocusSpy = spy();
menuListFocusSpy = spy();
Expand Down

0 comments on commit 87273f5

Please sign in to comment.