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
d04d8568
Commit
d04d8568
authored
3 years ago
by
Tifenn Guillas
Browse files
Options
Downloads
Patches
Plain Diff
Tests on detail effects => DONE
parent
b6e94dd8
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/detail.effects.spec.ts
+101
-118
101 additions, 118 deletions
client/src/app/instance/store/effects/detail.effects.spec.ts
with
101 additions
and
118 deletions
client/src/app/instance/store/effects/detail.effects.spec.ts
+
101
−
118
View file @
d04d8568
...
@@ -2,6 +2,7 @@ import { TestBed } from '@angular/core/testing';
...
@@ -2,6 +2,7 @@ import { TestBed } from '@angular/core/testing';
import
{
provideMockActions
}
from
'
@ngrx/effects/testing
'
;
import
{
provideMockActions
}
from
'
@ngrx/effects/testing
'
;
import
{
EffectsMetadata
,
getEffectsMetadata
}
from
'
@ngrx/effects
'
;
import
{
EffectsMetadata
,
getEffectsMetadata
}
from
'
@ngrx/effects
'
;
import
{
MockStore
,
provideMockStore
}
from
'
@ngrx/store/testing
'
;
import
{
Observable
}
from
'
rxjs
'
;
import
{
Observable
}
from
'
rxjs
'
;
import
{
cold
,
hot
}
from
'
jasmine-marbles
'
;
import
{
cold
,
hot
}
from
'
jasmine-marbles
'
;
import
{
ToastrService
}
from
'
ngx-toastr
'
;
import
{
ToastrService
}
from
'
ngx-toastr
'
;
...
@@ -9,16 +10,11 @@ import { ToastrService } from 'ngx-toastr';
...
@@ -9,16 +10,11 @@ import { ToastrService } from 'ngx-toastr';
import
{
DetailEffects
}
from
'
./detail.effects
'
;
import
{
DetailEffects
}
from
'
./detail.effects
'
;
import
{
DetailService
}
from
'
../services/detail.service
'
;
import
{
DetailService
}
from
'
../services/detail.service
'
;
import
*
as
detailActions
from
'
../actions/detail.actions
'
;
import
*
as
detailActions
from
'
../actions/detail.actions
'
;
import
{
Resolver
}
from
'
../models
'
;
import
{
MockStore
,
provideMockStore
}
from
'
@ngrx/store/testing
'
;
import
*
as
detailSelector
from
'
../selectors/detail.selector
'
;
import
*
as
detailSelector
from
'
../selectors/detail.selector
'
;
import
*
as
attributeSelector
from
'
src/app/metamodel/selectors/attribute.selector
'
;
import
*
as
attributeSelector
from
'
src/app/metamodel/selectors/attribute.selector
'
;
import
*
as
datasetSelector
from
'
src/app/metamodel/selectors/dataset.selector
'
;
import
*
as
datasetSelector
from
'
src/app/metamodel/selectors/dataset.selector
'
;
import
*
as
fromDetail
from
'
../reducers/detail.reducer
'
;
import
*
as
fromDetail
from
'
../reducers/detail.reducer
'
;
import
*
as
fromMetamodel
from
'
../../../metamodel/metamodel.reducer
'
;
import
*
as
fromMetamodel
from
'
../../../metamodel/metamodel.reducer
'
;
import
{
HttpClient
}
from
'
@angular/common/http
'
;
import
{
MemoizedSelector
}
from
'
@ngrx/store
'
;
import
{
Attribute
,
Dataset
,
Option
,
RendererConfig
}
from
'
../../../metamodel/models
'
;
describe
(
'
DetailEffects
'
,
()
=>
{
describe
(
'
DetailEffects
'
,
()
=>
{
let
actions
=
new
Observable
();
let
actions
=
new
Observable
();
...
@@ -56,23 +52,10 @@ describe('DetailEffects', () => {
...
@@ -56,23 +52,10 @@ describe('DetailEffects', () => {
store
=
TestBed
.
inject
(
MockStore
);
store
=
TestBed
.
inject
(
MockStore
);
toastr
=
TestBed
.
inject
(
ToastrService
);
toastr
=
TestBed
.
inject
(
ToastrService
);
mockDatasetSelectorSelectDatasetNameByRoute
=
store
.
overrideSelector
(
mockDatasetSelectorSelectDatasetNameByRoute
=
store
.
overrideSelector
(
datasetSelector
.
selectDatasetNameByRoute
,
datasetSelector
.
selectDatasetNameByRoute
,
''
'
myDatasetName
'
);
);
mockAttributeSelectorSelectAllAttributes
=
store
.
overrideSelector
(
mockAttributeSelectorSelectAllAttributes
=
store
.
overrideSelector
(
attributeSelector
.
selectAllAttributes
,
attributeSelector
.
selectAllAttributes
,[]
[{
id
:
1
,
name
:
'
myFirstAttribute
'
,
label
:
'
My First Attribute
'
,
form_label
:
'
My First Attribute
'
,
output_display
:
1
,
criteria_display
:
1
,
type
:
'
type
'
,
display_detail
:
1
,
order_by
:
true
,
detail
:
true
}]
as
Attribute
[]
);
);
mockDetailSelectorSelectIdByRoute
=
store
.
overrideSelector
(
mockDetailSelectorSelectIdByRoute
=
store
.
overrideSelector
(
detailSelector
.
selectIdByRoute
,
1
detailSelector
.
selectIdByRoute
,
1
...
@@ -84,46 +67,72 @@ describe('DetailEffects', () => {
...
@@ -84,46 +67,72 @@ describe('DetailEffects', () => {
});
});
describe
(
'
retrieveObject$ effect
'
,
()
=>
{
describe
(
'
retrieveObject$ effect
'
,
()
=>
{
// it.only('should call retrieveObject method of service', () => {
it
(
'
should dispatch the retrieveObjectSuccess action on success
'
,
()
=>
{
// const action = detailActions.retrieveObject();
mockDatasetSelectorSelectDatasetNameByRoute
=
store
.
overrideSelector
(
// jest.spyOn(detailService, 'retrieveObject');
datasetSelector
.
selectDatasetNameByRoute
,
'
myDatasetName
'
// actions = hot('a', { a: action });
);
// const outcome = detailActions.retrieveObjectSuccess({ object: 'myObject' });
mockAttributeSelectorSelectAllAttributes
=
store
.
overrideSelector
(
// const expected = cold('--b', { b: outcome });
attributeSelector
.
selectAllAttributes
,
[{
//
id
:
1
,
// // TODO: logger les params envoyé au service mocké.
name
:
'
myFirstAttribute
'
,
// // console.log(myMock.mock.calls.length);
label
:
'
My First Attribute
'
,
//
form_label
:
'
My First Attribute
'
,
// expect(effects.retrieveObject$).toBeObservable(expected);
output_display
:
1
,
// // expect(true).toBeTruthy();
criteria_display
:
1
,
// });
type
:
'
type
'
,
display_detail
:
1
,
// it('should dispatch the retrieveObjectSuccess action on success', () => {
order_by
:
true
,
// const action = detailActions.retrieveObject();
detail
:
true
// const outcome = detailActions.retrieveObjectSuccess({ object: 'myObject' });
}]
//
);
// actions = hot('-a', { a: action });
mockDetailSelectorSelectIdByRoute
=
store
.
overrideSelector
(
// const response = cold('-a|', { a: ['myObject'] });
detailSelector
.
selectIdByRoute
,
1
// const expected = cold('--b', { b: outcome });
);
// detailService.retrieveObject = jest.fn(() => response);
//
const
action
=
detailActions
.
retrieveObject
();
// expect(effects.retrieveObject$).toBeObservable(expected);
const
outcome
=
detailActions
.
retrieveObjectSuccess
({
object
:
'
myObject
'
});
// });
actions
=
hot
(
'
-a
'
,
{
a
:
action
});
// it('should dispatch the retrieveObjectFail action on failure', () => {
const
response
=
cold
(
'
-b|
'
,
{
b
:
[
'
myObject
'
]
});
// const action = detailActions.retrieveObject();
const
expected
=
cold
(
'
--c
'
,
{
c
:
outcome
});
// const error = new Error();
detailService
.
retrieveObject
=
jest
.
fn
(()
=>
response
);
// const outcome = detailActions.retrieveObjectFail();
//
expect
(
effects
.
retrieveObject$
).
toBeObservable
(
expected
);
// actions = hot('-a', { a: action });
});
// const response = cold('-#|', {}, error);
// const expected = cold('--b', { b: outcome });
it
(
'
should dispatch the retrieveObjectFail action on failure
'
,
()
=>
{
// detailService.retrieveObject = jest.fn(() => response);
mockDatasetSelectorSelectDatasetNameByRoute
=
store
.
overrideSelector
(
//
datasetSelector
.
selectDatasetNameByRoute
,
'
myDatasetName
'
// console.log(effects.retrieveObject$);
);
//
mockAttributeSelectorSelectAllAttributes
=
store
.
overrideSelector
(
// expect(effects.retrieveObject$).toBeObservable(expected);
attributeSelector
.
selectAllAttributes
,
[{
// });
id
:
1
,
name
:
'
myFirstAttribute
'
,
label
:
'
My First Attribute
'
,
form_label
:
'
My First Attribute
'
,
output_display
:
1
,
criteria_display
:
1
,
type
:
'
type
'
,
display_detail
:
1
,
order_by
:
true
,
detail
:
true
}]
);
mockDetailSelectorSelectIdByRoute
=
store
.
overrideSelector
(
detailSelector
.
selectIdByRoute
,
1
);
const
action
=
detailActions
.
retrieveObject
();
const
error
=
new
Error
();
const
outcome
=
detailActions
.
retrieveObjectFail
();
actions
=
hot
(
'
-a
'
,
{
a
:
action
});
const
response
=
cold
(
'
-#|
'
,
{},
error
);
const
expected
=
cold
(
'
--b
'
,
{
b
:
outcome
});
detailService
.
retrieveObject
=
jest
.
fn
(()
=>
response
);
expect
(
effects
.
retrieveObject$
).
toBeObservable
(
expected
);
});
});
});
describe
(
'
retrieveObjectFail$ effect
'
,
()
=>
{
describe
(
'
retrieveObjectFail$ effect
'
,
()
=>
{
...
@@ -147,64 +156,38 @@ describe('DetailEffects', () => {
...
@@ -147,64 +156,38 @@ describe('DetailEffects', () => {
});
});
describe
(
'
retrieveSpectra$ effect
'
,
()
=>
{
describe
(
'
retrieveSpectra$ effect
'
,
()
=>
{
// it('should call retrieveSpectra method of service', () => {
it
(
'
should dispatch the retrieveSpectraSuccess action on success
'
,
()
=>
{
// console.log(store);
mockDatasetSelectorSelectDatasetNameByRoute
=
store
.
overrideSelector
(
//
datasetSelector
.
selectDatasetNameByRoute
,
'
myDatasetName
'
// const action = detailActions.retrieveSpectra({ filename: 'mySpectra' });
);
// jest.spyOn(detailService, 'retrieveSpectra');
// actions = hot('a', { a: action });
const
action
=
detailActions
.
retrieveSpectra
({
filename
:
'
mySpectraFilename
'
});
// const expected = cold('a', { a: action });
const
outcome
=
detailActions
.
retrieveSpectraSuccess
({
spectraCSV
:
'
mySpectraFile
'
});
//
// expect(effects.retrieveSpectra$).toBeObservable(expected);
actions
=
hot
(
'
-a
'
,
{
a
:
action
});
// });
const
response
=
cold
(
'
-b|
'
,
{
b
:
'
mySpectraFile
'
});
const
expected
=
cold
(
'
--c
'
,
{
c
:
outcome
});
// it('should dispatch the retrieveSpectraSuccess action on success', () => {
detailService
.
retrieveSpectra
=
jest
.
fn
(()
=>
response
);
// const name: string = 'myObjectName';
// const apiResponse = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
expect
(
effects
.
retrieveSpectra$
).
toBeObservable
(
expected
);
// "<Sesame xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +
});
// " xsi:noNamespaceSchemaLocation=\"http://vizier.u-strasbg.fr/xml/sesame_4x.xsd\">\n" +
// "<Target option=\"NSV\">\n" +
it
(
'
should dispatch the retrieveSpectraFail action on failure
'
,
()
=>
{
// " <name>myObjectName</name>\n" +
mockDatasetSelectorSelectDatasetNameByRoute
=
store
.
overrideSelector
(
// " <!-- Q1525761 #1 -->\n" +
datasetSelector
.
selectDatasetNameByRoute
,
'
myDatasetName
'
// " <Resolver name=\"N=NED\"><!--delay: 989ms [2] -->\n" +
);
// " <otype>!*</otype>\n" +
// " <jpos>06:45:09.24 -16:42:47.3</jpos>\n" +
const
action
=
detailActions
.
retrieveSpectra
({
filename
:
'
mySpectraFilename
'
});
// " <jradeg>1</jradeg>\n" +
const
error
=
new
Error
();
// " <jdedeg>2</jdedeg>\n" +
const
outcome
=
detailActions
.
retrieveSpectraFail
();
// " <refPos>2007A&A...474..653V</refPos>\n" +
// " <errRAmas>50</errRAmas><errDEmas>500</errDEmas>\n" +
actions
=
hot
(
'
-a
'
,
{
a
:
action
});
// " <oname>Sirius</oname>\n" +
const
response
=
cold
(
'
-#|
'
,
{},
error
);
// " </Resolver>\n" +
const
expected
=
cold
(
'
--b
'
,
{
b
:
outcome
});
// "</Target>\n" +
detailService
.
retrieveSpectra
=
jest
.
fn
(()
=>
response
);
// "</Sesame>\n" +
// "<!--- ====Done (2021-Aug-04,15:00:56z)==== -->\n";
expect
(
effects
.
retrieveSpectra$
).
toBeObservable
(
expected
);
// const resolver: Resolver = { name: 'myObjectName', ra: 1, dec: 2 };
});
// const action = coneSearchActions.retrieveCoordinates({ name });
// const outcome = coneSearchActions.retrieveCoordinatesSuccess({ resolver });
//
// actions = hot('-a', { a: action });
// const response = cold('-a|', { a: apiResponse });
// const expected = cold('--b', { b: outcome });
// coneSearchService.retrieveCoordinates = jest.fn(() => response);
//
// expect(effects.retrieveCoordinates$).toBeObservable(expected);
// console.log(store.select())
// expect(false).toBeTruthy();
// });
// it('should dispatch the retrieveSpectraFail action on failure', () => {
// const name: string = 'myObjectName';
// const action = coneSearchActions.retrieveCoordinates({ name });
// const error = new Error();
// const outcome = coneSearchActions.retrieveCoordinatesFail();
//
// actions = hot('-a', { a: action });
// const response = cold('-#|', {}, error);
// const expected = cold('--b', { b: outcome });
// coneSearchService.retrieveCoordinates = jest.fn(() => response);
//
// expect(effects.retrieveCoordinates$).toBeObservable(expected);
// });
});
});
describe
(
'
retrieveSpectraFail$ effect
'
,
()
=>
{
describe
(
'
retrieveSpectraFail$ effect
'
,
()
=>
{
...
...
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