Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
siibra-explorer
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Xiao Gui
siibra-explorer
Commits
bd181061
Commit
bd181061
authored
3 years ago
by
Xiao Gui
Browse files
Options
Downloads
Patches
Plain Diff
bugfix: roi$ should retain ngId information
parent
4e228fec
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/viewerModule/viewerCmp/viewerCmp.component.spec.ts
+125
-0
125 additions, 0 deletions
src/viewerModule/viewerCmp/viewerCmp.component.spec.ts
src/viewerModule/viewerCmp/viewerCmp.component.ts
+26
-22
26 additions, 22 deletions
src/viewerModule/viewerCmp/viewerCmp.component.ts
with
151 additions
and
22 deletions
src/viewerModule/viewerCmp/viewerCmp.component.spec.ts
0 → 100644
+
125
−
0
View file @
bd181061
import
{
TestBed
}
from
"
@angular/core/testing
"
import
{
MockStore
,
provideMockStore
}
from
"
@ngrx/store/testing
"
import
{
hot
}
from
"
jasmine-marbles
"
import
{
Observable
,
of
,
throwError
}
from
"
rxjs
"
import
{
viewerStateContextedSelectedRegionsSelector
}
from
"
src/services/state/viewerState/selectors
"
import
{
ROIFactory
}
from
"
./viewerCmp.component
"
describe
(
'
> viewerCmp.component.ts
'
,
()
=>
{
let
mockStore
:
MockStore
beforeEach
(()
=>
{
TestBed
.
configureTestingModule
({
providers
:
[
provideMockStore
()
]
})
mockStore
=
TestBed
.
inject
(
MockStore
)
})
describe
(
'
> ROIFactory
'
,
()
=>
{
const
mockDetail
=
{
foo
:
'
bar
'
}
class
MockPCSvc
{
getRegionDetail
(){
return
of
(
mockDetail
)
}
}
const
pcsvc
=
new
MockPCSvc
()
let
getRegionDetailSpy
:
jasmine
.
Spy
beforeEach
(()
=>
{
getRegionDetailSpy
=
spyOn
(
pcsvc
,
'
getRegionDetail
'
)
mockStore
.
overrideSelector
(
viewerStateContextedSelectedRegionsSelector
,
[])
})
afterEach
(()
=>
{
getRegionDetailSpy
.
calls
.
reset
()
})
describe
(
'
> if regoinselected is empty array
'
,
()
=>
{
let
returnVal
:
Observable
<
any
>
beforeEach
(()
=>
{
getRegionDetailSpy
.
and
.
callThrough
()
returnVal
=
ROIFactory
(
mockStore
,
pcsvc
as
any
)
})
it
(
'
> returns null
'
,
()
=>
{
expect
(
returnVal
).
toBeObservable
(
hot
(
'
a
'
,
{
a
:
null
}))
})
it
(
'
> regionDetail not called
'
,
()
=>
{
expect
(
getRegionDetailSpy
).
not
.
toHaveBeenCalled
()
})
})
describe
(
'
> if regionselected is nonempty
'
,
()
=>
{
const
mockRegion
=
{
context
:
{
template
:
{
'
@id
'
:
'
template-id
'
},
parcellation
:
{
'
@id
'
:
'
parcellation-id
'
},
atlas
:
{
'
@id
'
:
'
atlas-id
'
}
},
ngId
:
'
foo-bar
'
,
labelIndex
:
123
}
const
returnDetail
=
{
map
:
{
hello
:
'
world
'
}
}
let
returnVal
:
Observable
<
any
>
beforeEach
(()
=>
{
getRegionDetailSpy
.
and
.
callFake
(()
=>
of
(
returnDetail
))
mockStore
.
overrideSelector
(
viewerStateContextedSelectedRegionsSelector
,
[
mockRegion
])
returnVal
=
ROIFactory
(
mockStore
,
pcsvc
as
any
)
})
// TODO check why marble is acting weird
// and that null is not emitted
it
(
'
> returns as expected
'
,
()
=>
{
expect
(
returnVal
).
toBeObservable
(
hot
(
'
b
'
,
{
a
:
null
,
b
:
{
...
mockRegion
,
...
returnDetail
}
})
)
const
{
context
}
=
mockRegion
expect
(
getRegionDetailSpy
).
toHaveBeenCalledWith
(
context
.
atlas
[
"
@id
"
],
context
.
parcellation
[
"
@id
"
],
context
.
template
[
"
@id
"
],
mockRegion
)
})
it
(
'
> if getRegionDetail throws, at least return original region
'
,
()
=>
{
getRegionDetailSpy
.
and
.
callFake
(()
=>
throwError
(
'
blabla
'
))
expect
(
returnVal
).
toBeObservable
(
hot
(
'
b
'
,
{
a
:
null
,
b
:
mockRegion
})
)
const
{
context
}
=
mockRegion
expect
(
getRegionDetailSpy
).
toHaveBeenCalledWith
(
context
.
atlas
[
"
@id
"
],
context
.
parcellation
[
"
@id
"
],
context
.
template
[
"
@id
"
],
mockRegion
)
})
})
})
})
This diff is collapsed.
Click to expand it.
src/viewerModule/viewerCmp/viewerCmp.component.ts
+
26
−
22
View file @
bd181061
...
...
@@ -28,6 +28,31 @@ type TCStoreViewerCmp = {
overlaySideNav
:
any
}
export
function
ROIFactory
(
store
:
Store
<
any
>
,
svc
:
PureContantService
){
return
store
.
pipe
(
select
(
viewerStateContextedSelectedRegionsSelector
),
switchMap
(
r
=>
{
if
(
!
r
[
0
])
return
of
(
null
)
const
{
context
}
=
r
[
0
]
const
{
atlas
,
template
,
parcellation
}
=
context
||
{}
return
merge
(
of
(
null
),
svc
.
getRegionDetail
(
atlas
[
'
@id
'
],
parcellation
[
'
@id
'
],
template
[
'
@id
'
],
r
[
0
]).
pipe
(
map
(
det
=>
{
return
{
...
r
[
0
],
...
det
,
}
}),
// in case detailed requests fails
catchError
((
_err
,
_obs
)
=>
of
(
r
[
0
])),
)
)
}),
shareReplay
(
1
)
)
}
@
Component
({
selector
:
'
iav-cmp-viewer-container
'
,
templateUrl
:
'
./viewerCmp.template.html
'
,
...
...
@@ -70,28 +95,7 @@ type TCStoreViewerCmp = {
providers
:
[
{
provide
:
REGION_OF_INTEREST
,
useFactory
:
(
store
:
Store
<
any
>
,
svc
:
PureContantService
)
=>
store
.
pipe
(
select
(
viewerStateContextedSelectedRegionsSelector
),
switchMap
(
r
=>
{
if
(
!
r
[
0
])
return
of
(
null
)
const
{
context
}
=
r
[
0
]
const
{
atlas
,
template
,
parcellation
}
=
context
||
{}
return
merge
(
of
(
null
),
svc
.
getRegionDetail
(
atlas
[
'
@id
'
],
parcellation
[
'
@id
'
],
template
[
'
@id
'
],
r
[
0
]).
pipe
(
map
(
det
=>
{
return
{
...
det
,
context
}
}),
// in case detailed requests
catchError
((
_err
,
_obs
)
=>
of
(
r
[
0
])),
)
)
}),
shareReplay
(
1
)
),
useFactory
:
ROIFactory
,
deps
:
[
Store
,
PureContantService
]
},
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment