test: 添加 giturl 的测试

This commit is contained in:
cp3hnu 2025-05-22 09:21:27 +08:00
parent 0ac624ed2a
commit 2b0c11525b
4 changed files with 39 additions and 23 deletions

View File

@ -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 '';
}

View File

@ -1,6 +1,6 @@
import { canBeConvertToDate } from '../src/utils/date';
describe('canBeConvertToDate()', () => {
describe('test canBeConvertToDate()', () => {
test('null', () => {
expect(canBeConvertToDate(null)).toBe(false);
});

View File

@ -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',
);
});
});

View File

@ -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',
);
});
});