Skip to content

Commit

Permalink
fix: handling in NewModel and NewDataset components
Browse files Browse the repository at this point in the history
  • Loading branch information
jialudev committed Dec 19, 2024
1 parent 9cba818 commit 551bdbd
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
28 changes: 13 additions & 15 deletions frontend/src/components/__tests__/models/NewModel.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ const createWrapper = (props) => {
};


async function triggerFormButton(wrapper) {
const button = wrapper.findComponent({ name: 'CsgButton' })
await button.trigger('click');
await delay(300);
await wrapper.vm.$nextTick()
}

// Mock stores
vi.mock('../../../stores/UserStore', () => ({
default: () => ({
Expand All @@ -31,6 +38,7 @@ vi.mock('../../../stores/UserStore', () => ({
})
}));

const buttonClass = '.btn.btn-primary'

describe("NewModel", () => {
describe("mount", async () => {
Expand All @@ -43,34 +51,26 @@ describe("NewModel", () => {
describe("form validation", () => {
it("validates required fields", async () => {
const wrapper = createWrapper();
await wrapper.find('button').trigger('click');
await delay(300);
await wrapper.vm.$nextTick()
await triggerFormButton(wrapper);
const formErrors = wrapper.findAll('.el-form-item__error');
expect(formErrors.length).toBeGreaterThan(0);
});

it("validates model name length", async () => {
const wrapper = createWrapper();
wrapper.vm.dataForm.name = 'a'; // Invalid length
await wrapper.find('button').trigger('click');
await delay(300);
await wrapper.vm.$nextTick()
await triggerFormButton(wrapper);
expect(wrapper.find('.el-form-item__error').exists()).toBe(true);

wrapper.vm.dataForm.name = 'valid-model'; // Valid length
await wrapper.find('button').trigger('click');
await delay(300);
await wrapper.vm.$nextTick()
await triggerFormButton(wrapper);
expect(wrapper.find('.el-form-item__error').exists()).toBe(false);
});

it("validates owner selection", async () => {
const wrapper = createWrapper();
wrapper.vm.dataForm.owner = ''; // Invalid owner
await wrapper.find('button').trigger('click');
await delay(300);
await wrapper.vm.$nextTick()
await triggerFormButton(wrapper);
expect(wrapper.find('.el-form-item__error').exists()).toBe(true);
});
});
Expand Down Expand Up @@ -100,9 +100,7 @@ describe("NewModel", () => {
})
}));

await wrapper.find('button').trigger('click');
await delay(800);
await wrapper.vm.$nextTick();
await triggerFormButton(wrapper);

// validate href is correct
expect(window.location.href).toBe('/models/testuser/testmodel');
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/datasets/NewDataset.vue
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
:loading="loading"
class="btn btn-primary btn-md"
:name="t('datasets.newDataset.createDataset')"
@click="createDataset"
@click="handleSubmit"
/>
</el-form-item>
</div>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/models/NewModel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
:loading="loading"
class="btn btn-primary btn-md"
:name="t('models.newModel.createModel')"
@click="createModel"
@click="handleSubmit"
/>
</el-form-item>
</div>
Expand Down

0 comments on commit 551bdbd

Please sign in to comment.