about summary refs log tree commit diff
path: root/spec/javascript
diff options
context:
space:
mode:
authorYamagishi Kazutoshi <ykzts@desire.sh>2017-06-02 00:27:15 +0900
committerEugen Rochko <eugen@zeonfederated.com>2017-06-01 17:27:15 +0200
commit39ea5c0e2e9bdf2c6e3bd0797e6fb422e6117aa2 (patch)
tree5af615d8559d8f142d6a979ba944d4f6b0cf49b6 /spec/javascript
parent509b0cfafc0857538d63f4b93b26462f035d458b (diff)
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
Diffstat (limited to 'spec/javascript')
-rw-r--r--spec/javascript/components/avatar.test.js (renamed from spec/javascript/components/avatar.test.jsx)4
-rw-r--r--spec/javascript/components/button.test.js (renamed from spec/javascript/components/button.test.jsx)2
-rw-r--r--spec/javascript/components/display_name.test.js (renamed from spec/javascript/components/display_name.test.jsx)8
-rw-r--r--spec/javascript/components/dropdown_menu.test.js (renamed from spec/javascript/components/dropdown_menu.test.jsx)12
-rw-r--r--spec/javascript/components/features/ui/components/column.test.js (renamed from spec/javascript/components/features/ui/components/column.test.jsx)2
-rw-r--r--spec/javascript/components/loading_indicator.test.js (renamed from spec/javascript/components/loading_indicator.test.jsx)4
-rw-r--r--spec/javascript/setup.js5
7 files changed, 17 insertions, 20 deletions
diff --git a/spec/javascript/components/avatar.test.jsx b/spec/javascript/components/avatar.test.js
index f70173880..03b71dc9d 100644
--- a/spec/javascript/components/avatar.test.jsx
+++ b/spec/javascript/components/avatar.test.js
@@ -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';
diff --git a/spec/javascript/components/button.test.jsx b/spec/javascript/components/button.test.js
index e08671c01..9cf8b1eed 100644
--- a/spec/javascript/components/button.test.jsx
+++ b/spec/javascript/components/button.test.js
@@ -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 />', () => {
diff --git a/spec/javascript/components/display_name.test.jsx b/spec/javascript/components/display_name.test.js
index 7072e653e..d6dc7edc0 100644
--- a/spec/javascript/components/display_name.test.jsx
+++ b/spec/javascript/components/display_name.test.js
@@ -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');
diff --git a/spec/javascript/components/dropdown_menu.test.jsx b/spec/javascript/components/dropdown_menu.test.js
index c5bbf5ad6..54cdcabf0 100644
--- a/spec/javascript/components/dropdown_menu.test.jsx
+++ b/spec/javascript/components/dropdown_menu.test.js
@@ -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', () => {
diff --git a/spec/javascript/components/features/ui/components/column.test.jsx b/spec/javascript/components/features/ui/components/column.test.js
index 6359905e6..df0f43e60 100644
--- a/spec/javascript/components/features/ui/components/column.test.jsx
+++ b/spec/javascript/components/features/ui/components/column.test.js
@@ -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';
 
diff --git a/spec/javascript/components/loading_indicator.test.jsx b/spec/javascript/components/loading_indicator.test.js
index a372640be..0859dd192 100644
--- a/spec/javascript/components/loading_indicator.test.jsx
+++ b/spec/javascript/components/loading_indicator.test.js
@@ -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 />', () => {
 
diff --git a/spec/javascript/setup.js b/spec/javascript/setup.js
index 24f21db72..7d4b2866e 100644
--- a/spec/javascript/setup.js
+++ b/spec/javascript/setup.js
@@ -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');