diff --git a/aas-web-ui/tests/mixins/SubmodelElementHandling.test.ts b/aas-web-ui/tests/mixins/SubmodelElementHandling.test.ts index 8b37c21..29b0ae5 100644 --- a/aas-web-ui/tests/mixins/SubmodelElementHandling.test.ts +++ b/aas-web-ui/tests/mixins/SubmodelElementHandling.test.ts @@ -9,23 +9,283 @@ describe('SubmodelElementHandling', () => { setActivePinia(createPinia()); }); - it('should return true for valid Eclass SemanticId', () => { - // Define a test component that uses the mixin - const TestComponent = defineComponent({ - mixins: [SubmodelElementHandling], - template: '
', - }); + // Define a test component that uses the mixin + const DummyComponent = defineComponent({ + mixins: [SubmodelElementHandling], + template: '
', + }); + + // Define semanticId + const iri = 'https://admin-shell.io/zvei/nameplate/2/0/Nameplate'; + const eclassIrdiWithVersion = '0173-1#01-AHF578#001'; + const eclassIrdiWithoutVersion = '0173-1#01-AHF578'; + const eclassIrdiSlashesWithVersion = '0173/1///01#AHF578#001'; + const eclassIrdiSlashesWithoutVersion = '0173/1///01#AHF578'; + const eclassIriWithVersion = 'https://api.eclass-cdp.com/0173-1-01-AHF578-001'; + const eclassIriWithoutVersion = 'https://api.eclass-cdp.com/0173-1-01-AHF578'; + + // Define test data for semanticIdCheck() + const semanticIdTestCombinations = [ + // IRI test cases + { + semanticId: iri, + submodelElementSemanticId: iri, + strategy: 'exact', + match: true, + }, + + // Eclass IRDI (hash) test cases + { + semanticId: eclassIrdiWithVersion, + submodelElementSemanticId: eclassIrdiWithVersion, + strategy: 'exact', + match: true, + }, + { + semanticId: eclassIrdiWithoutVersion, + submodelElementSemanticId: eclassIrdiWithoutVersion, + strategy: 'exact', + match: true, + }, + { + semanticId: eclassIrdiWithVersion, + submodelElementSemanticId: eclassIrdiWithoutVersion, + strategy: '', + match: false, + }, + { + semanticId: eclassIrdiWithoutVersion, + submodelElementSemanticId: eclassIrdiWithVersion, + strategy: '', + match: true, + }, + + // Eclass IRDI (slashes) test cases + { + semanticId: eclassIrdiSlashesWithVersion, + submodelElementSemanticId: eclassIrdiSlashesWithVersion, + strategy: 'exact', + match: true, + }, + { + semanticId: eclassIrdiSlashesWithoutVersion, + submodelElementSemanticId: eclassIrdiSlashesWithoutVersion, + strategy: 'exact', + match: true, + }, + { + semanticId: eclassIrdiSlashesWithVersion, + submodelElementSemanticId: eclassIrdiSlashesWithoutVersion, + strategy: '', + match: false, + }, + { + semanticId: eclassIrdiSlashesWithoutVersion, + submodelElementSemanticId: eclassIrdiSlashesWithVersion, + strategy: '', + match: true, + }, + + // Eclass IRI test cases + { + semanticId: eclassIriWithVersion, + submodelElementSemanticId: eclassIriWithVersion, + strategy: 'exact', + match: true, + }, + { + semanticId: eclassIriWithoutVersion, + submodelElementSemanticId: eclassIriWithoutVersion, + strategy: 'exact', + match: true, + }, + { + semanticId: eclassIriWithVersion, + submodelElementSemanticId: eclassIriWithoutVersion, + strategy: '', + match: false, + }, + { + semanticId: eclassIriWithoutVersion, + submodelElementSemanticId: eclassIriWithVersion, + strategy: '', + match: true, + }, + + // Eclass IRDI (hash) and IRDI (slashes) test cases + { + semanticId: eclassIrdiWithVersion, + submodelElementSemanticId: eclassIrdiSlashesWithVersion, + strategy: 'exact', + match: true, + }, + { + semanticId: eclassIrdiSlashesWithVersion, + submodelElementSemanticId: eclassIrdiWithVersion, + strategy: 'exact', + match: true, + }, + + { + semanticId: eclassIrdiWithoutVersion, + submodelElementSemanticId: eclassIrdiSlashesWithoutVersion, + strategy: 'exact', + match: true, + }, + { + semanticId: eclassIrdiSlashesWithoutVersion, + submodelElementSemanticId: eclassIrdiWithoutVersion, + strategy: 'exact', + match: true, + }, + + { + semanticId: eclassIrdiWithVersion, + submodelElementSemanticId: eclassIrdiSlashesWithoutVersion, + strategy: '', + match: false, + }, + { + semanticId: eclassIrdiSlashesWithoutVersion, + submodelElementSemanticId: eclassIrdiWithVersion, + strategy: '', + match: false, + }, - // Mount the component - const wrapper: VueWrapper = shallowMount(TestComponent); + { + semanticId: eclassIrdiWithoutVersion, + submodelElementSemanticId: eclassIrdiSlashesWithVersion, + strategy: '', + match: true, + }, + { + semanticId: eclassIrdiSlashesWithVersion, + submodelElementSemanticId: eclassIrdiWithoutVersion, + strategy: '', + match: true, + }, - // Define test data - const submodelElement = { - semanticId: { keys: [{ value: '0173-1#01-AHF578#001' }] }, - }; - const validEclassSemanticId = '0173-1#01-AHF578#001'; + // Eclass IRDI (hash) and IRI test cases + { + semanticId: eclassIrdiWithVersion, + submodelElementSemanticId: eclassIriWithVersion, + strategy: 'exact', + match: true, + }, + { + semanticId: eclassIriWithVersion, + submodelElementSemanticId: eclassIrdiWithVersion, + strategy: 'exact', + match: true, + }, - // Perform the assertion - expect(wrapper.vm.checkSemanticId(submodelElement, validEclassSemanticId)).toBe(true); + { + semanticId: eclassIrdiWithoutVersion, + submodelElementSemanticId: eclassIriWithoutVersion, + strategy: 'exact', + match: true, + }, + { + semanticId: eclassIriWithoutVersion, + submodelElementSemanticId: eclassIrdiWithoutVersion, + strategy: 'exact', + match: true, + }, + + { + semanticId: eclassIrdiWithVersion, + submodelElementSemanticId: eclassIriWithoutVersion, + strategy: '', + match: false, + }, + { + semanticId: eclassIriWithoutVersion, + submodelElementSemanticId: eclassIrdiWithVersion, + strategy: '', + match: false, + }, + + { + semanticId: eclassIrdiWithoutVersion, + submodelElementSemanticId: eclassIriWithVersion, + strategy: '', + match: true, + }, + { + semanticId: eclassIriWithVersion, + submodelElementSemanticId: eclassIrdiWithoutVersion, + strategy: '', + match: true, + }, + + // Eclass IRDI (slashes) and IRI test cases + { + semanticId: eclassIrdiSlashesWithVersion, + submodelElementSemanticId: eclassIriWithVersion, + strategy: 'exact', + match: true, + }, + { + semanticId: eclassIriWithVersion, + submodelElementSemanticId: eclassIrdiSlashesWithVersion, + strategy: 'exact', + match: true, + }, + + { + semanticId: eclassIrdiSlashesWithoutVersion, + submodelElementSemanticId: eclassIriWithoutVersion, + strategy: 'exact', + match: true, + }, + { + semanticId: eclassIriWithoutVersion, + submodelElementSemanticId: eclassIrdiSlashesWithoutVersion, + strategy: 'exact', + match: true, + }, + + { + semanticId: eclassIrdiSlashesWithVersion, + submodelElementSemanticId: eclassIriWithoutVersion, + strategy: '', + match: false, + }, + { + semanticId: eclassIriWithoutVersion, + submodelElementSemanticId: eclassIrdiSlashesWithVersion, + strategy: '', + match: false, + }, + + { + semanticId: eclassIrdiSlashesWithoutVersion, + submodelElementSemanticId: eclassIriWithVersion, + strategy: '', + match: true, + }, + { + semanticId: eclassIriWithVersion, + submodelElementSemanticId: eclassIrdiSlashesWithoutVersion, + strategy: '', + match: true, + }, + ]; + + // Tests for semanticIdCheck() + semanticIdTestCombinations.forEach(function (semanticIdTestCombination) { + it(`Should return ${semanticIdTestCombination.match} for ${semanticIdTestCombination.strategy} matching ${semanticIdTestCombination.submodelElementSemanticId} and ${semanticIdTestCombination.semanticId}`, () => { + // Mount the component + const wrapper: VueWrapper = shallowMount(DummyComponent); + + // Define test data + const semanticId = semanticIdTestCombination.semanticId; //e.g. the ID of a ConceptDescription + const submodelElement = { + semanticId: { keys: [{ value: semanticIdTestCombination.submodelElementSemanticId }] }, + }; + + // Perform the assertion + expect(wrapper.vm.checkSemanticId(submodelElement, semanticId)).toBe(semanticIdTestCombination.match); + }); }); });