Skip to content
Snippets Groups Projects
Commit ce38bebf authored by Benedikt Heinrichs's avatar Benedikt Heinrichs
Browse files

Fix: No Validation on Empty Metadata (coscine/issues#2417)

parent c99b2bd3
No related tags found
1 merge request!119Fix: No Validation on Empty Metadata
...@@ -10,6 +10,7 @@ import FormGenerator from '@/FormGenerator.vue'; ...@@ -10,6 +10,7 @@ import FormGenerator from '@/FormGenerator.vue';
import { listApplicationProfile } from '@/data/example/applicationProfile'; import { listApplicationProfile } from '@/data/example/applicationProfile';
import { listFixedValues } from '@/data/example/fixedValues'; import { listFixedValues } from '@/data/example/fixedValues';
import { listMetadata } from '@/data/example/metadata'; import { listMetadata } from '@/data/example/metadata';
import factory from 'rdf-ext';
function sleep(ms: number) { function sleep(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms)); return new Promise((resolve) => setTimeout(resolve, ms));
...@@ -138,4 +139,43 @@ describe('FormGenerator.vue', () => { ...@@ -138,4 +139,43 @@ describe('FormGenerator.vue', () => {
'Banana' 'Banana'
); );
}); });
/* Checks for correct functionality of empty metadatasets */
test('listWithEmptyMetadataFixedValues', async () => {
const wrapper = mount(FormGenerator, {
propsData: {
fixedValues: {},
formData: factory.dataset(),
selectedShape: 'https://aims-projekt.de/ap/agent/',
shapes: listApplicationProfile,
shapesMimeType: 'text/turtle',
userReceiver: () => {
return {
displayName: defaultDisplayName,
};
},
},
});
await wrapper.vm.$nextTick();
// Wait for 1 second until everything is set up
await sleep(1000);
expect(wrapper.emitted('isValid')).toBeFalsy();
const allTextFields = wrapper.findAllComponents({ name: 'InputTextField' });
expect(allTextFields.length).toBe(1);
await allTextFields.wrappers[0].setValue('example@example.org');
// Wait for validation debounce
await sleep(1000);
expect(wrapper.emitted('isValid')).toBeTruthy();
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
expect(wrapper.emitted('isValid')!.length).toBe(1);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
expect(wrapper.emitted('isValid')![0][0].conforms).toBeTruthy();
});
}); });
...@@ -82,6 +82,10 @@ export default defineComponent({ ...@@ -82,6 +82,10 @@ export default defineComponent({
if (this.timeOuts[validationContext]) { if (this.timeOuts[validationContext]) {
clearTimeout(this.timeOuts[validationContext]); clearTimeout(this.timeOuts[validationContext]);
} }
// Do not try to validate empty metadata sets
if (metadata.size === 0) {
return;
}
const clonedMetadata = factory.dataset( const clonedMetadata = factory.dataset(
Array.from(metadata) Array.from(metadata)
) as unknown as Dataset; ) as unknown as Dataset;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment