Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test cases for existing events in GitHubEventAction component #18

Merged
merged 9 commits into from
Oct 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/GitHubEventAction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function GitHubEventAction({type, payload}: GitHubEventActionProps): JSX.Element
return unknown;
}
return (
<span>{actionStr} on <ELink link={prURL}> pull request #{prNum}</ELink> in</span>
<span>{actionStr} on<ELink link={prURL}> pull request #{prNum}</ELink> in</span>
mattxwang marked this conversation as resolved.
Show resolved Hide resolved
);
}
case 'PullRequestReviewEvent': {
Expand Down
91 changes: 91 additions & 0 deletions test/components/GitHubEventAction.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import React from 'react';
import GitHubEventAction from '../../components/GitHubEventAction';
import createEventBranchData from '../fixtures/CreateEvent-Branch.json';
import deleteEventBranchData from '../fixtures/DeleteEvent-Branch.json';
import forkEventData from '../fixtures/ForkEvent.json';
import issueCommentEventData from '../fixtures/IssueCommentEvent.json';
import issuesEventClosedData from '../fixtures/IssuesEvent-Closed.json';
import issuesEventOpenedData from '../fixtures/IssuesEvent-Opened.json';
import pullRequestEventClosedData from '../fixtures/PullRequestEvent-Closed.json';
import pullRequestEventOpenedData from '../fixtures/PullRequestEvent-Opened.json';
import pullRequestReviewCommentEventData from '../fixtures/PullRequestReviewCommentEvent.json';
import pullRequestReviewEventData from '../fixtures/PullRequestReviewEvent.json';
import pushEventMultipleCommitsData from '../fixtures/PushEvent-MultipleCommits.json';
import pushEventSingleCommitData from '../fixtures/PushEvent-SingleCommit.json';

import { render } from '../testUtils';


const testCases = [
{
data: createEventBranchData,
expectedOutput: 'created branch town-hall-f21 in',
},
{
data: deleteEventBranchData,
expectedOutput: 'deleted branch jedis-typo in',
},
{
data: forkEventData,
expectedOutput: 'forked ansh-saini/website-1 from',
expectedHref: 'https://github.com/ansh-saini/website-1',
},
{
data: issueCommentEventData,
expectedOutput: 'commented on issue #45 in',
expectedHref: 'https://github.com/uclaacm/membership-portal/pull/45',
},
{
data: issuesEventOpenedData,
expectedOutput: 'opened issue #106 in',
expectedHref: 'https://github.com/uclaacm/icpc-website/issues/106',
},
{
data: issuesEventClosedData,
expectedOutput: 'closed issue #321 in',
expectedHref: 'https://github.com/uclaacm/website/issues/321',
},
{
data: pullRequestEventOpenedData,
expectedOutput: 'opened pull request #324 in',
expectedHref: 'https://github.com/uclaacm/website/pull/324',
},
{
data: pullRequestEventClosedData,
expectedOutput: 'closed pull request #324 in',
expectedHref: 'https://github.com/uclaacm/website/pull/324',
},
{
data: pullRequestReviewEventData,
expectedOutput: 'reviewed pull request #262 in',
expectedHref: 'https://github.com/uclaacm/hack.uclaacm.com/pull/262',
},
{
data: pullRequestReviewCommentEventData,
expectedOutput: 'commented on pull request #262 in',
expectedHref: 'https://github.com/uclaacm/hack.uclaacm.com/pull/262#discussion_r734235143',
},
{
data: pushEventSingleCommitData,
expectedOutput: 'pushed 1 commit to',
},
{
data: pushEventMultipleCommitsData,
expectedOutput: 'pushed 2 commits to',
},
];

describe('GitHub Event Action', () => {
testCases.forEach(({data ,expectedOutput, expectedHref}) => {
it(`renders correct string for ${data.type}`, () => {
const {container} = render(<GitHubEventAction payload={data.payload} type={data.type} />, {});

const element = container.querySelector('span');
expect(element.textContent).toBe(expectedOutput);

if (expectedHref) {
expect(element.querySelector('a').href).toBe(expectedHref);
}
ansh-saini marked this conversation as resolved.
Show resolved Hide resolved
});
});
});
33 changes: 33 additions & 0 deletions test/fixtures/CreateEvent-Branch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"id": "18563679088",
"type": "CreateEvent",
"actor": {
"id": 14893287,
"login": "mattxwang",
"display_login": "mattxwang",
"gravatar_id": "",
"url": "https://api.github.com/users/mattxwang",
"avatar_url": "https://avatars.githubusercontent.com/u/14893287?"
},
"repo": {
"id": 103854310,
"name": "uclaacm/website",
"url": "https://api.github.com/repos/uclaacm/website"
},
"payload": {
"ref": "town-hall-f21",
"ref_type": "branch",
"master_branch": "main",
"description": "The official website for ACM at UCLA, the largest tech community on campus!",
"pusher_type": "user"
},
"public": true,
"created_at": "2021-10-23T01:35:29Z",
"org": {
"id": 8324381,
"login": "uclaacm",
"gravatar_id": "",
"url": "https://api.github.com/orgs/uclaacm",
"avatar_url": "https://avatars.githubusercontent.com/u/8324381?"
}
}
31 changes: 31 additions & 0 deletions test/fixtures/DeleteEvent-Branch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"id": "18562886179",
"type": "DeleteEvent",
"actor": {
"id": 15240801,
"login": "dtjanaka",
"display_login": "dtjanaka",
"gravatar_id": "",
"url": "https://api.github.com/users/dtjanaka",
"avatar_url": "https://avatars.githubusercontent.com/u/15240801?"
},
"repo": {
"id": 103854310,
"name": "uclaacm/website",
"url": "https://api.github.com/repos/uclaacm/website"
},
"payload": {
"ref": "jedis-typo",
"ref_type": "branch",
"pusher_type": "user"
},
"public": true,
"created_at": "2021-10-22T22:59:22Z",
"org": {
"id": 8324381,
"login": "uclaacm",
"gravatar_id": "",
"url": "https://api.github.com/orgs/uclaacm",
"avatar_url": "https://avatars.githubusercontent.com/u/8324381?"
}
}
135 changes: 135 additions & 0 deletions test/fixtures/ForkEvent.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
{
"id": "18564222370",
"type": "ForkEvent",
"actor": {
"id": 32511936,
"login": "ansh-saini",
"display_login": "ansh-saini",
"gravatar_id": "",
"url": "https://api.github.com/users/ansh-saini",
"avatar_url": "https://avatars.githubusercontent.com/u/32511936?"
},
"repo": {
"id": 103854310,
"name": "uclaacm/website",
"url": "https://api.github.com/repos/uclaacm/website"
},
"payload": {
"forkee": {
"id": 420308904,
"node_id": "R_kgDOGQ1nqA",
"name": "website-1",
"full_name": "ansh-saini/website-1",
"private": false,
"owner": {
"login": "ansh-saini",
"id": 32511936,
"node_id": "MDQ6VXNlcjMyNTExOTM2",
"avatar_url": "https://avatars.githubusercontent.com/u/32511936?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/ansh-saini",
"html_url": "https://github.com/ansh-saini",
"followers_url": "https://api.github.com/users/ansh-saini/followers",
"following_url": "https://api.github.com/users/ansh-saini/following{/other_user}",
"gists_url": "https://api.github.com/users/ansh-saini/gists{/gist_id}",
"starred_url": "https://api.github.com/users/ansh-saini/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/ansh-saini/subscriptions",
"organizations_url": "https://api.github.com/users/ansh-saini/orgs",
"repos_url": "https://api.github.com/users/ansh-saini/repos",
"events_url": "https://api.github.com/users/ansh-saini/events{/privacy}",
"received_events_url": "https://api.github.com/users/ansh-saini/received_events",
"type": "User",
"site_admin": false
},
"html_url": "https://github.com/ansh-saini/website-1",
"description": "The official website for ACM at UCLA, the largest tech community on campus!",
"fork": true,
"url": "https://api.github.com/repos/ansh-saini/website-1",
"forks_url": "https://api.github.com/repos/ansh-saini/website-1/forks",
"keys_url": "https://api.github.com/repos/ansh-saini/website-1/keys{/key_id}",
"collaborators_url": "https://api.github.com/repos/ansh-saini/website-1/collaborators{/collaborator}",
"teams_url": "https://api.github.com/repos/ansh-saini/website-1/teams",
"hooks_url": "https://api.github.com/repos/ansh-saini/website-1/hooks",
"issue_events_url": "https://api.github.com/repos/ansh-saini/website-1/issues/events{/number}",
"events_url": "https://api.github.com/repos/ansh-saini/website-1/events",
"assignees_url": "https://api.github.com/repos/ansh-saini/website-1/assignees{/user}",
"branches_url": "https://api.github.com/repos/ansh-saini/website-1/branches{/branch}",
"tags_url": "https://api.github.com/repos/ansh-saini/website-1/tags",
"blobs_url": "https://api.github.com/repos/ansh-saini/website-1/git/blobs{/sha}",
"git_tags_url": "https://api.github.com/repos/ansh-saini/website-1/git/tags{/sha}",
"git_refs_url": "https://api.github.com/repos/ansh-saini/website-1/git/refs{/sha}",
"trees_url": "https://api.github.com/repos/ansh-saini/website-1/git/trees{/sha}",
"statuses_url": "https://api.github.com/repos/ansh-saini/website-1/statuses/{sha}",
"languages_url": "https://api.github.com/repos/ansh-saini/website-1/languages",
"stargazers_url": "https://api.github.com/repos/ansh-saini/website-1/stargazers",
"contributors_url": "https://api.github.com/repos/ansh-saini/website-1/contributors",
"subscribers_url": "https://api.github.com/repos/ansh-saini/website-1/subscribers",
"subscription_url": "https://api.github.com/repos/ansh-saini/website-1/subscription",
"commits_url": "https://api.github.com/repos/ansh-saini/website-1/commits{/sha}",
"git_commits_url": "https://api.github.com/repos/ansh-saini/website-1/git/commits{/sha}",
"comments_url": "https://api.github.com/repos/ansh-saini/website-1/comments{/number}",
"issue_comment_url": "https://api.github.com/repos/ansh-saini/website-1/issues/comments{/number}",
"contents_url": "https://api.github.com/repos/ansh-saini/website-1/contents/{+path}",
"compare_url": "https://api.github.com/repos/ansh-saini/website-1/compare/{base}...{head}",
"merges_url": "https://api.github.com/repos/ansh-saini/website-1/merges",
"archive_url": "https://api.github.com/repos/ansh-saini/website-1/{archive_format}{/ref}",
"downloads_url": "https://api.github.com/repos/ansh-saini/website-1/downloads",
"issues_url": "https://api.github.com/repos/ansh-saini/website-1/issues{/number}",
"pulls_url": "https://api.github.com/repos/ansh-saini/website-1/pulls{/number}",
"milestones_url": "https://api.github.com/repos/ansh-saini/website-1/milestones{/number}",
"notifications_url": "https://api.github.com/repos/ansh-saini/website-1/notifications{?since,all,participating}",
"labels_url": "https://api.github.com/repos/ansh-saini/website-1/labels{/name}",
"releases_url": "https://api.github.com/repos/ansh-saini/website-1/releases{/id}",
"deployments_url": "https://api.github.com/repos/ansh-saini/website-1/deployments",
"created_at": "2021-10-23T04:01:56Z",
"updated_at": "2021-10-23T00:15:36Z",
"pushed_at": "2021-10-23T01:36:00Z",
"git_url": "git://github.com/ansh-saini/website-1.git",
"ssh_url": "[email protected]:ansh-saini/website-1.git",
"clone_url": "https://github.com/ansh-saini/website-1.git",
"svn_url": "https://github.com/ansh-saini/website-1",
"homepage": "https://acm.cs.ucla.edu",
"size": 111762,
"stargazers_count": 0,
"watchers_count": 0,
"language": null,
"has_issues": false,
"has_projects": true,
"has_downloads": true,
"has_wiki": true,
"has_pages": false,
"forks_count": 0,
"mirror_url": null,
"archived": false,
"disabled": false,
"open_issues_count": 0,
"license": {
"key": "mpl-2.0",
"name": "Mozilla Public License 2.0",
"spdx_id": "MPL-2.0",
"url": "https://api.github.com/licenses/mpl-2.0",
"node_id": "MDc6TGljZW5zZTE0"
},
"allow_forking": true,
"is_template": false,
"topics": [

],
"visibility": "public",
"forks": 0,
"open_issues": 0,
"watchers": 0,
"default_branch": "main",
"public": true
}
},
"public": true,
"created_at": "2021-10-23T04:01:57Z",
"org": {
"id": 8324381,
"login": "uclaacm",
"gravatar_id": "",
"url": "https://api.github.com/orgs/uclaacm",
"avatar_url": "https://avatars.githubusercontent.com/u/8324381?"
}
}
Loading