Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
anis
anis-client
Commits
c92189a6
Commit
c92189a6
authored
Oct 09, 2019
by
Tifenn Guillas
Browse files
WIP: add tests
parent
002efdd5
Changes
14
Hide whitespace changes
Inline
Side-by-side
src/app/core/components/
anis-
nav.component.css
→
src/app/core/components/nav.component.css
View file @
c92189a6
File moved
src/app/core/components/
anis-
nav.component.html
→
src/app/core/components/nav.component.html
View file @
c92189a6
<nav
class=
"navbar navbar-light bg-light navbar-expand-md fixed-top border-bottom"
>
<!-- Logo -->
<a
href=
"/"
class=
"navbar-brand"
>
<img
src=
"../assets/cesam_anis80.png"
alt=
"CeSAM logo"
/>
<img
src=
"../assets/cesam_anis80.png"
alt=
"CeSAM logo"
/>
</a>
<!-- Right Navigation -->
...
...
@@ -18,10 +18,12 @@
</a>
</li>
</ul>
<button
*ngIf=
"!isAuthenticated"
class=
"btn btn-outline-success my-2 my-sm-0"
routerLink=
"/login"
>
<button
*ngIf=
"!isAuthenticated"
class=
"btn btn-outline-success my-2 my-sm-0"
id=
"button-sign-in"
routerLink=
"/login"
>
Sign In / Register
</button>
<span
*ngIf=
"isAuthenticated"
dropdown
>
<span
*ngIf=
"isAuthenticated"
id=
"dropdown-menu"
dropdown
>
<button
id=
"button-basic"
dropdownToggle
type=
"button"
class=
"btn btn-light"
aria-controls=
"dropdown-basic"
>
<span
class=
"fa-stack theme-color"
>
<span
class=
"fas fa-circle fa-2x"
></span>
...
...
@@ -32,7 +34,7 @@
</button>
<ul
id=
"basic-link-dropdown"
*dropdownMenu
class=
"dropdown-menu dropdown-menu-right dropdown-up"
role=
"menu"
aria-labelledby=
"basic-link"
>
<li
role=
"menuitem"
>
<li
id=
"li-email"
role=
"menuitem"
>
<span
class=
"dropdown-item font-italic"
>
{{ loginToken.email }}
</span>
</li>
<li
class=
"divider dropdown-divider"
></li>
...
...
src/app/core/components/nav.component.spec.ts
0 → 100644
View file @
c92189a6
import
{
async
,
ComponentFixture
,
TestBed
}
from
'
@angular/core/testing
'
;
import
{
NavComponent
}
from
'
./nav.component
'
;
describe
(
'
Component: NavComponent
'
,
()
=>
{
let
component
:
NavComponent
;
let
fixture
:
ComponentFixture
<
NavComponent
>
;
beforeEach
(()
=>
{
TestBed
.
configureTestingModule
({
declarations
:
[
NavComponent
]
});
fixture
=
TestBed
.
createComponent
(
NavComponent
);
component
=
fixture
.
componentInstance
;
});
it
(
'
should create the component
'
,
()
=>
{
expect
(
component
).
toBeTruthy
();
});
it
(
'
should display the Sign In button if no user logged in
'
,
()
=>
{
component
.
isAuthenticated
=
false
;
fixture
.
detectChanges
();
const
template
=
fixture
.
nativeElement
;
expect
(
template
.
querySelector
(
'
#button-sign-in
'
)).
toBeTruthy
();
});
it
(
'
should not display the dropdown menu if no user logged in
'
,
()
=>
{
component
.
isAuthenticated
=
false
;
fixture
.
detectChanges
();
const
template
=
fixture
.
nativeElement
;
expect
(
template
.
querySelector
(
'
#dropdown-menu
'
)).
toBeFalsy
();
});
it
(
'
should display the dropdown menu if user logged in
'
,
()
=>
{
component
.
isAuthenticated
=
true
;
fixture
.
detectChanges
();
const
template
=
fixture
.
nativeElement
;
expect
(
template
.
querySelector
(
'
#dropdown-menu
'
)).
toBeTruthy
();
});
it
(
'
should not display the Sign In button if user logged in
'
,
()
=>
{
component
.
isAuthenticated
=
true
;
fixture
.
detectChanges
();
const
template
=
fixture
.
nativeElement
;
expect
(
template
.
querySelector
(
'
#button-sign-in
'
)).
toBeFalsy
();
});
});
src/app/core/components/
anis-
nav.component.ts
→
src/app/core/components/nav.component.ts
View file @
c92189a6
...
...
@@ -3,12 +3,12 @@ import { Component, Input, Output, EventEmitter, ChangeDetectionStrategy } from
import
{
LoginToken
}
from
'
../../login/store/model
'
;
@
Component
({
selector
:
'
app-
anis-
nav
'
,
templateUrl
:
'
anis-
nav.component.html
'
,
styleUrls
:
[
'
anis-
nav.component.css
'
],
selector
:
'
app-nav
'
,
templateUrl
:
'
nav.component.html
'
,
styleUrls
:
[
'
nav.component.css
'
],
changeDetection
:
ChangeDetectionStrategy
.
OnPush
})
export
class
Anis
NavComponent
{
export
class
NavComponent
{
@
Input
()
isAuthenticated
:
boolean
;
@
Input
()
loginToken
:
LoginToken
;
@
Output
()
logout
:
EventEmitter
<
{}
>
=
new
EventEmitter
();
...
...
src/app/core/containers/app.component.html
View file @
c92189a6
<header>
<app-
anis-
nav
[isAuthenticated]=
"isAuthenticated | async"
[loginToken]=
"loginToken | async"
(logout)=
"logout()"
>
</app-
anis-
nav>
<app-nav
[isAuthenticated]=
"isAuthenticated | async"
[loginToken]=
"loginToken | async"
(logout)=
"logout()"
>
</app-nav>
</header>
<main
role=
"main"
class=
"container-fluid pb-4"
>
<router-outlet></router-outlet>
...
...
src/app/core/containers/not-found-page.component.spec.ts
View file @
c92189a6
...
...
@@ -2,24 +2,19 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import
{
NotFoundPageComponent
}
from
'
./not-found-page.component
'
;
describe
(
'
NotFoundPageComponent
'
,
()
=>
{
let
component
:
NotFoundPageComponent
;
let
fixture
:
ComponentFixture
<
NotFoundPageComponent
>
;
describe
(
'
Component:
NotFoundPageComponent
'
,
()
=>
{
let
component
:
NotFoundPageComponent
;
let
fixture
:
ComponentFixture
<
NotFoundPageComponent
>
;
beforeEach
(
async
(()
=>
{
TestBed
.
configureTestingModule
({
declarations
:
[
NotFoundPageComponent
]
})
.
compileComponents
();
}));
beforeEach
(()
=>
{
TestBed
.
configureTestingModule
({
declarations
:
[
NotFoundPageComponent
]
});
fixture
=
TestBed
.
createComponent
(
NotFoundPageComponent
);
component
=
fixture
.
componentInstance
;
});
beforeEach
(()
=>
{
fixture
=
TestBed
.
createComponent
(
NotFoundPageComponent
);
component
=
fixture
.
componentInstance
;
fixture
.
detectChanges
();
});
it
(
'
should create
'
,
()
=>
{
expect
(
component
).
toBeTruthy
();
});
it
(
'
should create the component
'
,
()
=>
{
expect
(
component
).
toBeTruthy
();
});
});
src/app/core/core.module.ts
View file @
c92189a6
...
...
@@ -6,13 +6,13 @@ import { CollapseModule, BsDropdownModule } from 'ngx-bootstrap';
import
{
AppComponent
}
from
'
./containers/app.component
'
;
import
{
NotFoundPageComponent
}
from
'
./containers/not-found-page.component
'
;
import
{
Anis
NavComponent
}
from
'
./components/
anis-
nav.component
'
;
import
{
NavComponent
}
from
'
./components/nav.component
'
;
import
{
throwIfAlreadyLoaded
}
from
'
./module-import-guard
'
;
export
const
COMPONENTS
=
[
AppComponent
,
NotFoundPageComponent
,
Anis
NavComponent
NavComponent
];
@
NgModule
({
...
...
src/app/detail/components/object-display.component.spec.ts
0 → 100644
View file @
c92189a6
import
{
async
,
ComponentFixture
,
TestBed
}
from
'
@angular/core/testing
'
;
import
{
ObjectDisplayComponent
}
from
'
./object-display.component
'
;
describe
(
'
Component: ObjectDisplayComponent
'
,
()
=>
{
it
(
'
#getAttributesVisible() should filter and sort #attributeList
'
,
()
=>
{
const
component
=
new
ObjectDisplayComponent
();
component
.
attributeList
=
[
{
id
:
1
,
name
:
'
id
'
,
table_name
:
'
obs_cat
'
,
label
:
'
id
'
,
form_label
:
'
id
'
,
description
:
null
,
output_display
:
10
,
criteria_display
:
10
,
search_flag
:
'
ID
'
,
search_type
:
'
between
'
,
type
:
'
integer
'
,
operator
:
'
eq
'
,
min
:
null
,
max
:
null
,
placeholder_min
:
null
,
placeholder_max
:
null
,
uri_action
:
null
,
renderer
:
'
detail-btn
'
,
display_detail
:
10
,
selected
:
true
,
order_by
:
false
,
order_display
:
10
,
detail
:
false
,
renderer_detail
:
null
,
options
:
null
,
vo_utype
:
null
,
vo_ucd
:
null
,
vo_unit
:
null
,
vo_description
:
null
,
vo_datatype
:
null
,
vo_size
:
0
,
id_criteria_family
:
1
,
id_output_category
:
1
},
{
id
:
2
,
name
:
'
ra
'
,
table_name
:
'
obs_cat
'
,
label
:
'
ra
'
,
form_label
:
'
ra
'
,
description
:
null
,
output_display
:
20
,
criteria_display
:
20
,
search_flag
:
null
,
search_type
:
'
between
'
,
type
:
'
decimal
'
,
operator
:
null
,
min
:
null
,
max
:
null
,
placeholder_min
:
null
,
placeholder_max
:
null
,
uri_action
:
null
,
renderer
:
null
,
display_detail
:
20
,
selected
:
true
,
order_by
:
false
,
order_display
:
20
,
detail
:
true
,
renderer_detail
:
null
,
options
:
null
,
vo_utype
:
null
,
vo_ucd
:
null
,
vo_unit
:
null
,
vo_description
:
null
,
vo_datatype
:
null
,
vo_size
:
0
,
id_criteria_family
:
1
,
id_output_category
:
1
},
{
id
:
3
,
name
:
'
dec
'
,
table_name
:
'
obs_cat
'
,
label
:
'
dec
'
,
form_label
:
'
dec
'
,
description
:
null
,
output_display
:
30
,
criteria_display
:
30
,
search_flag
:
null
,
search_type
:
'
between
'
,
type
:
'
decimal
'
,
operator
:
null
,
min
:
null
,
max
:
null
,
placeholder_min
:
null
,
placeholder_max
:
null
,
uri_action
:
null
,
renderer
:
null
,
display_detail
:
10
,
selected
:
true
,
order_by
:
false
,
order_display
:
30
,
detail
:
true
,
renderer_detail
:
null
,
options
:
null
,
vo_utype
:
null
,
vo_ucd
:
null
,
vo_unit
:
null
,
vo_description
:
null
,
vo_datatype
:
null
,
vo_size
:
0
,
id_criteria_family
:
1
,
id_output_category
:
1
}
];
const
expectedAttributeList
=
[
{
id
:
3
,
name
:
'
dec
'
,
table_name
:
'
obs_cat
'
,
label
:
'
dec
'
,
form_label
:
'
dec
'
,
description
:
null
,
output_display
:
30
,
criteria_display
:
30
,
search_flag
:
null
,
search_type
:
'
between
'
,
type
:
'
decimal
'
,
operator
:
null
,
min
:
null
,
max
:
null
,
placeholder_min
:
null
,
placeholder_max
:
null
,
uri_action
:
null
,
renderer
:
null
,
display_detail
:
10
,
selected
:
true
,
order_by
:
false
,
order_display
:
30
,
detail
:
true
,
renderer_detail
:
null
,
options
:
null
,
vo_utype
:
null
,
vo_ucd
:
null
,
vo_unit
:
null
,
vo_description
:
null
,
vo_datatype
:
null
,
vo_size
:
0
,
id_criteria_family
:
1
,
id_output_category
:
1
},
{
id
:
2
,
name
:
'
ra
'
,
table_name
:
'
obs_cat
'
,
label
:
'
ra
'
,
form_label
:
'
ra
'
,
description
:
null
,
output_display
:
20
,
criteria_display
:
20
,
search_flag
:
null
,
search_type
:
'
between
'
,
type
:
'
decimal
'
,
operator
:
null
,
min
:
null
,
max
:
null
,
placeholder_min
:
null
,
placeholder_max
:
null
,
uri_action
:
null
,
renderer
:
null
,
display_detail
:
20
,
selected
:
true
,
order_by
:
false
,
order_display
:
20
,
detail
:
true
,
renderer_detail
:
null
,
options
:
null
,
vo_utype
:
null
,
vo_ucd
:
null
,
vo_unit
:
null
,
vo_description
:
null
,
vo_datatype
:
null
,
vo_size
:
0
,
id_criteria_family
:
1
,
id_output_category
:
1
}
];
const
filteredAttributeList
=
component
.
getAttributesVisible
();
expect
(
filteredAttributeList
).
toEqual
(
expectedAttributeList
);
});
});
src/app/detail/containers/detail.component.html
View file @
c92189a6
<div
class=
"row text-center mb-5"
>
<div
class=
"col"
>
<h1>
Object detail
</h1>
<div
class=
"mx-5 px-5"
>
<div
class=
"row text-center mb-5"
>
<div
class=
"col"
>
<h1>
Object detail
</h1>
</div>
</div>
</div
>
<div
*ngIf=
"objectIsLoading | async"
class=
"row justify-content-center mt-5"
>
<span
class=
"
fas fa-circle-notch fa-spin fa-3x"
>
</span>
<
span
class=
"sr-only"
>
Loading...
</span
>
</div
>
<div
*ngIf=
"objectIsLoaded
|
async"
>
<
app-object-display
[attributeList]=
"attributeList | async"
[object]=
"object | async"
></app-object-display
>
</div
>
<div
*ngIf=
"!(pristine | async)"
class=
"row mt-5 justify-content-between
"
>
<div
class=
"col
"
>
<
butto
n
(
cl
ick)=
"goBackToResult()"
class=
"btn btn-outline-secondary"
>
<
span
class=
"fa fa-backward"
></span>
Back to search results
</
button
>
<div
*ngIf=
"objectIsLoading | async"
id=
"div-spinner"
class=
"row justify-content-center mt-5"
>
<span
class=
"fas fa-circle-notch fa-spin fa-3x"
></span
>
<span
class=
"
sr-only"
>
Loading...
</span>
<
/div
>
<div
*ngIf=
"objectIsLoaded | async"
>
<app-object-display
[attributeList]=
"attributeList | async"
[object]=
"object
|
async"
>
</app-object-display>
<
/div
>
<div
*ngIf=
"!(pristine | async)"
class=
"row mt-5 justify-content-between"
>
<div
class=
"col
"
>
<button
(click)=
"goBackToResult()"
class=
"btn btn-outline-secondary
"
>
<
spa
n
cl
ass=
"fa fa-backward"
></span>
Back to search results
<
/button>
</
div
>
</div>
</div>
\ No newline at end of file
src/app/detail/store/detail.effects.ts
View file @
c92189a6
...
...
@@ -90,7 +90,6 @@ export class DetailEffects {
const
objectSelected
=
state
.
router
.
state
.
params
.
objectSelected
;
const
attributes
=
state
.
detail
.
attributeList
;
const
attributeCriterionId
=
attributes
.
find
(
a
=>
a
.
search_flag
===
'
ID
'
);
console
.
log
(
attributes
);
const
attributesOutputList
=
attributes
.
filter
(
a
=>
a
.
detail
).
map
(
a
=>
a
.
id
);
return
this
.
detailService
.
retrieveObject
(
datasetName
,
attributeCriterionId
.
id
,
objectSelected
,
attributesOutputList
).
pipe
(
map
((
object
:
any
[])
=>
new
detailActions
.
RetrieveObjectSuccessAction
(
object
[
0
])),
...
...
src/app/login/components/account-benefits.component.spec.ts
View file @
c92189a6
...
...
@@ -2,24 +2,19 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import
{
AccountBenefitsComponent
}
from
'
./account-benefits.component
'
;
describe
(
'
AccountBenefitsComponent
'
,
()
=>
{
let
component
:
AccountBenefitsComponent
;
let
fixture
:
ComponentFixture
<
AccountBenefitsComponent
>
;
describe
(
'
Component:
AccountBenefitsComponent
'
,
()
=>
{
let
component
:
AccountBenefitsComponent
;
let
fixture
:
ComponentFixture
<
AccountBenefitsComponent
>
;
beforeEach
(
async
(()
=>
{
TestBed
.
configureTestingModule
({
declarations
:
[
AccountBenefitsComponent
]
})
.
compileComponents
();
}));
beforeEach
(()
=>
{
TestBed
.
configureTestingModule
({
declarations
:
[
AccountBenefitsComponent
]
});
fixture
=
TestBed
.
createComponent
(
AccountBenefitsComponent
);
component
=
fixture
.
componentInstance
;
});
beforeEach
(()
=>
{
fixture
=
TestBed
.
createComponent
(
AccountBenefitsComponent
);
component
=
fixture
.
componentInstance
;
fixture
.
detectChanges
();
});
it
(
'
should create
'
,
()
=>
{
expect
(
component
).
toBeTruthy
();
});
it
(
'
should create the component
'
,
()
=>
{
expect
(
component
).
toBeTruthy
();
});
});
src/app/search/store/search.service.spec.ts
View file @
c92189a6
import
{
async
,
ComponentFixture
,
TestBed
}
from
'
@angular/core/testing
'
;
import
{
SearchService
}
from
'
./search.service
'
;
import
{
HttpErrorResponse
}
from
'
@angular/common/http
'
;
describe
(
'
SearchService
'
,
()
=>
{
let
searchService
:
SearchService
;
let
httpClientSpy
:
{
get
:
jasmine
.
Spy
};
beforeEach
(()
=>
{
httpClientSpy
=
jasmine
.
createSpyObj
(
'
HttpClient
'
,
[
'
get
'
]);
searchService
=
new
SearchService
(
httpClientSpy
as
any
);
});
it
(
'
should return an error when the server returns a 404
'
,
()
=>
{
const
errorResponse
=
new
HttpErrorResponse
({
error
:
'
test 404 error
'
,
status
:
404
,
statusText
:
'
Not Found
'
});
httpClientSpy
.
get
.
and
.
returnValue
(
errorResponse
);
searchService
.
retrieveMeta
(
'
obs_cat?a=1;2;3
'
).
subscribe
(
meta
=>
fail
(
'
expected an error, not metadata
'
),
error
=>
expect
(
error
.
message
).
toContain
(
'
test 404 error
'
)
);
});
});
// import { async, ComponentFixture, TestBed } from '@angular/core/testing';
// import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
// import { HttpClient, HttpResponse } from '@angular/common/http';
// import { SearchService } from './search.service';
// import { SearchMeta } from './model';
// describe('SearchService', () => {
// let searchService: SearchService;
// let httpClient: HttpClient;
// let httpTestingController: HttpTestingController;
// beforeEach(() => {
// TestBed.configureTestingModule({
// // Import the HttpClient mocking services
// imports: [HttpClientTestingModule],
// // Provide the service-under-test and its dependencies
// providers: [SearchService]
// });
// });
// // Inject the http, test controller, and service-under-test
// // as they will be referenced by each test.
// httpClient = TestBed.get(HttpClient);
// httpTestingController = TestBed.get(HttpTestingController);
// searchService = TestBed.get(SearchService);
// afterEach(() => {
// // After every test, assert that there are no more pending requests.
// httpTestingController.verify();
// });
// /// SeroService method tests begin ///
// describe('#getMeta', () => {
// let query = 'query';
// let expectedMeta: SearchMeta;
// beforeEach(() => {
// searchService = TestBed.get(SearchService);
// query = 'query';
// expectedMeta = {
// dataset_selected: 'obs_cat',
// attributes_selected: [
// { name: 'id', label: 'ID' },
// { name: 'ra', label: 'RA' },
// { name: 'dec', label: 'DEC' }
// ],
// total_items: 10
// };
// });
// // it('should return expected meta (called once)', () => {
// // searchService.retrieveMeta(query).subscribe(
// // meta => expect(meta).toEqual(expectedMeta, 'should return expected meta'),
// // fail
// // );
// // SearchService should have made one request to GET meta from expected URL
// // const url = searchService.API_PATH + '/search/' + searchService.instanceName + '/meta/' + query;
// // const req = httpTestingController.expectOne(url);
// // expect(req.request.method).toEqual('GET');
// // Respond with the mock meta
// // req.flush(expectedMeta);
// // });
// });
// });
src/app/search/store/search.service.ts
View file @
c92189a6
...
...
@@ -6,8 +6,8 @@ import { environment } from '../../../environments/environment';
@
Injectable
()
export
class
SearchService
{
private
API_PATH
:
string
=
environment
.
apiUrl
;
private
instanceName
:
string
=
environment
.
instanceName
;
API_PATH
:
string
=
environment
.
apiUrl
;
instanceName
:
string
=
environment
.
instanceName
;
constructor
(
private
http
:
HttpClient
)
{
}
...
...
src/app/static/home.component.spec.ts
View file @
c92189a6
...
...
@@ -2,24 +2,19 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import
{
HomeComponent
}
from
'
./home.component
'
;
describe
(
'
HomeComponent
'
,
()
=>
{
let
component
:
HomeComponent
;
let
fixture
:
ComponentFixture
<
HomeComponent
>
;
describe
(
'
Component:
HomeComponent
'
,
()
=>
{
let
component
:
HomeComponent
;
let
fixture
:
ComponentFixture
<
HomeComponent
>
;
beforeEach
(
async
(()
=>
{
TestBed
.
configureTestingModule
({
declarations
:
[
HomeComponent
]
})
.
compileComponents
();
}));
beforeEach
(()
=>
{
TestBed
.
configureTestingModule
({
declarations
:
[
HomeComponent
]
});
fixture
=
TestBed
.
createComponent
(
HomeComponent
);
component
=
fixture
.
componentInstance
;
});
beforeEach
(()
=>
{
fixture
=
TestBed
.
createComponent
(
HomeComponent
);
component
=
fixture
.
componentInstance
;
fixture
.
detectChanges
();
});
it
(
'
should create
'
,
()
=>
{
expect
(
component
).
toBeTruthy
();
});