Browse Source

test: 添加 giturl 的测试

pull/240/head
cp3hnu 10 months ago
parent
commit
2b0c11525b
4 changed files with 39 additions and 23 deletions
  1. +3
    -3
      react-ui/src/utils/index.ts
  2. +1
    -1
      react-ui/tests/date.test.ts
  3. +35
    -0
      react-ui/tests/getGitUrl.test.ts
  4. +0
    -19
      react-ui/tests/getGitUrl.tesx.ts

+ 3
- 3
react-ui/src/utils/index.ts 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 '';
}


+ 1
- 1
react-ui/tests/date.test.ts View File

@@ -1,6 +1,6 @@
import { canBeConvertToDate } from '../src/utils/date';

describe('canBeConvertToDate()', () => {
describe('test canBeConvertToDate()', () => {
test('null', () => {
expect(canBeConvertToDate(null)).toBe(false);
});


+ 35
- 0
react-ui/tests/getGitUrl.test.ts 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',
);
});
});

+ 0
- 19
react-ui/tests/getGitUrl.tesx.ts 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',
);
});
});

Loading…
Cancel
Save