Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace submit button #861

Merged
merged 4 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions frontend/setupTests.js
Original file line number Diff line number Diff line change
@@ -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
};
37 changes: 16 additions & 21 deletions frontend/src/components/__tests__/datasets/NewDataset.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
})
})
})
}));

Expand Down Expand Up @@ -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)
});
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,13 +318,12 @@
</p>
<div class="flex justify-end">
<el-form-item>
<button
<CsgButton
:loading="loading"
class="btn btn-primary btn-md"
@click="handleSubmit"
>
{{ t('application_spaces.new.create') }}
</button>
class="btn btn-primary btn-md"
:name="t('application_spaces.new.create')"
/>
</el-form-item>
</div>
</el-form>
Expand Down
7 changes: 3 additions & 4 deletions frontend/src/components/codes/NewCode.vue
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,12 @@
</p>
<div class="flex justify-end">
<el-form-item>
<button
<CsgButton
:loading="loading"
class="btn btn-primary btn-md"
:name="t('codes.newCode.createCode')"
@click="handleSubmit"
>
{{ t('codes.newCode.createCode') }}
</button>
/>
</el-form-item>
</div>
</el-form>
Expand Down
9 changes: 4 additions & 5 deletions frontend/src/components/collections/NewCollection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,11 @@
</el-form>
<div class="flex justify-end w-full">
<el-form-item>
<button
class="bg-brand-600 w-[118px] h-9 rounded-lg text-white flex items-center justify-center border disabled:text-gray-400 disabled:bg-gray-100 disabled:border-gray-200"
<CsgButton
class="btn btn-primary btn-md"
:name="$t('collections.newCollection.createCollection')"
@click="createCollection"
>
{{ $t('collections.newCollection.createCollection') }}
</button>
/>
</el-form-item>
</div>
</div>
Expand Down
12 changes: 5 additions & 7 deletions frontend/src/components/datasets/NewDataset.vue
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,12 @@
</p>
<div class="flex justify-end">
<el-form-item>
<button
<CsgButton
:loading="loading"
class="btn btn-primary btn-md"
@click="handleSubmit"
>
{{ t('datasets.newDataset.createDataset') }}
</button>
:name="t('datasets.newDataset.createDataset')"
@click="createDataset"
/>
</el-form-item>
</div>
</el-form>
Expand Down Expand Up @@ -296,8 +295,7 @@
body: JSON.stringify(params)
}
const newEndpoint = '/datasets'
const postres = await useFetchApi(newEndpoint, options).post()
const { data, error } = await postres.json()
const { data, error } = await useFetchApi(newEndpoint, options).post().json()

if (data.value) {
ElMessage.success(t('datasets.newDataset.createSuccess'))
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/components/endpoints/NewEndpoint.vue
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,12 @@

<div class="flex justify-end">
<el-form-item>
<button
<CsgButton
:loading="loading"
class="btn btn-primary btn-md"
@click="handleSubmit">
{{ t('endpoints.new.createEndpoint') }}
</button>
:name="t('endpoints.new.createEndpoint')"
@click="handleSubmit"
/>
</el-form-item>
</div>
</el-form>
Expand Down
9 changes: 4 additions & 5 deletions frontend/src/components/evaluations/NewEvaluation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,12 @@
{{ t('all.cancel') }}
</a>
<el-form-item>
<button
:disabled="submitLoading"
<CsgButton
class="btn btn-primary rounded-md text-sm font-medium flex items-center justify-center px-[14px] h-[42px]"
:disabled="submitLoading"
:name="t('evaluation.new.createEvaluation')"
@click="handleSubmit"
>
{{ t('evaluation.new.createEvaluation') }}
</button>
/>
</el-form-item>
</div>
</el-form>
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/components/finetune/NewFinetune.vue
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,12 @@

<div class="flex justify-end">
<el-form-item>
<button
<CsgButton
:loading="loading"
class="btn btn-primary btn-md"
@click="handleSubmit">
{{ t('finetune.new.createFinetune') }}
</button>
:name="t('finetune.new.createFinetune')"
@click="handleSubmit"
/>
</el-form-item>
</div>
</el-form>
Expand Down
9 changes: 4 additions & 5 deletions frontend/src/components/models/NewModel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,12 @@
</p>
<div class="flex justify-end">
<el-form-item>
<button
<CsgButton
:loading="loading"
class="btn btn-primary btn-md"
@click="handleSubmit"
>
{{ t('models.newModel.createModel') }}
</button>
:name="t('models.newModel.createModel')"
@click="createModel"
/>
</el-form-item>
</div>
</el-form>
Expand Down
12 changes: 5 additions & 7 deletions frontend/src/components/organizations/NewOrganization.vue
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,12 @@
</el-form-item>

<el-form-item>
<button
class="btn btn-primary btn-md"
style="width: 100%;"
<CsgButton
class="btn btn-primary btn-md w-full"
@click="handleSubmit"
:disabled="submitting"
>
{{ $t('organization.newOrganization.createOrg') }}
</button>
:loading="submitting"
:name="$t('organization.newOrganization.createOrg')"
/>
</el-form-item>
</el-form>
</div>
Expand Down
Loading