.github
app
controllers
helpers
javascript
fonts
images
mastodon
actions
components
__tests__
__snapshots__
avatar-test.js
avatar_overlay-test.js
button-test.js
display_name-test.js
account.js
attachment_list.js
autosuggest_emoji.js
autosuggest_textarea.js
avatar.js
avatar_overlay.js
button.js
collapsable.js
column.js
column_back_button.js
column_back_button_slim.js
column_header.js
display_name.js
dropdown_menu.js
extended_video_player.js
icon_button.js
intersection_observer_article.js
load_more.js
loading_indicator.js
media_gallery.js
missing_indicator.js
permalink.js
relative_timestamp.js
scrollable_list.js
setting_text.js
status.js
status_action_bar.js
status_content.js
status_list.js
containers
features
locales
middleware
reducers
selectors
service_worker
store
.gitkeep
api.js
base_polyfills.js
extra_polyfills.js
initial_state.js
is_mobile.js
link_header.js
load_polyfills.js
main.js
performance.js
ready.js
rtl.js
scroll.js
settings.js
stream.js
test_setup.js
uuid.js
packs
styles
lib
mailers
models
policies
presenters
serializers
services
validators
views
workers
bin
config
db
docs
lib
log
nanobox
public
spec
streaming
vendor
.babelrc
.buildpacks
.codeclimate.yml
.dockerignore
.editorconfig
.env.nanobox
.env.production.sample
.env.test
.env.vagrant
.eslintignore
.eslintrc.yml
.foreman
.gitattributes
.gitignore
.haml-lint.yml
.nanoignore
.nvmrc
.postcssrc.yml
.profile
.rspec
.rubocop.yml
.ruby-version
.scss-lint.yml
.slugignore
.travis.yml
.yarnclean
Aptfile
CODE_OF_CONDUCT.md
CONTRIBUTING.md
Capfile
Dockerfile
Gemfile
Gemfile.lock
LICENSE
Procfile
Procfile.dev
README.md
Rakefile
Vagrantfile
app.json
boxfile.yml
config.ru
docker-compose.yml
docker_entrypoint.sh
jest.config.js
package.json
scalingo.json
yarn.lock
76 lines
2.2 KiB
JavaScript
76 lines
2.2 KiB
JavaScript
import { shallow } from 'enzyme';
|
|
import React from 'react';
|
|
import renderer from 'react-test-renderer';
|
|
import Button from '../button';
|
|
|
|
describe('<Button />', () => {
|
|
it('renders a button element', () => {
|
|
const component = renderer.create(<Button />);
|
|
const tree = component.toJSON();
|
|
|
|
expect(tree).toMatchSnapshot();
|
|
});
|
|
|
|
it('renders the given text', () => {
|
|
const text = 'foo';
|
|
const component = renderer.create(<Button text={text} />);
|
|
const tree = component.toJSON();
|
|
|
|
expect(tree).toMatchSnapshot();
|
|
});
|
|
|
|
it('handles click events using the given handler', () => {
|
|
const handler = jest.fn();
|
|
const button = shallow(<Button onClick={handler} />);
|
|
button.find('button').simulate('click');
|
|
|
|
expect(handler.mock.calls.length).toEqual(1);
|
|
});
|
|
|
|
it('does not handle click events if props.disabled given', () => {
|
|
const handler = jest.fn();
|
|
const button = shallow(<Button onClick={handler} disabled />);
|
|
button.find('button').simulate('click');
|
|
|
|
expect(handler.mock.calls.length).toEqual(0);
|
|
});
|
|
|
|
it('renders a disabled attribute if props.disabled given', () => {
|
|
const component = renderer.create(<Button disabled />);
|
|
const tree = component.toJSON();
|
|
|
|
expect(tree).toMatchSnapshot();
|
|
});
|
|
|
|
it('renders the children', () => {
|
|
const children = <p>children</p>;
|
|
const component = renderer.create(<Button>{children}</Button>);
|
|
const tree = component.toJSON();
|
|
|
|
expect(tree).toMatchSnapshot();
|
|
});
|
|
|
|
it('renders the props.text instead of children', () => {
|
|
const text = 'foo';
|
|
const children = <p>children</p>;
|
|
const component = renderer.create(<Button text={text}>{children}</Button>);
|
|
const tree = component.toJSON();
|
|
|
|
expect(tree).toMatchSnapshot();
|
|
});
|
|
|
|
it('renders class="button--block" if props.block given', () => {
|
|
const component = renderer.create(<Button block />);
|
|
const tree = component.toJSON();
|
|
|
|
expect(tree).toMatchSnapshot();
|
|
});
|
|
|
|
it('adds class "button-secondary" if props.secondary given', () => {
|
|
const component = renderer.create(<Button secondary />);
|
|
const tree = component.toJSON();
|
|
|
|
expect(tree).toMatchSnapshot();
|
|
});
|
|
});
|