Skip to content

Commit

Permalink
Fixed lint, added test cases, added autoheight
Browse files Browse the repository at this point in the history
  • Loading branch information
saurabhnemade committed Dec 1, 2017
1 parent ac49fe5 commit f6266a9
Show file tree
Hide file tree
Showing 4 changed files with 198 additions and 26 deletions.
7 changes: 6 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-twitter-embed",
"version": "1.0.8",
"version": "1.0.9",
"description": "React Twitter Embed Components",
"main": "dist/index.js",
"author": "Saurabh Nemade",
Expand Down Expand Up @@ -57,6 +57,7 @@
},
"dependencies": {
"babel-runtime": "^6.11.6",
"chai-dom": "^1.6.0",
"react-proptype-conditional-require": "^1.0.4",
"scriptjs": "^2.5.8"
},
Expand Down
5 changes: 3 additions & 2 deletions src/components/TwitterTimelineEmbed.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ export default class TwitterTimelineEmbed extends Component {
* To show list, unique list id
* Also used with collections, in that case its valid collection id
*/
id: isRequiredIf(PropTypes.oneOf([PropTypes.number, PropTypes.string]), props => (props.sourceType === 'list' && !props.hasOwnProperty('ownerScreenName') && !props.hasOwnProperty('slug')) || props.sourceType === 'collection'),
id: isRequiredIf(PropTypes.oneOfType([PropTypes.number, PropTypes.string]), props => (props.sourceType === 'list' && !props.hasOwnProperty('ownerScreenName') && !props.hasOwnProperty('slug')) || props.sourceType === 'collection'),
/**
* To show twitter content with url. Supported content includes profiles, likes, lists, and collections.
* To show twitter content with url.
* Supported content includes profiles, likes, lists, and collections.
*/
url: isRequiredIf(PropTypes.string, props => props.sourceType === 'url'),
/**
Expand Down
209 changes: 187 additions & 22 deletions src/tests/index.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,193 @@
import React from 'react';
import { shallow, mount } from 'enzyme';
import Button from '../index';
import { mount } from 'enzyme';
import { expect } from 'chai';
import sinon from 'sinon';
import { TwitterFollowButton, TwitterHashtagButton, TwitterMentionButton, TwitterTweetEmbed, TwitterTimelineEmbed } from './../index';

const { describe, it } = global;

describe('Button', () => {
it('should show the given text', () => {
const text = 'The Text';
const wrapper = shallow(<Button>{text}</Button>);
expect(wrapper.text()).to.be.equal(text);
});

it('should handle the click event', () => {
const clickMe = sinon.stub();
// Here we do a JSDOM render. So, that's why we need to
// wrap this with a div.
const wrapper = mount(
<div>
<Button onClick={ clickMe }>ClickMe</Button>
</div>
);

wrapper.find('button').simulate('click');
expect(clickMe.callCount).to.be.equal(1);
describe('Twitter follow button', () => {
it('Should create follow button without options', () => {
expect(function () {
mount(<TwitterFollowButton screenName="saurabhnemade" />);
}).to.not.throw();
});

it('Should create follow button with options', () => {
expect(function () {
mount(<TwitterFollowButton screenName="saurabhnemade" options={{ size: 'large' }} />);
}).to.not.throw();
});
});

describe('Twitter hashtag button', () => {
it('Should create hashtag button without options', () => {
expect(function () {
mount(<TwitterHashtagButton tag="saurabhnemade" />);
}).to.not.throw();
});

it('Should create hashtag button with options', () => {
expect(function () {
mount(<TwitterHashtagButton tag="saurabhnemade" options={{ size: 'large' }} />);
}).to.not.throw();
});
});

describe('Twitter Mention button', () => {
it('Should create Mention button without options', () => {
expect(function () {
mount(<TwitterMentionButton screenName="saurabhnemade" />);
}).to.not.throw();
});

it('Should create Mention button with options', () => {
expect(function () {
mount(<TwitterMentionButton screenName="saurabhnemade" options={{ size: 'large' }} />);
}).to.not.throw();
});
});

describe('Twitter tweet view', () => {
it('Should create tweet view', () => {
expect(function () {
mount(<TwitterTweetEmbed tweetId="933354946111705097" />);
}).to.not.throw();
});
});

describe('Twitter timeline view', () => {
it('Should create timeline with screen name without options', () => {
expect(function () {
mount(<TwitterTimelineEmbed
sourceType="profile"
screenName="saurabhnemade"
/>);
}).to.not.throw();
});

it('Should create timeline with screen name with options', () => {
expect(function () {
mount(<TwitterTimelineEmbed
sourceType="profile"
screenName="saurabhnemade"
options={{ height: 400 }}
/>);
}).to.not.throw();
});

it('Should create timeline with userid without options', () => {
expect(function () {
mount(<TwitterTimelineEmbed
sourceType="profile"
userId={1934309676}
/>);
}).to.not.throw();
});

it('Should create timeline with userid without options', () => {
expect(function () {
mount(<TwitterTimelineEmbed
sourceType="profile"
userId={1934309676}
options={{ height: 400 }}
/>);
}).to.not.throw();
});

it('Should create timeline likes with screenname without options', () => {
expect(function () {
mount(<TwitterTimelineEmbed
sourceType="likes"
screenName="saurabhnemade"
/>);
}).to.not.throw();
});

it('Should create timeline likes with screenname with options', () => {
expect(function () {
mount(<TwitterTimelineEmbed
sourceType="likes"
screenName="saurabhnemade"
options={{ height: 400 }}
/>);
}).to.not.throw();
});

it('Should create timeline likes with userid without options', () => {
expect(function () {
mount(<TwitterTimelineEmbed
sourceType="likes"
userId={1934309676}
/>);
}).to.not.throw();
});

it('Should create timeline likes with userid with options', () => {
expect(function () {
mount(<TwitterTimelineEmbed
sourceType="likes"
userId={1934309676}
options={{ height: 400 }}
/>);
}).to.not.throw();
});

it('Should create timeline list with ownerScreenName and slug without options', () => {
expect(function () {
mount(<TwitterTimelineEmbed
sourceType="list"
ownerScreenName="palafo"
slug="breakingnews"
/>);
}).to.not.throw();
});

it('Should create timeline list with ownerScreenName and slug with options', () => {
expect(function () {
mount(<TwitterTimelineEmbed
sourceType="list"
ownerScreenName="palafo"
slug="breakingnews"
options={{ height: 400 }}
/>);
}).to.not.throw();
});

it('Should create timeline list with list id without options', () => {
expect(function () {
mount(<TwitterTimelineEmbed
sourceType="list"
id={8044403}
/>);
}).to.not.throw();
});

it('Should create timeline list with list id with options', () => {
expect(function () {
mount(<TwitterTimelineEmbed
sourceType="list"
id={8044403}
options={{ height: 400 }}
/>);
}).to.not.throw();
});

it('Should create timeline list with list id without options', () => {
expect(function () {
mount(<TwitterTimelineEmbed
sourceType="collection"
id={'588824628950269952'}
/>);
}).to.not.throw();
});

it('Should create timeline list with list id with options', () => {
expect(function () {
mount(<TwitterTimelineEmbed
sourceType="collection"
id={'588824628950269952'}
options={{ height: 400 }}
/>);
}).to.not.throw();
});
});

0 comments on commit f6266a9

Please sign in to comment.