diff --git a/src/ui/parcellationRegion/region.base.ts b/src/ui/parcellationRegion/region.base.ts index 51ea824139a920943ebcc57f3b4a117da74c2129..473a830af001bb96e532fb38d2f516afb92390b7 100644 --- a/src/ui/parcellationRegion/region.base.ts +++ b/src/ui/parcellationRegion/region.base.ts @@ -90,19 +90,31 @@ export class RegionBase { const filteredRsInOtherTmpls = [] for (const bundledObj of regionsInOtherTemplates) { const { template, parcellation, region } = bundledObj - const idx = filteredRsInOtherTmpls.findIndex(({ template: _template, region: _region }) => { + + /** + * trying to find duplicate region + * with same templateId, and same hemisphere + */ + const sameEntityIdx = filteredRsInOtherTmpls.findIndex(({ template: _template, region: _region }) => { return _template['@id'] === template['@id'] - && getRegionHemisphere(_region) !== getRegionHemisphere(region) + && getRegionHemisphere(_region) === getRegionHemisphere(region) }) - if ( idx < 0 ) { + /** + * if doesn't exist, just push to output + */ + if ( sameEntityIdx < 0 ) { filteredRsInOtherTmpls.push(bundledObj) } else { - const { parcellation: currentParc } = filteredRsInOtherTmpls[idx] + + /** + * if exists, only append the latest version + */ + const { parcellation: currentParc } = filteredRsInOtherTmpls[sameEntityIdx] /** * if the new element is newer than existing item */ if (isNewerThan(parcellations, parcellation, currentParc)) { - filteredRsInOtherTmpls.splice(idx, 1) + filteredRsInOtherTmpls.splice(sameEntityIdx, 1) filteredRsInOtherTmpls.push(bundledObj) } } diff --git a/src/ui/parcellationRegion/regionMenu/regionMenu.component.spec.ts b/src/ui/parcellationRegion/regionMenu/regionMenu.component.spec.ts index fceeb0c7046afe38195967825e12cbd82097dde2..3c7f395eece740396746c2e452f9f9061490736b 100644 --- a/src/ui/parcellationRegion/regionMenu/regionMenu.component.spec.ts +++ b/src/ui/parcellationRegion/regionMenu/regionMenu.component.spec.ts @@ -112,161 +112,5 @@ describe('> regionMenu.component.ts', () => { const fixture = TestBed.createComponent(RegionMenuComponent) expect(fixture).toBeTruthy() }) - - describe('> regionInOtherTemplatesTmpl', () => { - beforeEach(() => { - const mockStore = TestBed.inject(MockStore) - mockStore.overrideSelector( - viewerStateGetSelectedAtlas, - { parcellations: [] } - ) - }) - - it('> if selector returns empty array, data-available-in-tmpl-count == 0', () => { - - const mockStore = TestBed.inject(MockStore) - mockStore.overrideSelector( - regionInOtherTemplateSelector, - [] - ) - - const fixture = TestBed.createComponent(RegionMenuComponent) - fixture.componentInstance.region = mr1 - fixture.detectChanges() - - const toggleBtn = fixture.debugElement.query( By.css(`[aria-label="${ARIA_LABELS.AVAILABILITY_IN_OTHER_REF_SPACE}"]`) ) - expect(toggleBtn.attributes['data-available-in-tmpl-count']).toEqual('0') - }) - - it('> if selector returns non empty array, data-available-in-tmpl-count == array.length', () => { - - const mockStore = TestBed.inject(MockStore) - mockStore.overrideSelector( - regionInOtherTemplateSelector, - nohemisphereHrms - ) - - const fixture = TestBed.createComponent(RegionMenuComponent) - fixture.componentInstance.region = mr1 - fixture.detectChanges() - - const toggleBtn = fixture.debugElement.query( By.css(`[aria-label="${ARIA_LABELS.AVAILABILITY_IN_OTHER_REF_SPACE}"]`) ) - expect(toggleBtn.attributes['data-available-in-tmpl-count']).toEqual('2') - }) - - it('> if showRegionInOtherTmpl is set to false, toggle btn will not be shown', () => { - - const mockStore = TestBed.inject(MockStore) - mockStore.overrideSelector( - regionInOtherTemplateSelector, - nohemisphereHrms - ) - - const fixture = TestBed.createComponent(RegionMenuComponent) - fixture.componentInstance.region = mr1 - fixture.componentInstance.showRegionInOtherTmpl = false - fixture.detectChanges() - - const toggleBtn = fixture.debugElement.query( By.css(`[aria-label="${ARIA_LABELS.SHOW_IN_OTHER_REF_SPACE}"]`) ) - expect(toggleBtn).toBeFalsy() - }) - - it('> even if toggleBtn exists, list should be hidden by default', () => { - - const mockStore = TestBed.inject(MockStore) - mockStore.overrideSelector( - regionInOtherTemplateSelector, - nohemisphereHrms - ) - - const fixture = TestBed.createComponent(RegionMenuComponent) - fixture.componentInstance.region = mr1 - fixture.detectChanges() - - const listContainer = fixture.debugElement.query( By.css(`[aria-label="${ARIA_LABELS.SHOW_IN_OTHER_REF_SPACE}"]`) ) - expect(listContainer).toBeFalsy() - }) - - it('> on click of toggle btn, list to become visible', () => { - - const mockStore = TestBed.inject(MockStore) - mockStore.overrideSelector( - regionInOtherTemplateSelector, - nohemisphereHrms - ) - - const fixture = TestBed.createComponent(RegionMenuComponent) - fixture.componentInstance.region = mr1 - fixture.detectChanges() - const toggleBtn = fixture.debugElement.query( By.css(`[aria-label="${ARIA_LABELS.AVAILABILITY_IN_OTHER_REF_SPACE}"]`) ) - toggleBtn.triggerEventHandler('click', null) - fixture.detectChanges() - const listContainer = fixture.debugElement.query( By.css(`[aria-label="${ARIA_LABELS.SHOW_IN_OTHER_REF_SPACE}"]`) ) - expect(listContainer).toBeTruthy() - }) - - it('> once list becomes available, there should be 2 items on the list', () => { - - const mockStore = TestBed.inject(MockStore) - mockStore.overrideSelector( - regionInOtherTemplateSelector, - nohemisphereHrms - ) - - const fixture = TestBed.createComponent(RegionMenuComponent) - fixture.componentInstance.region = mr1 - fixture.detectChanges() - const toggleBtn = fixture.debugElement.query( By.css(`[aria-label="${ARIA_LABELS.AVAILABILITY_IN_OTHER_REF_SPACE}"]`) ) - toggleBtn.triggerEventHandler('click', null) - fixture.detectChanges() - const listContainer = fixture.debugElement.queryAll( By.css(`[aria-label="${ARIA_LABELS.SHOW_IN_OTHER_REF_SPACE}"] [role="button"]`) ) - expect(listContainer.length).toEqual(2) - }) - - it('> the text (no hemisphere metadata) on the list is as expected', () => { - - const mockStore = TestBed.inject(MockStore) - mockStore.overrideSelector( - regionInOtherTemplateSelector, - nohemisphereHrms - ) - - const fixture = TestBed.createComponent(RegionMenuComponent) - fixture.componentInstance.region = mr1 - fixture.detectChanges() - const toggleBtn = fixture.debugElement.query( By.css(`[aria-label="${ARIA_LABELS.AVAILABILITY_IN_OTHER_REF_SPACE}"]`) ) - toggleBtn.triggerEventHandler('click', null) - fixture.detectChanges() - const listContainer = fixture.debugElement.queryAll( By.css(`[aria-label="${ARIA_LABELS.SHOW_IN_OTHER_REF_SPACE}"] [role="button"]`) ) - - // trim white spaces before and after - - const texts = listContainer.map(c => c.nativeElement.textContent.replace(/^\s+/, '').replace(/\s+$/, '')) - expect(texts).toContain(mt0.name) - expect(texts).toContain(mt1.name) - }) - - it('> the text (with hemisphere metadata) on the list is as expected', () => { - - const mockStore = TestBed.inject(MockStore) - mockStore.overrideSelector( - regionInOtherTemplateSelector, - hemisphereMrms - ) - - const fixture = TestBed.createComponent(RegionMenuComponent) - fixture.componentInstance.region = mr1 - fixture.detectChanges() - const toggleBtn = fixture.debugElement.query( By.css(`[aria-label="${ARIA_LABELS.AVAILABILITY_IN_OTHER_REF_SPACE}"]`) ) - toggleBtn.triggerEventHandler('click', null) - fixture.detectChanges() - const listContainer = fixture.debugElement.queryAll( By.css(`[aria-label="${ARIA_LABELS.SHOW_IN_OTHER_REF_SPACE}"] [role="button"]`) ) - - // trim white spaces before and after, and middle white spaces into a single white space - const texts = listContainer.map(c => c.nativeElement.textContent.replace(/^\s+/, '').replace(/\s+$/, '').replace(/\s+/g, ' ')) - expect(texts).toContain(`${mt0.name} (left hemisphere)`) - expect(texts).toContain(`${mt1.name} (left hemisphere)`) - }) - }) }) }) \ No newline at end of file