From 26702e689641138a791f3c8cb935ddc99540a19e Mon Sep 17 00:00:00 2001 From: Ozgur Sar Date: Sat, 27 May 2023 21:12:13 +0300 Subject: [PATCH] test: add tests for utils/urlMatchers.ts (#143) * add tests for urlMatchers * Update test/utils/urlMatcher.test.ts I agree Co-authored-by: Brian Douglas * change abcd to google.com --------- Co-authored-by: Brian Douglas --- test/utils/urlMatcher.test.ts | 51 ++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/test/utils/urlMatcher.test.ts b/test/utils/urlMatcher.test.ts index 2f4514de..cfe40882 100644 --- a/test/utils/urlMatcher.test.ts +++ b/test/utils/urlMatcher.test.ts @@ -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', () => { @@ -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) +}) \ No newline at end of file