Skip to content

Commit

Permalink
test: enhance setupTests configuration and update RepoCards tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jialudev committed Dec 26, 2024
1 parent 33f7519 commit acab4b9
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 11 deletions.
30 changes: 25 additions & 5 deletions frontend/setupTests.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import { config } from '@vue/test-utils';
import ElementPlus from 'element-plus';
import 'element-plus/dist/index.css';
import CsgButton from '@/components/shared/CsgButton.vue';
import CsgButton from '@/components/shared/CsgButton.vue';
import SvgIcon from '@/components/shared/SvgIcon.vue';
import FlashMessage from '@/components/shared/FlashMessage.vue';
import * as ElementPlusIconsVue from '@element-plus/icons-vue';
import { createI18n } from 'vue-i18n';
import { createPinia } from 'pinia'
import en from '@/locales/en.js'
import zh from '@/locales/zh.js'
import zhCn from 'element-plus/dist/locale/zh-cn.mjs'
import '@/assets/stylesheets/element-plus/_variables.css'
import '@/assets/stylesheets/markdown.css'
import '@/style.css'

const pinia = createPinia();
const i18n = createI18n({
Expand All @@ -19,16 +24,31 @@ const i18n = createI18n({
}
});

config.global.plugins = [ElementPlus, i18n, pinia];

// register global components
config.global.components = {
SvgIcon,
CsgButton,
FlashMessage,
...ElementPlusIconsVue
};

// gllbal mock
config.global.plugins = [
[ElementPlus, {
locale: zhCn,
}],
i18n,
pinia
];

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]+$/
};

// Mock window.location
const mockLocation = {
Expand Down
27 changes: 21 additions & 6 deletions frontend/src/components/__tests__/shared/RepoCards.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it, expect, beforeEach, vi } from "vitest";
import { describe, it, expect, vi } from "vitest";
import { mount } from "@vue/test-utils";
import RepoCards from "@/components/shared/RepoCards.vue";
import RepoItem from "@/components/shared/RepoItem.vue";
Expand Down Expand Up @@ -60,12 +60,30 @@ vi.mock('@/packs/useFetchApi', () => ({
category: 'task',
scope: 'model',
built_in: true,
group: 'computer_vision'
group: 'computer_vision',
name: 'computer_vision',
show_name: 'Computer Vision'
},
{
category: 'framework',
scope: 'model',
built_in: true
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'
}
]
}
Expand Down Expand Up @@ -97,9 +115,6 @@ const createWrapper = (props = {}) => {
TagSidebar,
CsgPagination
},
provide: {
onPremise: 'true'
},
stubs: {
'svg-icon': true,
'el-message': true
Expand Down

0 comments on commit acab4b9

Please sign in to comment.