From 2b0c11525b60dcd38d88f8cbb077067946d3d0d7 Mon Sep 17 00:00:00 2001 From: cp3hnu Date: Thu, 22 May 2025 09:21:27 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E6=B7=BB=E5=8A=A0=20giturl=20=E7=9A=84?= =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- react-ui/src/utils/index.ts | 6 +++--- react-ui/tests/date.test.ts | 2 +- react-ui/tests/getGitUrl.test.ts | 35 ++++++++++++++++++++++++++++++++ react-ui/tests/getGitUrl.tesx.ts | 19 ----------------- 4 files changed, 39 insertions(+), 23 deletions(-) create mode 100644 react-ui/tests/getGitUrl.test.ts delete mode 100644 react-ui/tests/getGitUrl.tesx.ts diff --git a/react-ui/src/utils/index.ts b/react-ui/src/utils/index.ts index a62e6e88..2db6af2a 100644 --- a/react-ui/src/utils/index.ts +++ b/react-ui/src/utils/index.ts @@ -267,14 +267,14 @@ export const hasNoValue = (value?: any | null): boolean => { /** * 获取 git 仓库的 url * - * @param {string} url - the url of the git repository - * @param {string} branch - the branch of the repository + * @param {string} [url] - the url of the git repository + * @param {string} [branch] - the branch of the repository * @return {string} the url of the repository * * If `branch` is given, the url will be in the format of 'http://gitlab.com/user/repo/tree/branch'. * Otherwise, the url will be in the format of 'http://gitlab.com/user/repo'. */ -export const getGitUrl = (url: string, branch: string): string => { +export const getGitUrl = (url?: string, branch?: string): string => { if (!url) { return ''; } diff --git a/react-ui/tests/date.test.ts b/react-ui/tests/date.test.ts index 6dbb028f..af91d8ab 100644 --- a/react-ui/tests/date.test.ts +++ b/react-ui/tests/date.test.ts @@ -1,6 +1,6 @@ import { canBeConvertToDate } from '../src/utils/date'; -describe('canBeConvertToDate()', () => { +describe('test canBeConvertToDate()', () => { test('null', () => { expect(canBeConvertToDate(null)).toBe(false); }); diff --git a/react-ui/tests/getGitUrl.test.ts b/react-ui/tests/getGitUrl.test.ts new file mode 100644 index 00000000..19be4061 --- /dev/null +++ b/react-ui/tests/getGitUrl.test.ts @@ -0,0 +1,35 @@ +import { getGitUrl } from '../src/utils'; + +describe('test getGitUrl', () => { + test('undefined', () => { + expect(getGitUrl(undefined)).toBe(''); + }); + + test('empty url', () => { + expect(getGitUrl('')).toBe(''); + }); + + test('url domain with branch', () => { + expect( + getGitUrl('https://gitlink.org.cn/somunslotus/material-atom-predict.git', 'master'), + ).toBe('https://gitlink.org.cn/somunslotus/material-atom-predict/tree/master'); + }); + + test('url domain without branch', () => { + expect(getGitUrl('https://gitlink.org.cn/somunslotus/material-atom-predict.git')).toBe( + 'https://gitlink.org.cn/somunslotus/material-atom-predict', + ); + }); + + test('30202 port with branch', () => { + expect(getGitUrl('http://172.20.32.235:30202/fanshuai/active_learn_demo.git', 'master')).toBe( + 'http://172.20.32.235:30203/fanshuai/active_learn_demo/tree/master', + ); + }); + + test('30202 port without branch', () => { + expect(getGitUrl('http://172.20.32.235:30202/fanshuai/active_learn_demo.git')).toBe( + 'http://172.20.32.235:30203/fanshuai/active_learn_demo', + ); + }); +}); diff --git a/react-ui/tests/getGitUrl.tesx.ts b/react-ui/tests/getGitUrl.tesx.ts deleted file mode 100644 index b33a592e..00000000 --- a/react-ui/tests/getGitUrl.tesx.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { getGitUrl } from '../src/utils'; - -describe('canBeConvertToDate()', () => { - test('empty string', () => { - expect(getGitUrl('', '')).toBe(''); - }); - - test('url domain with branch', () => { - expect( - getGitUrl('https://gitlink.org.cn/somunslotus/material-atom-predict.git', 'master'), - ).toBe('https://gitlink.org.cn/somunslotus/material-atom-predict/tree/master'); - }); - - test('url domain without branch', () => { - expect(getGitUrl('https://gitlink.org.cn/somunslotus/material-atom-predict.git', '')).toBe( - 'https://gitlink.org.cn/somunslotus/material-atom-predict.git', - ); - }); -});