Skip to content

Commit

Permalink
test: add tests for utils/urlMatchers.ts (#143)
Browse files Browse the repository at this point in the history
* add tests for urlMatchers

* Update test/utils/urlMatcher.test.ts

I agree

Co-authored-by: Brian Douglas <bdougie@users.noreply.github.com>

* change abcd to google.com

---------

Co-authored-by: Brian Douglas <bdougie@users.noreply.github.com>
  • Loading branch information
ozgursar and bdougie committed May 27, 2023
1 parent c9b4207 commit 26702e6
Showing 1 changed file with 50 additions and 1 deletion.
51 changes: 50 additions & 1 deletion test/utils/urlMatcher.test.ts
Expand Up @@ -20,7 +20,7 @@ test('getGithubUsername', () => {
expect(getGithubUsername('https://www.github.com/username/repo/pulls')).toBe('username')
expect(getGithubUsername('www.github.com/123')).toBe('123')
expect(getGithubUsername('github.com/123/')).toBe('123')
expect(getGithubUsername('abcd')).toBe(undefined)
expect(getGithubUsername('https://google.com/')).toBe(undefined)
})

test('getLinkedInUsername', () => {
Expand All @@ -41,6 +41,55 @@ test('getTwitterUsername', () => {
expect(getTwitterUsername('twitter.com/123/')).toBe('123')
})

test('isGithubPullRequestPage', () => {
expect(isGithubPullRequestPage('https://www.github.com/')).toBe(false)
expect(isGithubPullRequestPage('https://www.github.com/pull')).toBe(false)
expect(isGithubPullRequestPage('https://www.github.com/pull/')).toBe(false)
expect(isGithubPullRequestPage('https://www.github.com/username/repo/pull/123')).toBe(true)
expect(isGithubPullRequestPage('https://www.github.com/username/repo/pull/123/')).toBe(true)
expect(isGithubPullRequestPage('www.github.com/username/repo/pull/123')).toBe(true)
expect(isGithubPullRequestPage('github.com/username/repo/pull/123/')).toBe(true)
expect(isGithubPullRequestPage('https://google.com/')).toBe(false)
})

test('isGithubProfilePage', () => {
expect(isGithubProfilePage('https://www.github.com/')).toBe(false)
expect(isGithubProfilePage('https://www.github.com/username')).toBe(true)
expect(isGithubProfilePage('https://www.github.com/username/')).toBe(false)
expect(isGithubProfilePage('https://www.github.com/username?tab=repositories')).toBe(true)
expect(isGithubProfilePage('www.github.com/username')).toBe(true)
expect(isGithubProfilePage('github.com/username')).toBe(true)
expect(isGithubProfilePage('github.com/username/')).toBe(false)
expect(isGithubProfilePage('https://google.com/')).toBe(false)
})

test('isGithubRepoPage', () => {
expect(isGithubRepoPage('https://www.github.com/')).toBe(false)
expect(isGithubRepoPage('https://www.github.com/username/')).toBe(false)
expect(isGithubRepoPage('https://www.github.com/username/repo')).toBe(true)
expect(isGithubRepoPage('https://www.github.com/username/repo/')).toBe(false)
expect(isGithubRepoPage('https://www.github.com/username/repo/https://google.com/')).toBe(false)
expect(isGithubRepoPage('www.github.com/username/repo')).toBe(true)
expect(isGithubRepoPage('github.com/username/repo')).toBe(true)
expect(isGithubRepoPage('https://google.com/')).toBe(false)
})

test('isPullRequestCreatePage', () => {
expect(isPullRequestCreatePage('https://www.github.com/')).toBe(false)
expect(isPullRequestCreatePage('https://github.com/username/repo/compare/')).toBe(false)
expect(isPullRequestCreatePage('https://github.com/username/repo/compare/https://google.com/')).toBe(true)
expect(isPullRequestCreatePage('https://github.com/username/repo/compare/https://google.com//')).toBe(true)
expect(isPullRequestCreatePage('www.github.com/username/repo/compare/https://google.com//')).toBe(true)
expect(isPullRequestCreatePage('github.com/username/repo/compare/https://google.com//')).toBe(true)
expect(isPullRequestCreatePage('https://google.com/')).toBe(false)
})

test('isPullRequestFilesChangedPage', () => {
expect(isPullRequestFilesChangedPage('https://www.github.com/')).toBe(false)
expect(isPullRequestFilesChangedPage('https://github.com/username/repo/pull/123/files')).toBe(true)
expect(isPullRequestFilesChangedPage('https://github.com/username/repo/pull/123/files/')).toBe(true)
expect(isPullRequestFilesChangedPage('www.github.com/username/repo/pull/123/files')).toBe(true)
expect(isPullRequestFilesChangedPage('github.com/username/repo/pull/123/files/')).toBe(true)
expect(isPullRequestFilesChangedPage('github.com/username/repo/pull/123/fil')).toBe(false)
expect(isPullRequestFilesChangedPage('https://google.com/')).toBe(false)
})

0 comments on commit 26702e6

Please sign in to comment.