Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
anis-next
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
anis
anis-next
Commits
b6e94dd8
Commit
b6e94dd8
authored
3 years ago
by
Tifenn Guillas
Browse files
Options
Downloads
Patches
Plain Diff
Tests on search effects => DONE
parent
1d3e3f8c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!29
Develop
,
!8
Resolve "Add tests for instance store module"
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
client/src/app/instance/store/effects/search.effects.spec.ts
+125
-53
125 additions, 53 deletions
client/src/app/instance/store/effects/search.effects.spec.ts
with
125 additions
and
53 deletions
client/src/app/instance/store/effects/search.effects.spec.ts
+
125
−
53
View file @
b6e94dd8
...
...
@@ -2,6 +2,7 @@ import { TestBed } from '@angular/core/testing';
import
{
provideMockActions
}
from
'
@ngrx/effects/testing
'
;
import
{
EffectsMetadata
,
getEffectsMetadata
}
from
'
@ngrx/effects
'
;
import
{
MockStore
,
provideMockStore
}
from
'
@ngrx/store/testing
'
;
import
{
Observable
}
from
'
rxjs
'
;
import
{
cold
,
hot
}
from
'
jasmine-marbles
'
;
import
{
ToastrService
}
from
'
ngx-toastr
'
;
...
...
@@ -9,7 +10,6 @@ import { ToastrService } from 'ngx-toastr';
import
{
SearchEffects
}
from
'
./search.effects
'
;
import
{
SearchService
}
from
'
../services/search.service
'
;
import
*
as
searchActions
from
'
../actions/search.actions
'
;
import
{
MockStore
,
provideMockStore
}
from
'
@ngrx/store/testing
'
;
import
*
as
fromSearch
from
'
../reducers/search.reducer
'
;
import
*
as
datasetSelector
from
'
../../../metamodel/selectors/dataset.selector
'
;
import
*
as
searchSelector
from
'
../selectors/search.selector
'
;
...
...
@@ -19,9 +19,8 @@ import * as outputFamilyActions from '../../../metamodel/actions/output-family.a
import
*
as
outputCategoryActions
from
'
../../../metamodel/actions/output-category.actions
'
;
import
*
as
attributeSelector
from
'
../../../metamodel/selectors/attribute.selector
'
;
import
*
as
coneSearchSelector
from
'
../selectors/cone-search.selector
'
;
import
{
RendererConfig
}
from
'
../../../metamodel/models/renderers
'
;
import
{
Option
}
from
'
../../../metamodel/models
'
;
import
*
as
coneSearchActions
from
'
../actions/cone-search.actions
'
;
import
{
Criterion
,
PaginationOrder
}
from
'
../models
'
;
describe
(
'
SearchEffects
'
,
()
=>
{
let
actions
=
new
Observable
();
...
...
@@ -37,8 +36,11 @@ describe('SearchEffects', () => {
let
mockSearchSelectorSelectStepsByRoute
;
let
mockAttributeSelectorSelectAllAttributes
;
let
mockSearchSelectorSelectCriteriaListByRoute
;
let
mockSearchSelectorSelectCriteriaList
;
let
mockConeSearchSelectorSelectConeSearchByRoute
;
let
mockConeSearchSelectorSelectConeSearch
;
let
mockSearchSelectorSelectOutputListByRoute
;
let
mockSearchSelectorSelectOutputList
;
beforeEach
(()
=>
{
TestBed
.
configureTestingModule
({
...
...
@@ -76,12 +78,21 @@ describe('SearchEffects', () => {
mockSearchSelectorSelectCriteriaListByRoute
=
store
.
overrideSelector
(
searchSelector
.
selectCriteriaListByRoute
,
''
);
mockSearchSelectorSelectCriteriaList
=
store
.
overrideSelector
(
searchSelector
.
selectCriteriaList
,[]
);
mockConeSearchSelectorSelectConeSearchByRoute
=
store
.
overrideSelector
(
coneSearchSelector
.
selectConeSearchByRoute
,
''
);
mockConeSearchSelectorSelectConeSearch
=
store
.
overrideSelector
(
coneSearchSelector
.
selectConeSearch
,{
ra
:
1
,
dec
:
2
,
radius
:
3
}
);
mockSearchSelectorSelectOutputListByRoute
=
store
.
overrideSelector
(
searchSelector
.
selectOutputListByRoute
,
''
);
mockSearchSelectorSelectOutputList
=
store
.
overrideSelector
(
searchSelector
.
selectOutputList
,[]
);
});
it
(
'
should be created
'
,
()
=>
{
...
...
@@ -495,30 +506,56 @@ describe('SearchEffects', () => {
});
describe
(
'
retrieveDataLength$ effect
'
,
()
=>
{
// it('should dispatch the retrieveDataLengthSuccess action on success', () => {
// const action = searchActions.retrieveDataLength();
// const outcome = searchActions.retrieveDataLengthSuccess({ length: 1 });
//
// actions = hot('-a', { a: action });
// const response = cold('-a|', { a: action });
// const expected = cold('--b', { b: outcome });
// searchService.retrieveDataLength = jest.fn(() => response);
//
// expect(effects.retrieveDataLength$).toBeObservable(expected);
// });
// it('should dispatch the registerFail action on failure', () => {
// const action = searchActions.retrieveDataLength();
// const error = new Error();
// const outcome = searchActions.retrieveDataLengthFail();
//
// actions = hot('-a', { a: action });
// const response = cold('-#|', {}, error);
// const expected = cold('--b', { b: outcome });
// searchService.retrieveDataLength = jest.fn(() => response);
//
// expect(effects.retrieveDataLength$).toBeObservable(expected);
// });
it
(
'
should dispatch the retrieveDataLengthSuccess action on success
'
,
()
=>
{
const
action
=
searchActions
.
retrieveDataLength
();
const
outcome
=
searchActions
.
retrieveDataLengthSuccess
({
length
:
5
});
actions
=
hot
(
'
-a
'
,
{
a
:
action
});
const
response
=
cold
(
'
-b|
'
,
{
b
:
[{
nb
:
5
}]
});
const
expected
=
cold
(
'
--c
'
,
{
c
:
outcome
});
searchService
.
retrieveDataLength
=
jest
.
fn
(()
=>
response
);
expect
(
effects
.
retrieveDataLength$
).
toBeObservable
(
expected
);
});
it
(
'
should dispatch the retrieveDataLengthFail action on failure
'
,
()
=>
{
const
action
=
searchActions
.
retrieveDataLength
();
const
error
=
new
Error
();
const
outcome
=
searchActions
.
retrieveDataLengthFail
();
actions
=
hot
(
'
-a
'
,
{
a
:
action
});
const
response
=
cold
(
'
-#|
'
,
{},
error
);
const
expected
=
cold
(
'
--b
'
,
{
b
:
outcome
});
searchService
.
retrieveDataLength
=
jest
.
fn
(()
=>
response
);
expect
(
effects
.
retrieveDataLength$
).
toBeObservable
(
expected
);
});
it
(
'
should pass correct query to the service
'
,
()
=>
{
mockDatasetSelectorSelectDatasetNameByRoute
=
store
.
overrideSelector
(
datasetSelector
.
selectDatasetNameByRoute
,
'
myDataset
'
);
mockSearchSelectorSelectCriteriaList
=
store
.
overrideSelector
(
searchSelector
.
selectCriteriaList
,
[{
'
id
'
:
1
,
'
type
'
:
'
field
'
,
'
operator
'
:
'
eq
'
,
'
value
'
:
'
one
'
}
as
Criterion
]
);
mockConeSearchSelectorSelectConeSearch
=
store
.
overrideSelector
(
coneSearchSelector
.
selectConeSearch
,
{
ra
:
1
,
dec
:
2
,
radius
:
3
}
);
jest
.
spyOn
(
searchService
,
'
retrieveDataLength
'
);
const
action
=
searchActions
.
retrieveDataLength
();
const
outcome
=
searchActions
.
retrieveDataLengthSuccess
({
length
:
5
});
actions
=
hot
(
'
-a
'
,
{
a
:
action
});
const
response
=
cold
(
'
-b|
'
,
{
b
:
[{
nb
:
5
}]
});
const
expected
=
cold
(
'
--c
'
,
{
c
:
outcome
});
searchService
.
retrieveDataLength
=
jest
.
fn
(()
=>
response
);
expect
(
effects
.
retrieveDataLength$
).
toBeObservable
(
expected
);
expect
(
searchService
.
retrieveDataLength
).
toHaveBeenCalledTimes
(
1
);
expect
(
searchService
.
retrieveDataLength
).
toHaveBeenCalledWith
(
'
myDataset?a=count&c=1::eq::one&cs=1:2:3
'
);
});
});
describe
(
'
retrieveDataLengthFail$ effect
'
,
()
=>
{
...
...
@@ -541,32 +578,67 @@ describe('SearchEffects', () => {
});
});
// describe('retrieveData$ effect', () => {
// it('should dispatch the registerSuccess action on success', () => {
// const action = sampActions.register();
// const outcome = sampActions.registerSuccess();
//
// actions = hot('-a', { a: action });
// const response = cold('-a|', { a: action });
// const expected = cold('--b', { b: outcome });
// sampService.register = jest.fn(() => response);
//
// expect(effects.register$).toBeObservable(expected);
// });
//
// it('should dispatch the registerFail action on failure', () => {
// const action = sampActions.register();
// const error = new Error();
// const outcome = sampActions.registerFail();
//
// actions = hot('-a', { a: action });
// const response = cold('-#|', {}, error);
// const expected = cold('--b', { b: outcome });
// sampService.register = jest.fn(() => response);
//
// expect(effects.register$).toBeObservable(expected);
// });
// });
describe
(
'
retrieveData$ effect
'
,
()
=>
{
it
(
'
should dispatch the retrieveDataSuccess action on success
'
,
()
=>
{
const
action
=
searchActions
.
retrieveData
(
{
pagination
:
{
dname
:
'
myDatasetName
'
,
page
:
1
,
nbItems
:
10
,
sortedCol
:
1
,
order
:
PaginationOrder
.
a
}
});
const
outcome
=
searchActions
.
retrieveDataSuccess
({
data
:
[
'
data
'
]
});
actions
=
hot
(
'
-a
'
,
{
a
:
action
});
const
response
=
cold
(
'
-b|
'
,
{
b
:
[
'
data
'
]
});
const
expected
=
cold
(
'
--c
'
,
{
c
:
outcome
});
searchService
.
retrieveData
=
jest
.
fn
(()
=>
response
);
expect
(
effects
.
retrieveData$
).
toBeObservable
(
expected
);
});
it
(
'
should dispatch the retrieveDataFail action on failure
'
,
()
=>
{
const
action
=
searchActions
.
retrieveData
({
pagination
:
{
dname
:
'
myDatasetName
'
,
page
:
1
,
nbItems
:
10
,
sortedCol
:
1
,
order
:
PaginationOrder
.
a
}
});
const
error
=
new
Error
();
const
outcome
=
searchActions
.
retrieveDataFail
();
actions
=
hot
(
'
-a
'
,
{
a
:
action
});
const
response
=
cold
(
'
-#|
'
,
{},
error
);
const
expected
=
cold
(
'
--b
'
,
{
b
:
outcome
});
searchService
.
retrieveData
=
jest
.
fn
(()
=>
response
);
expect
(
effects
.
retrieveData$
).
toBeObservable
(
expected
);
});
it
(
'
should pass correct query to the service
'
,
()
=>
{
mockDatasetSelectorSelectDatasetNameByRoute
=
store
.
overrideSelector
(
datasetSelector
.
selectDatasetNameByRoute
,
'
myDataset
'
);
mockSearchSelectorSelectCriteriaList
=
store
.
overrideSelector
(
searchSelector
.
selectCriteriaList
,
[{
'
id
'
:
1
,
'
type
'
:
'
field
'
,
'
operator
'
:
'
eq
'
,
'
value
'
:
'
one
'
}
as
Criterion
]
);
mockConeSearchSelectorSelectConeSearch
=
store
.
overrideSelector
(
coneSearchSelector
.
selectConeSearch
,
{
ra
:
1
,
dec
:
2
,
radius
:
3
}
);
mockSearchSelectorSelectOutputList
=
store
.
overrideSelector
(
searchSelector
.
selectOutputList
,
[
1
,
2
]
);
jest
.
spyOn
(
searchService
,
'
retrieveData
'
);
const
action
=
searchActions
.
retrieveData
({
pagination
:
{
dname
:
'
myDatasetName
'
,
page
:
1
,
nbItems
:
10
,
sortedCol
:
1
,
order
:
PaginationOrder
.
a
}
});
const
outcome
=
searchActions
.
retrieveDataSuccess
({
data
:
[
'
data
'
]
});
actions
=
hot
(
'
-a
'
,
{
a
:
action
});
const
response
=
cold
(
'
-b|
'
,
{
b
:
[
'
data
'
]
});
const
expected
=
cold
(
'
--c
'
,
{
c
:
outcome
});
searchService
.
retrieveData
=
jest
.
fn
(()
=>
response
);
expect
(
effects
.
retrieveData$
).
toBeObservable
(
expected
);
expect
(
searchService
.
retrieveData
).
toHaveBeenCalledTimes
(
1
);
expect
(
searchService
.
retrieveData
).
toHaveBeenCalledWith
(
'
myDataset?a=1;2&c=1::eq::one&cs=1:2:3&p=10:1&o=1:a
'
);
});
});
describe
(
'
retrieveDataFail$ effect
'
,
()
=>
{
it
(
'
should not dispatch
'
,
()
=>
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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