Skip to content

Commit

Permalink
feat: RepoCards
Browse files Browse the repository at this point in the history
  • Loading branch information
jialudev committed Dec 26, 2024
1 parent acab4b9 commit 8e22778
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 27 deletions.
2 changes: 0 additions & 2 deletions frontend/setupTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,10 @@ config.global.plugins = [

const DEFAULT_TAGS = []
const CSGHUB_SERVER = 'http://localhost:8080'
const ON_PREMISE = false

config.global.provide = {
defaultTags: DEFAULT_TAGS,
csghubServer: CSGHUB_SERVER,
onPremise: ON_PREMISE || false,
nameRule: /^(?=.{2,64}$)(?!.*[-_.]{2})[a-zA-Z][a-zA-Z0-9_.-]*[a-zA-Z0-9]+$/
};

Expand Down
74 changes: 50 additions & 24 deletions frontend/src/components/__tests__/shared/RepoCards.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,56 @@ vi.mock('@/components/shared/RepoCards.vue', async (importOriginal) => {

// Mock fetch API
vi.mock('@/packs/useFetchApi', () => ({
default: vi.fn(() => ({
json: () => Promise.resolve({
data: {
value: {
data: [
{
id: 1,
name: 'Repo 1',
path: 'user/repo-1',
updated_at: '2024-03-20 10:00:00',
downloads: 100
},
{
id: 2,
name: 'Repo 2',
path: 'user/repo-2',
updated_at: '2024-03-20 10:00:00',
downloads: 200
default: vi.fn((url) => ({
json: () => {
if (url === '/tags') {
return Promise.resolve({
data: {
value: {
data: [
{
category: 'task',
scope: 'model',
built_in: true,
group: 'computer_vision',
name: 'computer_vision',
show_name: 'Computer Vision'
},
{
category: 'framework',
scope: 'model',
built_in: true,
name: 'pytorch',
show_name: 'PyTorch'
},
{
category: 'language',
scope: 'model',
built_in: true,
name: 'python',
show_name: 'Python'
},
{
category: 'license',
scope: 'model',
built_in: true,
name: 'MIT',
show_name: 'MIT License'
}
]
}
],
total: 2
}
}
});
}
})
return Promise.resolve({
data: {
value: {
data: [],
total: 0
}
}
});
}
}))
}));

Expand Down Expand Up @@ -75,8 +101,8 @@ vi.mock('@/packs/useFetchApi', () => ({
category: 'language',
scope: 'model',
built_in: true,
name: 'python',
show_name: 'Python'
name: 'english',
show_name: 'English'
},
{
category: 'license',
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/shared/RepoCards.vue
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@
} else {
let tempTaskTags = {}
const allTaskTags = data.value.data.filter(tag => tag.category === 'task' && tag.scope === props.repoType && tag.built_in === true)
tagFields[props.repoType].forEach((field) => {
tagFields[props.repoType]?.forEach((field) => {
const fieldTags = allTaskTags.filter(tag => tag.group === field)
tempTaskTags[field] = fieldTags
})
Expand Down

0 comments on commit 8e22778

Please sign in to comment.