test: 添加 giturl 的测试
This commit is contained in:
parent
0ac624ed2a
commit
2b0c11525b
|
|
@ -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 '';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { canBeConvertToDate } from '../src/utils/date';
|
||||
|
||||
describe('canBeConvertToDate()', () => {
|
||||
describe('test canBeConvertToDate()', () => {
|
||||
test('null', () => {
|
||||
expect(canBeConvertToDate(null)).toBe(false);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
@ -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',
|
||||
);
|
||||
});
|
||||
});
|
||||
Loading…
Reference in New Issue