From a065de7b39359bb1b21fa1e58b341648ce633695 Mon Sep 17 00:00:00 2001 From: zhendi Date: Wed, 18 Dec 2024 11:59:59 +0800 Subject: [PATCH 1/4] replace form submit button to csghub-button --- .../application_spaces/NewApplicationSpace.vue | 9 ++++----- frontend/src/components/codes/NewCode.vue | 7 +++---- .../src/components/collections/NewCollection.vue | 9 ++++----- frontend/src/components/datasets/NewDataset.vue | 9 ++++----- frontend/src/components/endpoints/NewEndpoint.vue | 8 ++++---- frontend/src/components/finetune/NewFinetune.vue | 8 ++++---- frontend/src/components/models/NewModel.vue | 9 ++++----- .../src/components/organizations/NewOrganization.vue | 12 +++++------- 8 files changed, 32 insertions(+), 39 deletions(-) diff --git a/frontend/src/components/application_spaces/NewApplicationSpace.vue b/frontend/src/components/application_spaces/NewApplicationSpace.vue index bb981b229..d4e0d3e41 100644 --- a/frontend/src/components/application_spaces/NewApplicationSpace.vue +++ b/frontend/src/components/application_spaces/NewApplicationSpace.vue @@ -318,13 +318,12 @@

- + class="btn btn-primary btn-md" + :name="t('application_spaces.new.create')" + />
diff --git a/frontend/src/components/codes/NewCode.vue b/frontend/src/components/codes/NewCode.vue index a00aff16a..7f0e1b9f1 100644 --- a/frontend/src/components/codes/NewCode.vue +++ b/frontend/src/components/codes/NewCode.vue @@ -139,13 +139,12 @@

- + />
diff --git a/frontend/src/components/collections/NewCollection.vue b/frontend/src/components/collections/NewCollection.vue index 5cb62efe7..227002969 100644 --- a/frontend/src/components/collections/NewCollection.vue +++ b/frontend/src/components/collections/NewCollection.vue @@ -128,12 +128,11 @@
- + />
diff --git a/frontend/src/components/datasets/NewDataset.vue b/frontend/src/components/datasets/NewDataset.vue index 8be3de8a9..769abf270 100644 --- a/frontend/src/components/datasets/NewDataset.vue +++ b/frontend/src/components/datasets/NewDataset.vue @@ -145,13 +145,12 @@

- + :name="t('datasets.newDataset.createDataset')" + @click="createDataset" + />
diff --git a/frontend/src/components/endpoints/NewEndpoint.vue b/frontend/src/components/endpoints/NewEndpoint.vue index 47124f0ad..e43d6f636 100644 --- a/frontend/src/components/endpoints/NewEndpoint.vue +++ b/frontend/src/components/endpoints/NewEndpoint.vue @@ -182,12 +182,12 @@
- + :name="t('endpoints.new.createEndpoint')" + @click="handleSubmit" + />
diff --git a/frontend/src/components/finetune/NewFinetune.vue b/frontend/src/components/finetune/NewFinetune.vue index c50826b9b..48ad21b8d 100644 --- a/frontend/src/components/finetune/NewFinetune.vue +++ b/frontend/src/components/finetune/NewFinetune.vue @@ -143,12 +143,12 @@
- + :name="t('finetune.new.createFinetune')" + @click="handleSubmit" + />
diff --git a/frontend/src/components/models/NewModel.vue b/frontend/src/components/models/NewModel.vue index 1c745d1c5..1ded835c7 100644 --- a/frontend/src/components/models/NewModel.vue +++ b/frontend/src/components/models/NewModel.vue @@ -143,13 +143,12 @@

- + :name="t('models.newModel.createModel')" + @click="createModel" + />
diff --git a/frontend/src/components/organizations/NewOrganization.vue b/frontend/src/components/organizations/NewOrganization.vue index c0badf160..84c29daa6 100644 --- a/frontend/src/components/organizations/NewOrganization.vue +++ b/frontend/src/components/organizations/NewOrganization.vue @@ -87,14 +87,12 @@ - + :loading="submitting" + :name="$t('organization.newOrganization.createOrg')" + /> From 581aa469c0d8be4ef2926e75ab568e8fa353ed34 Mon Sep 17 00:00:00 2001 From: zhendi Date: Wed, 18 Dec 2024 12:03:22 +0800 Subject: [PATCH 2/4] update new evaluation submit button --- frontend/src/components/evaluations/NewEvaluation.vue | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/frontend/src/components/evaluations/NewEvaluation.vue b/frontend/src/components/evaluations/NewEvaluation.vue index 271a35959..d5cb87141 100644 --- a/frontend/src/components/evaluations/NewEvaluation.vue +++ b/frontend/src/components/evaluations/NewEvaluation.vue @@ -220,13 +220,12 @@ {{ t('all.cancel') }} - + /> From 01449427f6d18c83e90781889387bebad77a4cbc Mon Sep 17 00:00:00 2001 From: zhendi Date: Wed, 18 Dec 2024 12:11:59 +0800 Subject: [PATCH 3/4] fix dataset create bug --- frontend/src/components/datasets/NewDataset.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/components/datasets/NewDataset.vue b/frontend/src/components/datasets/NewDataset.vue index 769abf270..3b8e842d3 100644 --- a/frontend/src/components/datasets/NewDataset.vue +++ b/frontend/src/components/datasets/NewDataset.vue @@ -295,7 +295,7 @@ body: JSON.stringify(params) } const newEndpoint = '/datasets' - const postres = await useFetchApi(newEndpoint, options).post() + const postres = await useFetchApi(newEndpoint, options).post().json() const { data, error } = await postres.json() if (data.value) { From 3418a11d085f5f2f0222725401dd550406d1fffc Mon Sep 17 00:00:00 2001 From: zhendi Date: Wed, 18 Dec 2024 14:15:13 +0800 Subject: [PATCH 4/4] update new dataset test --- frontend/setupTests.js | 7 ++++ .../__tests__/datasets/NewDataset.spec.js | 37 ++++++++----------- .../src/components/datasets/NewDataset.vue | 3 +- 3 files changed, 24 insertions(+), 23 deletions(-) diff --git a/frontend/setupTests.js b/frontend/setupTests.js index 3ad1c5931..4ec575ed2 100644 --- a/frontend/setupTests.js +++ b/frontend/setupTests.js @@ -1,5 +1,12 @@ import { config } from '@vue/test-utils'; import ElementPlus from 'element-plus'; import 'element-plus/dist/index.css'; +import CsgButton from './src/components/shared/CsgButton.vue'; +import SvgIcon from './src/components/shared/SvgIcon.vue'; config.global.plugins = [ElementPlus]; + +config.global.components = { + CsgButton, + SvgIcon +}; 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/datasets/NewDataset.vue b/frontend/src/components/datasets/NewDataset.vue index 3b8e842d3..caf96561b 100644 --- a/frontend/src/components/datasets/NewDataset.vue +++ b/frontend/src/components/datasets/NewDataset.vue @@ -295,8 +295,7 @@ body: JSON.stringify(params) } const newEndpoint = '/datasets' - const postres = await useFetchApi(newEndpoint, options).post().json() - const { data, error } = await postres.json() + const { data, error } = await useFetchApi(newEndpoint, options).post().json() if (data.value) { ElMessage.success(t('datasets.newDataset.createSuccess'))