Skip to content
Snippets Groups Projects
Unverified Commit a5a8031e authored by xgui3783's avatar xgui3783 Committed by GitHub
Browse files

Merge pull request #780 from HumanBrainProject/chore_regionInOtherTmpl

bugfix: show only latest version of region...
parents 2fa750d4 5d602e04
No related branches found
No related tags found
No related merge requests found
......@@ -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)
}
}
......
......@@ -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
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment