Improve tests for JavaScript (#3496)
- Upgrade dependencies
    - chai (3.5.0 -> 4.0.1)
    - chai-enzyme (0.6.1 -> 0.7.1)
    - sinon (2.2.0 -> 2.3.2)
- Change extensions from .jsx to .js
- Don't assign `React` to `global`
- Check code format using ESLint
			
			
This commit is contained in:
		
				
					committed by
					
						 Eugen Rochko
						Eugen Rochko
					
				
			
			
				
	
			
			
			
						parent
						
							509b0cfafc
						
					
				
				
					commit
					39ea5c0e2e
				
			| @@ -1,7 +1,7 @@ | ||||
| import { expect } from 'chai'; | ||||
| import { render } from 'enzyme'; | ||||
| 
 | ||||
| import Avatar from '../../../app/javascript/mastodon/components/avatar' | ||||
| import React from 'react'; | ||||
| import Avatar from '../../../app/javascript/mastodon/components/avatar'; | ||||
| 
 | ||||
| describe('<Avatar />', () => { | ||||
|   const src = '/path/to/image.jpg'; | ||||
| @@ -1,7 +1,7 @@ | ||||
| import { expect } from 'chai'; | ||||
| import { shallow } from 'enzyme'; | ||||
| import sinon from 'sinon'; | ||||
| 
 | ||||
| import React from 'react'; | ||||
| import Button from '../../../app/javascript/mastodon/components/button'; | ||||
| 
 | ||||
| describe('<Button />', () => { | ||||
| @@ -1,15 +1,15 @@ | ||||
| import { expect } from 'chai'; | ||||
| import { render } from 'enzyme'; | ||||
| import Immutable  from 'immutable'; | ||||
| 
 | ||||
| import DisplayName from '../../../app/javascript/mastodon/components/display_name' | ||||
| import React from 'react'; | ||||
| import DisplayName from '../../../app/javascript/mastodon/components/display_name'; | ||||
| 
 | ||||
| describe('<DisplayName />', () => { | ||||
|   it('renders display name + account name', () => { | ||||
|     const account = Immutable.fromJS({ | ||||
|       username: 'bar', | ||||
|       acct: 'bar@baz', | ||||
|       display_name: 'Foo' | ||||
|       display_name: 'Foo', | ||||
|     }); | ||||
|     const wrapper = render(<DisplayName account={account} />); | ||||
|     expect(wrapper).to.have.text('Foo @bar@baz'); | ||||
| @@ -19,7 +19,7 @@ describe('<DisplayName />', () => { | ||||
|     const account = Immutable.fromJS({ | ||||
|       username: 'bar', | ||||
|       acct: 'bar@baz', | ||||
|       display_name: '' | ||||
|       display_name: '', | ||||
|     }); | ||||
|     const wrapper = render(<DisplayName account={account} />); | ||||
|     expect(wrapper).to.have.text('bar @bar@baz'); | ||||
| @@ -1,7 +1,7 @@ | ||||
| import { expect } from 'chai'; | ||||
| import { shallow, mount } from 'enzyme'; | ||||
| import sinon from 'sinon'; | ||||
| 
 | ||||
| import React from 'react'; | ||||
| import DropdownMenu from '../../../app/javascript/mastodon/components/dropdown_menu'; | ||||
| import Dropdown, { DropdownTrigger, DropdownContent } from 'react-simple-dropdown'; | ||||
| 
 | ||||
| @@ -12,7 +12,7 @@ describe('<DropdownMenu />', () => { | ||||
| 
 | ||||
|   const items = [ | ||||
|     { text: 'first item',  action: action, href: '/some/url' }, | ||||
|     { text: 'second item', action: 'noop' } | ||||
|     { text: 'second item', action: 'noop' }, | ||||
|   ]; | ||||
|   const wrapper = shallow(<DropdownMenu icon={icon} items={items} size={size} />); | ||||
| 
 | ||||
| @@ -35,23 +35,23 @@ describe('<DropdownMenu />', () => { | ||||
|   }); | ||||
| 
 | ||||
|   it('uses props.icon as icon class name', () => { | ||||
|     expect(wrapper.find(DropdownTrigger).find('i')).to.have.className(`fa-${icon}`) | ||||
|     expect(wrapper.find(DropdownTrigger).find('i')).to.have.className(`fa-${icon}`); | ||||
|   }); | ||||
| 
 | ||||
|   it('is not expanded by default', () => { | ||||
|     expect(wrapper.state('expanded')).to.be.equal(false); | ||||
|   }) | ||||
|   }); | ||||
| 
 | ||||
|   it('does not render the list elements if not expanded', () => { | ||||
|     const lis = wrapper.find(DropdownContent).find('li'); | ||||
|     expect(lis.length).to.be.equal(0); | ||||
|   }) | ||||
|   }); | ||||
| 
 | ||||
|   it('sets expanded to true when clicking the trigger', () => { | ||||
|     const wrapper = mount(<DropdownMenu icon={icon} items={items} size={size} />); | ||||
|     wrapper.find(DropdownTrigger).first().simulate('click'); | ||||
|     expect(wrapper.state('expanded')).to.be.equal(true); | ||||
|   }) | ||||
|   }); | ||||
| 
 | ||||
|   // Error: ReactWrapper::state() can only be called on the root
 | ||||
|   /*it('sets expanded to false when clicking outside', () => { | ||||
| @@ -1,7 +1,7 @@ | ||||
| import { expect } from 'chai'; | ||||
| import { mount } from 'enzyme'; | ||||
| import sinon from 'sinon'; | ||||
| 
 | ||||
| import React from 'react'; | ||||
| import Column from '../../../../../../app/javascript/mastodon/features/ui/components/column'; | ||||
| import ColumnHeader from '../../../../../../app/javascript/mastodon/features/ui/components/column_header'; | ||||
| 
 | ||||
| @@ -1,7 +1,7 @@ | ||||
| import { expect } from 'chai'; | ||||
| import { shallow } from 'enzyme'; | ||||
| 
 | ||||
| import LoadingIndicator from '../../../app/javascript/mastodon/components/loading_indicator' | ||||
| import React from 'react'; | ||||
| import LoadingIndicator from '../../../app/javascript/mastodon/components/loading_indicator'; | ||||
| 
 | ||||
| describe('<LoadingIndicator />', () => { | ||||
| 
 | ||||
| @@ -15,8 +15,5 @@ Object.keys(document.defaultView).forEach((property) => { | ||||
| }); | ||||
|  | ||||
| global.navigator = { | ||||
|   userAgent: 'node.js' | ||||
|   userAgent: 'node.js', | ||||
| }; | ||||
|  | ||||
| var React    = window.React    = global.React    = require('react'); | ||||
| var ReactDOM = window.ReactDOM = global.ReactDOM = require('react-dom'); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user