From d5b767c3747b9e7f9afcbcecffb662843ca2a346 Mon Sep 17 00:00:00 2001 From: Yamagishi Kazutoshi Date: Mon, 16 Oct 2017 16:33:08 +0900 Subject: Replace JavaScript Testing Framework from Mocha to Jest (#5412) --- .../__tests__/__snapshots__/avatar-test.js.snap | 33 ++++++ .../__snapshots__/avatar_overlay-test.js.snap | 24 ++++ .../__tests__/__snapshots__/button-test.js.snap | 114 ++++++++++++++++++ .../__snapshots__/display_name-test.js.snap | 23 ++++ .../mastodon/components/__tests__/avatar-test.js | 36 ++++++ .../components/__tests__/avatar_overlay-test.js | 29 +++++ .../mastodon/components/__tests__/button-test.js | 75 ++++++++++++ .../components/__tests__/display_name-test.js | 18 +++ .../features/emoji/__tests__/emoji-test.js | 61 ++++++++++ .../features/emoji/__tests__/emoji_index-test.js | 130 +++++++++++++++++++++ .../ui/components/__tests__/column-test.js | 34 ++++++ app/javascript/mastodon/test_setup.js | 5 + 12 files changed, 582 insertions(+) create mode 100644 app/javascript/mastodon/components/__tests__/__snapshots__/avatar-test.js.snap create mode 100644 app/javascript/mastodon/components/__tests__/__snapshots__/avatar_overlay-test.js.snap create mode 100644 app/javascript/mastodon/components/__tests__/__snapshots__/button-test.js.snap create mode 100644 app/javascript/mastodon/components/__tests__/__snapshots__/display_name-test.js.snap create mode 100644 app/javascript/mastodon/components/__tests__/avatar-test.js create mode 100644 app/javascript/mastodon/components/__tests__/avatar_overlay-test.js create mode 100644 app/javascript/mastodon/components/__tests__/button-test.js create mode 100644 app/javascript/mastodon/components/__tests__/display_name-test.js create mode 100644 app/javascript/mastodon/features/emoji/__tests__/emoji-test.js create mode 100644 app/javascript/mastodon/features/emoji/__tests__/emoji_index-test.js create mode 100644 app/javascript/mastodon/features/ui/components/__tests__/column-test.js create mode 100644 app/javascript/mastodon/test_setup.js (limited to 'app/javascript') diff --git a/app/javascript/mastodon/components/__tests__/__snapshots__/avatar-test.js.snap b/app/javascript/mastodon/components/__tests__/__snapshots__/avatar-test.js.snap new file mode 100644 index 000000000..76ab3374a --- /dev/null +++ b/app/javascript/mastodon/components/__tests__/__snapshots__/avatar-test.js.snap @@ -0,0 +1,33 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[` Autoplay renders a animated avatar 1`] = ` +
+`; + +exports[` Still renders a still avatar 1`] = ` +
+`; diff --git a/app/javascript/mastodon/components/__tests__/__snapshots__/avatar_overlay-test.js.snap b/app/javascript/mastodon/components/__tests__/__snapshots__/avatar_overlay-test.js.snap new file mode 100644 index 000000000..d59fee42f --- /dev/null +++ b/app/javascript/mastodon/components/__tests__/__snapshots__/avatar_overlay-test.js.snap @@ -0,0 +1,24 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[` +
+
+
+`; diff --git a/app/javascript/mastodon/components/__tests__/__snapshots__/button-test.js.snap b/app/javascript/mastodon/components/__tests__/__snapshots__/button-test.js.snap new file mode 100644 index 000000000..c3f018d90 --- /dev/null +++ b/app/javascript/mastodon/components/__tests__/__snapshots__/button-test.js.snap @@ -0,0 +1,114 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[` +`; + +exports[` +`; + +exports[` +`; diff --git a/app/javascript/mastodon/components/__tests__/__snapshots__/display_name-test.js.snap b/app/javascript/mastodon/components/__tests__/__snapshots__/display_name-test.js.snap new file mode 100644 index 000000000..533359ffe --- /dev/null +++ b/app/javascript/mastodon/components/__tests__/__snapshots__/display_name-test.js.snap @@ -0,0 +1,23 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[` renders display name + account name 1`] = ` + + Foo

", + } + } + /> + + + @ + bar@baz + +
+`; diff --git a/app/javascript/mastodon/components/__tests__/avatar-test.js b/app/javascript/mastodon/components/__tests__/avatar-test.js new file mode 100644 index 000000000..dd3f7b7d2 --- /dev/null +++ b/app/javascript/mastodon/components/__tests__/avatar-test.js @@ -0,0 +1,36 @@ +import React from 'react'; +import renderer from 'react-test-renderer'; +import { fromJS } from 'immutable'; +import Avatar from '../avatar'; + +describe('', () => { + const account = fromJS({ + username: 'alice', + acct: 'alice', + display_name: 'Alice', + avatar: '/animated/alice.gif', + avatar_static: '/static/alice.jpg', + }); + + const size = 100; + + describe('Autoplay', () => { + it('renders a animated avatar', () => { + const component = renderer.create(); + const tree = component.toJSON(); + + expect(tree).toMatchSnapshot(); + }); + }); + + describe('Still', () => { + it('renders a still avatar', () => { + const component = renderer.create(); + const tree = component.toJSON(); + + expect(tree).toMatchSnapshot(); + }); + }); + + // TODO add autoplay test if possible +}); diff --git a/app/javascript/mastodon/components/__tests__/avatar_overlay-test.js b/app/javascript/mastodon/components/__tests__/avatar_overlay-test.js new file mode 100644 index 000000000..44addea83 --- /dev/null +++ b/app/javascript/mastodon/components/__tests__/avatar_overlay-test.js @@ -0,0 +1,29 @@ +import React from 'react'; +import renderer from 'react-test-renderer'; +import { fromJS } from 'immutable'; +import AvatarOverlay from '../avatar_overlay'; + +describe(' { + const account = fromJS({ + username: 'alice', + acct: 'alice', + display_name: 'Alice', + avatar: '/animated/alice.gif', + avatar_static: '/static/alice.jpg', + }); + + const friend = fromJS({ + username: 'eve', + acct: 'eve@blackhat.lair', + display_name: 'Evelyn', + avatar: '/animated/eve.gif', + avatar_static: '/static/eve.jpg', + }); + + it('renders a overlay avatar', () => { + const component = renderer.create(); + const tree = component.toJSON(); + + expect(tree).toMatchSnapshot(); + }); +}); diff --git a/app/javascript/mastodon/components/__tests__/button-test.js b/app/javascript/mastodon/components/__tests__/button-test.js new file mode 100644 index 000000000..160cd3cbc --- /dev/null +++ b/app/javascript/mastodon/components/__tests__/button-test.js @@ -0,0 +1,75 @@ +import { shallow } from 'enzyme'; +import React from 'react'; +import renderer from 'react-test-renderer'; +import Button from '../button'; + +describe('); + const tree = component.toJSON(); + + expect(tree).toMatchSnapshot(); + }); + + it('renders the props.text instead of children', () => { + const text = 'foo'; + const children =

children

; + const component = renderer.create(); + const tree = component.toJSON(); + + expect(tree).toMatchSnapshot(); + }); + + it('renders class="button--block" if props.block given', () => { + const component = renderer.create(