From f7548cecfd54702e1503290f69122be9f8b85e13 Mon Sep 17 00:00:00 2001 From: Keerthi Humsika Kattamudi Date: Fri, 17 Jul 2026 10:17:16 -0500 Subject: [PATCH] [BI-2959] BI-2959: Updated frontend External UID lookup logic to display the value and added unit tests for canonical External UID display. --- .../model/import/germplasm/ExternalUID.ts | 11 ++-- src/breeding-insight/utils/GermplasmUtils.ts | 4 +- src/views/import/ImportGermplasm.vue | 2 +- tests/unit/models/externalUID.spec.ts | 51 ++++++++++++++++ tests/unit/models/germplasmUtils.spec.ts | 61 +++++++++++++++++++ 5 files changed, 120 insertions(+), 9 deletions(-) create mode 100644 tests/unit/models/externalUID.spec.ts create mode 100644 tests/unit/models/germplasmUtils.spec.ts diff --git a/src/breeding-insight/model/import/germplasm/ExternalUID.ts b/src/breeding-insight/model/import/germplasm/ExternalUID.ts index 4ca4d54fa..74b53c61b 100644 --- a/src/breeding-insight/model/import/germplasm/ExternalUID.ts +++ b/src/breeding-insight/model/import/germplasm/ExternalUID.ts @@ -18,17 +18,16 @@ export class ExternalUID { /** - * Get ExternalUID value from germplasm BrAPI external references array based - * on the seedSource value + * Get ExternalUID value from germplasm BrAPI external references array using + * the canonical External UID reference source. * * @param externalReferences - * @param source */ - public static getExternalUIDFromExternalReferences(externalReferences: Array, source : string) : string | undefined { - if (externalReferences === undefined || source === undefined) { + public static getExternalUIDFromExternalReferences(externalReferences: Array) : string | undefined { + if (externalReferences === undefined) { return undefined; } - const externalUID = externalReferences.find( ({ referenceSource }) => referenceSource === source ); + const externalUID = externalReferences.find( ({ referenceSource }) => referenceSource === "External UID" ); if (externalUID !== undefined) { return externalUID.referenceID; } else diff --git a/src/breeding-insight/utils/GermplasmUtils.ts b/src/breeding-insight/utils/GermplasmUtils.ts index 15ffa51c7..2c66c6b99 100644 --- a/src/breeding-insight/utils/GermplasmUtils.ts +++ b/src/breeding-insight/utils/GermplasmUtils.ts @@ -26,8 +26,8 @@ export const MOMENT_DATE_PERSISTED_FORMAT = 'DD/MM/YYYY h:mm:ss'; export class GermplasmUtils { static getExternalUID(germplasm: Germplasm): string | undefined { let val; - if (germplasm.externalReferences && germplasm.seedSource) { - val = germplasm.externalReferences!.filter(ref => ref.referenceSource == germplasm.seedSource!) + if (germplasm.externalReferences) { + val = germplasm.externalReferences!.filter(ref => ref.referenceSource == "External UID") .map(ref => ref.referenceID); return val ? val[0]: ""; } diff --git a/src/views/import/ImportGermplasm.vue b/src/views/import/ImportGermplasm.vue index 2bc95a1f6..12e315732 100644 --- a/src/views/import/ImportGermplasm.vue +++ b/src/views/import/ImportGermplasm.vue @@ -136,7 +136,7 @@ {{ props.row.data.brAPIObject.additionalInfo.maleParentEntryNo }} - {{ ExternalUID.getExternalUIDFromExternalReferences(props.row.data.brAPIObject.externalReferences, props.row.data.brAPIObject.seedSource) }} + {{ ExternalUID.getExternalUIDFromExternalReferences(props.row.data.brAPIObject.externalReferences) }} {{ GermplasmUtils.formatSynonyms(props.row.data.brAPIObject.synonyms) }} diff --git a/tests/unit/models/externalUID.spec.ts b/tests/unit/models/externalUID.spec.ts new file mode 100644 index 000000000..88281a995 --- /dev/null +++ b/tests/unit/models/externalUID.spec.ts @@ -0,0 +1,51 @@ +/* + * See the NOTICE file distributed with this work for additional information + * regarding copyright ownership. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { ExternalUID } from "@/breeding-insight/model/import/germplasm/ExternalUID"; + +describe('ExternalUID helper returns the correct values.', () => { + + it('Returns External UID when canonical External UID reference exists', () => { + const externalReferences = [ + { referenceSource: "USDA", referenceID: "OLD-123" }, + { referenceSource: "External UID", referenceID: "ABC-123" } + ]; + + expect(ExternalUID.getExternalUIDFromExternalReferences(externalReferences)).toBe("ABC-123"); + }); + + it('Returns External UID when canonical External UID reference exists and source is blank', () => { + const externalReferences = [ + { referenceSource: "External UID", referenceID: "ABC-456" } + ]; + + expect(ExternalUID.getExternalUIDFromExternalReferences(externalReferences)).toBe("ABC-456"); + }); + + it('Returns undefined when canonical External UID reference does not exist', () => { + const externalReferences = [ + { referenceSource: "USDA", referenceID: "OLD-123" } + ]; + + expect(ExternalUID.getExternalUIDFromExternalReferences(externalReferences)).toBeUndefined(); + }); + + it('Returns undefined when external references are undefined', () => { + expect(ExternalUID.getExternalUIDFromExternalReferences(undefined as any)).toBeUndefined(); + }); + +}); \ No newline at end of file diff --git a/tests/unit/models/germplasmUtils.spec.ts b/tests/unit/models/germplasmUtils.spec.ts new file mode 100644 index 000000000..8d873a513 --- /dev/null +++ b/tests/unit/models/germplasmUtils.spec.ts @@ -0,0 +1,61 @@ +/* + * See the NOTICE file distributed with this work for additional information + * regarding copyright ownership. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { GermplasmUtils } from "@/breeding-insight/utils/GermplasmUtils"; + +describe('GermplasmUtils External UID helper returns the correct values.', () => { + + it('Returns External UID from canonical External UID reference source', () => { + const germplasm: any = { + seedSource: "USDA", + externalReferences: [ + { referenceSource: "USDA", referenceID: "OLD-123" }, + { referenceSource: "External UID", referenceID: "ABC-123" } + ] + }; + + expect(GermplasmUtils.getExternalUID(germplasm)).toBe("ABC-123"); + }); + + it('Returns External UID when seed source is blank and canonical External UID reference exists', () => { + const germplasm: any = { + externalReferences: [ + { referenceSource: "External UID", referenceID: "ABC-456" } + ] + }; + + expect(GermplasmUtils.getExternalUID(germplasm)).toBe("ABC-456"); + }); + + it('Returns undefined when canonical External UID reference does not exist', () => { + const germplasm: any = { + seedSource: "USDA", + externalReferences: [ + { referenceSource: "USDA", referenceID: "OLD-123" } + ] + }; + + expect(GermplasmUtils.getExternalUID(germplasm)).toBeUndefined(); + }); + + it('Returns empty string when external references are missing', () => { + const germplasm: any = {}; + + expect(GermplasmUtils.getExternalUID(germplasm)).toBe(""); + }); + +}); \ No newline at end of file