Skip to content

Commit 1a0edca

Browse files
ice201508Jiuling.Lei
andauthored
fix-comandline-url (#1400)
Co-authored-by: Jiuling.Lei <[email protected]>
1 parent 6f98860 commit 1a0edca

File tree

2 files changed

+116
-1
lines changed

2 files changed

+116
-1
lines changed
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
import { describe, it, expect, vi, beforeEach } from "vitest";
2+
import { mount } from "@vue/test-utils";
3+
import { createPinia, setActivePinia } from 'pinia';
4+
import RepoClone from "@/components/shared/RepoClone.vue";
5+
import useRepoDetailStore from '@/stores/RepoDetailStore';
6+
7+
// Mock CSGHUB_SERVER 全局变量
8+
global.CSGHUB_SERVER = 'https://hub.opencsg.com';
9+
10+
vi.mock('@/packs/useFetchApi', () => ({
11+
default: vi.fn(() => ({
12+
json: () => Promise.resolve({
13+
data: { value: { data: [] } }
14+
}),
15+
post: () => ({
16+
json: () => Promise.resolve({ error: { value: null } })
17+
})
18+
}))
19+
}));
20+
21+
vi.mock('@/packs/config', () => ({
22+
isEE: () => false
23+
}));
24+
25+
vi.mock('@/packs/utils', () => ({
26+
ToLoginPage: vi.fn()
27+
}));
28+
29+
const createWrapper = (props = {}) => {
30+
const pinia = createPinia();
31+
setActivePinia(pinia);
32+
33+
const repoDetailStore = useRepoDetailStore();
34+
repoDetailStore.repository = {
35+
http_clone_url: 'https://hub.opencsg.com/models/test/repo.git',
36+
ssh_clone_url: '[email protected]:test/repo.git'
37+
};
38+
repoDetailStore.defaultBranch = 'main';
39+
40+
return mount(RepoClone, {
41+
props: {
42+
repoType: 'model',
43+
namespacePath: 'test/repo',
44+
repo: {
45+
source: 'local',
46+
syncStatus: 'completed',
47+
mirrorTaskStatus: 'idle'
48+
},
49+
enableEndpoint: false,
50+
enableFinetune: false,
51+
enableEvaluation: false,
52+
showAddToCollections: false,
53+
canManage: false,
54+
syncStatus: 'completed',
55+
commitId: 'abc123',
56+
...props
57+
},
58+
global: {
59+
stubs: {
60+
'svg-icon': true,
61+
'el-tooltip': true,
62+
'el-dialog': true,
63+
'el-tabs': true,
64+
'el-tab-pane': true,
65+
'el-checkbox': true,
66+
'markdown-viewer': true,
67+
'AddToCollections': true,
68+
'SyncDropdown': true,
69+
'UseModelDropdown': true,
70+
'CsgButton': true
71+
}
72+
}
73+
});
74+
};
75+
76+
describe("RepoClone - httpCloneProtocolHostname", () => {
77+
beforeEach(() => {
78+
vi.clearAllMocks();
79+
});
80+
81+
it("应该正确解析不带端口的域名", () => {
82+
global.CSGHUB_SERVER = 'https://hub.opencsg.com';
83+
const wrapper = createWrapper();
84+
85+
expect(wrapper.vm.httpCloneProtocolHostname).toBe('https://hub.opencsg.com');
86+
});
87+
88+
it("应该正确解析带有端口的域名", () => {
89+
global.CSGHUB_SERVER = 'https://hub.opencsg.com:8080';
90+
const wrapper = createWrapper();
91+
92+
expect(wrapper.vm.httpCloneProtocolHostname).toBe('https://hub.opencsg.com:8080');
93+
});
94+
95+
it("应该正确解析带有非标准端口的域名", () => {
96+
global.CSGHUB_SERVER = 'http://localhost:3000';
97+
const wrapper = createWrapper();
98+
99+
expect(wrapper.vm.httpCloneProtocolHostname).toBe('http://localhost:3000');
100+
});
101+
102+
it("应该正确解析带有端口的IP地址", () => {
103+
global.CSGHUB_SERVER = 'http://192.168.1.100:8080';
104+
const wrapper = createWrapper();
105+
106+
expect(wrapper.vm.httpCloneProtocolHostname).toBe('http://192.168.1.100:8080');
107+
});
108+
109+
it("应该正确处理https协议带端口的情况", () => {
110+
global.CSGHUB_SERVER = 'https://example.com:9443';
111+
const wrapper = createWrapper();
112+
113+
expect(wrapper.vm.httpCloneProtocolHostname).toBe('https://example.com:9443');
114+
});
115+
});

frontend/src/components/shared/RepoClone.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@
383383
const httpCloneProtocolHostname = computed(() => {
384384
const url = new URL(CSGHUB_SERVER)
385385
if (!url) return ''
386-
return `${url.protocol}//${url.hostname}`
386+
return `${url.protocol}//${url.host}`
387387
})
388388
389389
const httpsCloneCode = computed(() => {

0 commit comments

Comments
 (0)