diff --git a/frontend/setupTests.js b/frontend/setupTests.js index 1d907ba8d..ac798a5a3 100644 --- a/frontend/setupTests.js +++ b/frontend/setupTests.js @@ -1,6 +1,7 @@ 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 SvgIcon from '@/components/shared/SvgIcon.vue'; import * as ElementPlusIconsVue from '@element-plus/icons-vue'; import { createI18n } from 'vue-i18n'; @@ -23,6 +24,7 @@ config.global.plugins = [ElementPlus, i18n, pinia]; // register global components config.global.components = { SvgIcon, + CsgButton, ...ElementPlusIconsVue }; diff --git a/frontend/src/components/__tests__/datasets/NewDataset.spec.js b/frontend/src/components/__tests__/datasets/NewDataset.spec.js index 5b6675169..837d65c92 100644 --- a/frontend/src/components/__tests__/datasets/NewDataset.spec.js +++ b/frontend/src/components/__tests__/datasets/NewDataset.spec.js @@ -12,16 +12,14 @@ vi.mock('../../../stores/UserStore', () => ({ })); // Mock useFetchApi -const mockPost = vi.fn().mockResolvedValue({ - json: async () => ({ - data: { value: { data: { path: 'testuser/testdataset' } } }, - error: { value: null } - }) - }); - vi.mock('../../../packs/useFetchApi', () => ({ default: () => ({ - post: () => mockPost(), + post: () => ({ + json: () => Promise.resolve({ + data: { value: { data: { path: 'testuser/testdataset' } } }, + error: { value: null } + }) + }) }) })); @@ -70,28 +68,25 @@ describe("NewDataset", () => { }); describe("form validation", () => { + const validateForm = () => { + return new Promise(resolve => { + wrapper.vm.$refs.dataFormRef.validate(valid => resolve(valid)) + }) + } it("validates required fields", async() => { - await wrapper.find('button').trigger('click'); - - await new Promise((resolve) => setTimeout(resolve, 300)) - const formErrors = wrapper.findAll('.el-form-item__error'); - expect(formErrors.length).toBeGreaterThan(0); + expect(await validateForm()).toBe(false) }) it("accepts invalid dataset name", async () => { wrapper.vm.dataForm.name = '**__invalid-name' - await wrapper.find('button').trigger('click'); - await new Promise((resolve) => setTimeout(resolve, 300)) - const errorMessage = wrapper.find('.el-form-item__error'); - expect(errorMessage.exists()).toBe(true); + await wrapper.vm.$nextTick() + expect(await validateForm()).toBe(false) }); it("accepts valid dataset name", async () => { wrapper.vm.dataForm.name = 'valid-name' - await wrapper.find('button').trigger('click'); - await new Promise((resolve) => setTimeout(resolve, 300)) - const errorMessage = wrapper.find('.el-form-item__error'); - expect(errorMessage.exists()).toBe(false); + await wrapper.vm.$nextTick() + expect(await validateForm()).toBe(true) }); }) diff --git a/frontend/src/components/application_spaces/ApplicationSpaceDetail.vue b/frontend/src/components/application_spaces/ApplicationSpaceDetail.vue index f25cdac85..c817e8740 100644 --- a/frontend/src/components/application_spaces/ApplicationSpaceDetail.vue +++ b/frontend/src/components/application_spaces/ApplicationSpaceDetail.vue @@ -1,5 +1,5 @@