diff --git a/.eslintignore b/.eslintignore index a3fa96186..11c15a017 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1 +1,2 @@ __tests__/** +testenv.js diff --git a/.travis.yml b/.travis.yml index c425b6d8f..9a432d599 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,8 +4,9 @@ cache: directories: - node_modules node_js: - - '7' + - 7 before_script: - - 'yarn' + - yarn script: + - yarn run test - yarn run eslint diff --git a/__tests__/data/issue.js b/__tests__/data/issue.js new file mode 100644 index 000000000..d8ef97fa9 --- /dev/null +++ b/__tests__/data/issue.js @@ -0,0 +1,151 @@ +export const open = { + url: 'https://api.github.com/repos/gitpoint/git-point/issues/144', + repository_url: 'https://api.github.com/repos/gitpoint/git-point', + labels_url: + 'https://api.github.com/repos/gitpoint/git-point/issues/144/labels{/name}', + comments_url: + 'https://api.github.com/repos/gitpoint/git-point/issues/144/comments', + events_url: + 'https://api.github.com/repos/gitpoint/git-point/issues/144/events', + html_url: 'https://github.com/gitpoint/git-point/pull/144', + id: 244830380, + number: 144, + title: 'Show actual version of the application', + user: { + login: 'lex111', + id: 4408379, + avatar_url: 'https://avatars2.githubusercontent.com/u/4408379?v=4', + gravatar_id: '', + url: 'https://api.github.com/users/lex111', + html_url: 'https://github.com/lex111', + followers_url: 'https://api.github.com/users/lex111/followers', + following_url: 'https://api.github.com/users/lex111/following{/other_user}', + gists_url: 'https://api.github.com/users/lex111/gists{/gist_id}', + starred_url: 'https://api.github.com/users/lex111/starred{/owner}{/repo}', + subscriptions_url: 'https://api.github.com/users/lex111/subscriptions', + organizations_url: 'https://api.github.com/users/lex111/orgs', + repos_url: 'https://api.github.com/users/lex111/repos', + events_url: 'https://api.github.com/users/lex111/events{/privacy}', + received_events_url: 'https://api.github.com/users/lex111/received_events', + type: 'User', + site_admin: false, + }, + labels: [], + state: 'open', + locked: false, + assignee: null, + assignees: [], + milestone: null, + comments: 0, + created_at: '2017-07-22T07:21:23Z', + updated_at: '2017-07-22T17:03:14Z', + closed_at: '2017-07-22T16:52:21Z', + author_association: 'MEMBER', + pull_request: { + url: 'https://api.github.com/repos/gitpoint/git-point/pulls/144', + html_url: 'https://github.com/gitpoint/git-point/pull/144', + diff_url: 'https://github.com/gitpoint/git-point/pull/144.diff', + patch_url: 'https://github.com/gitpoint/git-point/pull/144.patch', + }, + body: + "Now the version of the application is hardcoded, which is not good, it's best practice to specify the version number in the `package.json` file and from there take it to display.", + closed_by: { + login: 'housseindjirdeh', + id: 12476932, + avatar_url: 'https://avatars3.githubusercontent.com/u/12476932?v=4', + gravatar_id: '', + url: 'https://api.github.com/users/housseindjirdeh', + html_url: 'https://github.com/housseindjirdeh', + followers_url: 'https://api.github.com/users/housseindjirdeh/followers', + following_url: + 'https://api.github.com/users/housseindjirdeh/following{/other_user}', + gists_url: 'https://api.github.com/users/housseindjirdeh/gists{/gist_id}', + starred_url: + 'https://api.github.com/users/housseindjirdeh/starred{/owner}{/repo}', + subscriptions_url: + 'https://api.github.com/users/housseindjirdeh/subscriptions', + organizations_url: 'https://api.github.com/users/housseindjirdeh/orgs', + repos_url: 'https://api.github.com/users/housseindjirdeh/repos', + events_url: 'https://api.github.com/users/housseindjirdeh/events{/privacy}', + received_events_url: + 'https://api.github.com/users/housseindjirdeh/received_events', + type: 'User', + site_admin: false, + }, +}; + +export const closed = { + url: 'https://api.github.com/repos/gitpoint/git-point/issues/144', + repository_url: 'https://api.github.com/repos/gitpoint/git-point', + labels_url: + 'https://api.github.com/repos/gitpoint/git-point/issues/144/labels{/name}', + comments_url: + 'https://api.github.com/repos/gitpoint/git-point/issues/144/comments', + events_url: + 'https://api.github.com/repos/gitpoint/git-point/issues/144/events', + html_url: 'https://github.com/gitpoint/git-point/pull/144', + id: 244830380, + number: 144, + title: 'Show actual version of the application', + user: { + login: 'lex111', + id: 4408379, + avatar_url: 'https://avatars2.githubusercontent.com/u/4408379?v=4', + gravatar_id: '', + url: 'https://api.github.com/users/lex111', + html_url: 'https://github.com/lex111', + followers_url: 'https://api.github.com/users/lex111/followers', + following_url: 'https://api.github.com/users/lex111/following{/other_user}', + gists_url: 'https://api.github.com/users/lex111/gists{/gist_id}', + starred_url: 'https://api.github.com/users/lex111/starred{/owner}{/repo}', + subscriptions_url: 'https://api.github.com/users/lex111/subscriptions', + organizations_url: 'https://api.github.com/users/lex111/orgs', + repos_url: 'https://api.github.com/users/lex111/repos', + events_url: 'https://api.github.com/users/lex111/events{/privacy}', + received_events_url: 'https://api.github.com/users/lex111/received_events', + type: 'User', + site_admin: false, + }, + labels: [], + state: 'closed', + locked: false, + assignee: null, + assignees: [], + milestone: null, + comments: 0, + created_at: '2017-07-22T07:21:23Z', + updated_at: '2017-07-22T17:03:14Z', + closed_at: '2017-07-22T16:52:21Z', + author_association: 'MEMBER', + pull_request: { + url: 'https://api.github.com/repos/gitpoint/git-point/pulls/144', + html_url: 'https://github.com/gitpoint/git-point/pull/144', + diff_url: 'https://github.com/gitpoint/git-point/pull/144.diff', + patch_url: 'https://github.com/gitpoint/git-point/pull/144.patch', + }, + body: + "Now the version of the application is hardcoded, which is not good, it's best practice to specify the version number in the `package.json` file and from there take it to display.", + closed_by: { + login: 'housseindjirdeh', + id: 12476932, + avatar_url: 'https://avatars3.githubusercontent.com/u/12476932?v=4', + gravatar_id: '', + url: 'https://api.github.com/users/housseindjirdeh', + html_url: 'https://github.com/housseindjirdeh', + followers_url: 'https://api.github.com/users/housseindjirdeh/followers', + following_url: + 'https://api.github.com/users/housseindjirdeh/following{/other_user}', + gists_url: 'https://api.github.com/users/housseindjirdeh/gists{/gist_id}', + starred_url: + 'https://api.github.com/users/housseindjirdeh/starred{/owner}{/repo}', + subscriptions_url: + 'https://api.github.com/users/housseindjirdeh/subscriptions', + organizations_url: 'https://api.github.com/users/housseindjirdeh/orgs', + repos_url: 'https://api.github.com/users/housseindjirdeh/repos', + events_url: 'https://api.github.com/users/housseindjirdeh/events{/privacy}', + received_events_url: + 'https://api.github.com/users/housseindjirdeh/received_events', + type: 'User', + site_admin: false, + }, +}; diff --git a/__tests__/data/label.js b/__tests__/data/label.js new file mode 100644 index 000000000..84ae6f55e --- /dev/null +++ b/__tests__/data/label.js @@ -0,0 +1,4 @@ +export default { + name: 'test tag', + color: 'c3c3c3', +}; diff --git a/__tests__/data/organization.js b/__tests__/data/organization.js new file mode 100644 index 000000000..dfd05754e --- /dev/null +++ b/__tests__/data/organization.js @@ -0,0 +1,36 @@ +export default { + login: 'github', + id: 1, + url: 'https://api.github.com/orgs/github', + repos_url: 'https://api.github.com/orgs/github/repos', + events_url: 'https://api.github.com/orgs/github/events', + hooks_url: 'https://api.github.com/orgs/github/hooks', + issues_url: 'https://api.github.com/orgs/github/issues', + members_url: 'https://api.github.com/orgs/github/members{/member}', + public_members_url: + 'https://api.github.com/orgs/github/public_members{/member}', + avatar_url: 'https://github.com/images/error/octocat_happy.gif', + description: 'A great organization', + name: 'github', + blog: 'https://github.com/blog', + location: 'San Francisco', + email: 'octocat@github.com', + public_repos: 2, + public_gists: 1, + html_url: 'https://github.com/octocat', + created_at: '2008-01-14T04:33:35Z', + type: 'Organization', + total_private_repos: 100, + owned_private_repos: 100, + private_gists: 81, + disk_usage: 10000, + collaborators: 8, + billing_email: 'support@github.com', + plan: { + name: 'Medium', + space: 400, + private_repos: 20, + }, + default_repository_settings: 'read', + members_can_create_repositories: true, +}; diff --git a/__tests__/data/pull-request.js b/__tests__/data/pull-request.js new file mode 100644 index 000000000..aa8db95be --- /dev/null +++ b/__tests__/data/pull-request.js @@ -0,0 +1,212 @@ +export const open = { + url: 'https://api.github.com/repos/gitpoint/git-point/issues/148', + repository_url: 'https://api.github.com/repos/gitpoint/git-point', + labels_url: + 'https://api.github.com/repos/gitpoint/git-point/issues/148/labels{/name}', + comments_url: + 'https://api.github.com/repos/gitpoint/git-point/issues/148/comments', + events_url: + 'https://api.github.com/repos/gitpoint/git-point/issues/148/events', + html_url: 'https://github.com/gitpoint/git-point/pull/148', + id: 244885063, + number: 148, + title: 'test: begin implementing basic tests', + user: { + login: 'andrewda', + id: 10191084, + avatar_url: 'https://avatars1.githubusercontent.com/u/10191084?v=4', + gravatar_id: '', + url: 'https://api.github.com/users/andrewda', + html_url: 'https://github.com/andrewda', + followers_url: 'https://api.github.com/users/andrewda/followers', + following_url: + 'https://api.github.com/users/andrewda/following{/other_user}', + gists_url: 'https://api.github.com/users/andrewda/gists{/gist_id}', + starred_url: 'https://api.github.com/users/andrewda/starred{/owner}{/repo}', + subscriptions_url: 'https://api.github.com/users/andrewda/subscriptions', + organizations_url: 'https://api.github.com/users/andrewda/orgs', + repos_url: 'https://api.github.com/users/andrewda/repos', + events_url: 'https://api.github.com/users/andrewda/events{/privacy}', + received_events_url: + 'https://api.github.com/users/andrewda/received_events', + type: 'User', + site_admin: false, + }, + labels: [ + { + id: 649983803, + url: 'https://api.github.com/repos/gitpoint/git-point/labels/tests', + name: 'tests', + color: 'fef2c0', + default: false, + }, + { + id: 650761287, + url: + 'https://api.github.com/repos/gitpoint/git-point/labels/work%20in%20progress', + name: 'work in progress', + color: 'fbca04', + default: false, + }, + ], + state: 'open', + locked: false, + assignee: null, + assignees: [], + milestone: null, + comments: 7, + created_at: '2017-07-23T02:58:07Z', + updated_at: '2017-10-01T17:40:47Z', + closed_at: null, + author_association: 'MEMBER', + pull_request: { + url: 'https://api.github.com/repos/gitpoint/git-point/pulls/148', + html_url: 'https://github.com/gitpoint/git-point/pull/148', + diff_url: 'https://github.com/gitpoint/git-point/pull/148.diff', + patch_url: 'https://github.com/gitpoint/git-point/pull/148.patch', + }, + body: 'Fixes #112.', + closed_by: null, +}; + +export const closed = { + url: 'https://api.github.com/repos/gitpoint/git-point/issues/148', + repository_url: 'https://api.github.com/repos/gitpoint/git-point', + labels_url: + 'https://api.github.com/repos/gitpoint/git-point/issues/148/labels{/name}', + comments_url: + 'https://api.github.com/repos/gitpoint/git-point/issues/148/comments', + events_url: + 'https://api.github.com/repos/gitpoint/git-point/issues/148/events', + html_url: 'https://github.com/gitpoint/git-point/pull/148', + id: 244885063, + number: 148, + title: 'test: begin implementing basic tests', + user: { + login: 'andrewda', + id: 10191084, + avatar_url: 'https://avatars1.githubusercontent.com/u/10191084?v=4', + gravatar_id: '', + url: 'https://api.github.com/users/andrewda', + html_url: 'https://github.com/andrewda', + followers_url: 'https://api.github.com/users/andrewda/followers', + following_url: + 'https://api.github.com/users/andrewda/following{/other_user}', + gists_url: 'https://api.github.com/users/andrewda/gists{/gist_id}', + starred_url: 'https://api.github.com/users/andrewda/starred{/owner}{/repo}', + subscriptions_url: 'https://api.github.com/users/andrewda/subscriptions', + organizations_url: 'https://api.github.com/users/andrewda/orgs', + repos_url: 'https://api.github.com/users/andrewda/repos', + events_url: 'https://api.github.com/users/andrewda/events{/privacy}', + received_events_url: + 'https://api.github.com/users/andrewda/received_events', + type: 'User', + site_admin: false, + }, + labels: [ + { + id: 649983803, + url: 'https://api.github.com/repos/gitpoint/git-point/labels/tests', + name: 'tests', + color: 'fef2c0', + default: false, + }, + { + id: 650761287, + url: + 'https://api.github.com/repos/gitpoint/git-point/labels/work%20in%20progress', + name: 'work in progress', + color: 'fbca04', + default: false, + }, + ], + state: 'closed', + locked: false, + assignee: null, + assignees: [], + milestone: null, + comments: 7, + created_at: '2017-07-23T02:58:07Z', + updated_at: '2017-10-01T17:40:47Z', + closed_at: null, + author_association: 'MEMBER', + pull_request: { + url: 'https://api.github.com/repos/gitpoint/git-point/pulls/148', + html_url: 'https://github.com/gitpoint/git-point/pull/148', + diff_url: 'https://github.com/gitpoint/git-point/pull/148.diff', + patch_url: 'https://github.com/gitpoint/git-point/pull/148.patch', + }, + body: 'Fixes #112.', + closed_by: null, +}; + +export const merged = { + url: 'https://api.github.com/repos/gitpoint/git-point/issues/148', + repository_url: 'https://api.github.com/repos/gitpoint/git-point', + labels_url: + 'https://api.github.com/repos/gitpoint/git-point/issues/148/labels{/name}', + comments_url: + 'https://api.github.com/repos/gitpoint/git-point/issues/148/comments', + events_url: + 'https://api.github.com/repos/gitpoint/git-point/issues/148/events', + html_url: 'https://github.com/gitpoint/git-point/pull/148', + id: 244885063, + number: 148, + title: 'test: begin implementing basic tests', + user: { + login: 'andrewda', + id: 10191084, + avatar_url: 'https://avatars1.githubusercontent.com/u/10191084?v=4', + gravatar_id: '', + url: 'https://api.github.com/users/andrewda', + html_url: 'https://github.com/andrewda', + followers_url: 'https://api.github.com/users/andrewda/followers', + following_url: + 'https://api.github.com/users/andrewda/following{/other_user}', + gists_url: 'https://api.github.com/users/andrewda/gists{/gist_id}', + starred_url: 'https://api.github.com/users/andrewda/starred{/owner}{/repo}', + subscriptions_url: 'https://api.github.com/users/andrewda/subscriptions', + organizations_url: 'https://api.github.com/users/andrewda/orgs', + repos_url: 'https://api.github.com/users/andrewda/repos', + events_url: 'https://api.github.com/users/andrewda/events{/privacy}', + received_events_url: + 'https://api.github.com/users/andrewda/received_events', + type: 'User', + site_admin: false, + }, + labels: [ + { + id: 649983803, + url: 'https://api.github.com/repos/gitpoint/git-point/labels/tests', + name: 'tests', + color: 'fef2c0', + default: false, + }, + { + id: 650761287, + url: + 'https://api.github.com/repos/gitpoint/git-point/labels/work%20in%20progress', + name: 'work in progress', + color: 'fbca04', + default: false, + }, + ], + state: 'merged', + locked: false, + assignee: null, + assignees: [], + milestone: null, + comments: 7, + created_at: '2017-07-23T02:58:07Z', + updated_at: '2017-10-01T17:40:47Z', + closed_at: null, + author_association: 'MEMBER', + pull_request: { + url: 'https://api.github.com/repos/gitpoint/git-point/pulls/148', + html_url: 'https://github.com/gitpoint/git-point/pull/148', + diff_url: 'https://github.com/gitpoint/git-point/pull/148.diff', + patch_url: 'https://github.com/gitpoint/git-point/pull/148.patch', + }, + body: 'Fixes #112.', + closed_by: null, +}; diff --git a/__tests__/data/user.js b/__tests__/data/user.js new file mode 100644 index 000000000..f65d20d33 --- /dev/null +++ b/__tests__/data/user.js @@ -0,0 +1,32 @@ +export default { + login: 'octocat', + id: 1, + avatar_url: 'https://github.com/images/error/octocat_happy.gif', + gravatar_id: '', + url: 'https://api.github.com/users/octocat', + html_url: 'https://github.com/octocat', + followers_url: 'https://api.github.com/users/octocat/followers', + following_url: 'https://api.github.com/users/octocat/following{/other_user}', + gists_url: 'https://api.github.com/users/octocat/gists{/gist_id}', + starred_url: 'https://api.github.com/users/octocat/starred{/owner}{/repo}', + subscriptions_url: 'https://api.github.com/users/octocat/subscriptions', + organizations_url: 'https://api.github.com/users/octocat/orgs', + repos_url: 'https://api.github.com/users/octocat/repos', + events_url: 'https://api.github.com/users/octocat/events{/privacy}', + received_events_url: 'https://api.github.com/users/octocat/received_events', + type: 'User', + site_admin: false, + name: 'monalisa octocat', + company: '@GitHub', + blog: 'https://github.com/blog', + location: 'San Francisco', + email: 'octocat@github.com', + hireable: false, + bio: 'There once was...', + public_repos: 2, + public_gists: 1, + followers: 20, + following: 0, + created_at: '2008-01-14T04:33:35Z', + updated_at: '2008-01-14T04:33:35Z', +}; diff --git a/__tests__/index.android.js b/__tests__/index.android.js deleted file mode 100644 index 84e6b670d..000000000 --- a/__tests__/index.android.js +++ /dev/null @@ -1,10 +0,0 @@ -import 'react-native'; -import React from 'react'; -import renderer from 'react-test-renderer'; -import Index from '../index.android'; - -// Note: test renderer must be required after react-native. - -it('renders correctly', () => { - const tree = renderer.create(); -}); diff --git a/__tests__/index.ios.js b/__tests__/index.ios.js deleted file mode 100644 index 3b7b2e010..000000000 --- a/__tests__/index.ios.js +++ /dev/null @@ -1,10 +0,0 @@ -import 'react-native'; -import React from 'react'; -import renderer from 'react-test-renderer'; -import Index from '../index.ios'; - -// Note: test renderer must be required after react-native. - -it('renders correctly', () => { - const tree = renderer.create(); -}); diff --git a/__tests__/tests/components/Badge.js b/__tests__/tests/components/Badge.js new file mode 100644 index 000000000..ef79e2d80 --- /dev/null +++ b/__tests__/tests/components/Badge.js @@ -0,0 +1,17 @@ +import React from 'react'; +import { shallow } from 'enzyme'; + +import { Badge } from 'components'; + +describe('', () => { + it('correctly renders with text', () => { + const wrapper = shallow(); + + expect( + wrapper + .childAt(0) + .childAt(0) + .text() + ).toEqual('test text'); + }); +}); diff --git a/__tests__/tests/components/Button.js b/__tests__/tests/components/Button.js new file mode 100644 index 000000000..8aac8457e --- /dev/null +++ b/__tests__/tests/components/Button.js @@ -0,0 +1,48 @@ +import React from 'react'; +import sinon from 'sinon'; +import { shallow, render } from 'enzyme'; + +import { Button } from 'components'; + +describe('