This is the codeAbility Sharing Platform! Learn more about the
codeAbility Sharing Platform
.
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
codeAbility Sharing Platform
Manage
Activity
Members
Labels
Plan
Issues
43
Issue boards
Milestones
Wiki
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
development
sharing
codeAbility Sharing Platform
Commits
e276f690
Commit
e276f690
authored
3 years ago
by
Michael Breu
Browse files
Options
Downloads
Patches
Plain Diff
Fixing Tests
parent
7331835d
1 merge request
!62
created achievementService and separated some functionality out of...
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/test/javascript/spec/app/editorialPages/pages.component.spec.ts
+70
-35
70 additions, 35 deletions
...avascript/spec/app/editorialPages/pages.component.spec.ts
src/test/javascript/spec/helpers/mock-language.service.ts
+7
-1
7 additions, 1 deletion
src/test/javascript/spec/helpers/mock-language.service.ts
with
77 additions
and
36 deletions
src/test/javascript/spec/app/editorialPages/pages.component.spec.ts
+
70
−
35
View file @
e276f690
...
...
@@ -4,11 +4,11 @@ import { PagesComponent } from 'app/editorialPages/pages.component';
import
{
PagesService
}
from
'
app/shared/service/pages-service
'
;
import
{
ActivatedRoute
,
Router
,
RouterState
}
from
'
@angular/router
'
;
import
{
PagesMarkDownViewerComponent
}
from
'
app/editorialPages/markDownViewer/markDownViewer.component
'
;
import
{
MarkdownModule
,
MarkdownService
}
from
'
ngx-markdown
'
;
import
{
MarkdownComponent
,
MarkdownModule
,
MarkdownService
}
from
'
ngx-markdown
'
;
import
{
RouterTestingModule
}
from
'
@angular/router/testing
'
;
import
{
PagesResolve
}
from
'
app/editorialPages/pages.route
'
;
import
{
Location
}
from
'
@angular/common
'
;
import
{
of
,
Subject
}
from
'
rxjs
'
;
import
{
of
}
from
'
rxjs
'
;
import
{
By
}
from
'
@angular/platform-browser
'
;
import
{
TranslateService
}
from
'
@ngx-translate/core
'
;
...
...
@@ -18,6 +18,8 @@ describe('Component Tests', () => {
let
fixture
:
ComponentFixture
<
PagesComponent
>
;
let
compMD
:
PagesMarkDownViewerComponent
;
let
fixtureMD
:
ComponentFixture
<
PagesMarkDownViewerComponent
>
;
let
compMarkDown
:
MarkdownComponent
;
let
fixtureMarkDown
:
ComponentFixture
<
MarkdownComponent
>
;
let
pagesService
:
PagesService
;
let
router
:
Router
;
let
route
:
ActivatedRoute
;
...
...
@@ -28,29 +30,31 @@ describe('Component Tests', () => {
const
pagesTestRoutes
=
{
path
:
'
pages
'
,
children
:
[
{
path
:
"
**
"
,
// loadChildren: () => import('app/editorialPages/editorialPages.module').then(m => m.PagesModule),
resolve
:
{
pagePath
:
PagesResolve
,
},
component
:
PagesComponent
,
}
{
path
:
"
**
"
,
// loadChildren: () => import('app/editorialPages/editorialPages.module').then(m => m.PagesModule),
resolve
:
{
pagePath
:
PagesResolve
,
},
component
:
PagesComponent
,
}
]
}
}
TestBed
.
configureTestingModule
({
imports
:
[
GitsearchTestModule
,
MarkdownModule
.
forRoot
(),
RouterTestingModule
.
withRoutes
([
pagesTestRoutes
])],
declarations
:
[
PagesComponent
,
PagesMarkDownViewerComponent
],
providers
:
[
MarkdownService
,
{
providers
:
[
MarkdownService
,
{
provide
:
ActivatedRoute
,
useValue
:
{
url
:
of
([]),
data
:
of
({
pagePath
:
'
start
'
}),
params
:
of
({
id
:
123
}),
queryParams
:
of
([]),
outlet
:
"
Hello World
"
,
component
:
"
1
"
,
tagged
:
"
hello WORLD
"
}
}
],
})
useValue
:
{
url
:
of
([]),
data
:
of
({
pagePath
:
'
start
'
}),
params
:
of
({
id
:
123
}),
queryParams
:
of
([]),
outlet
:
"
Hello World
"
,
component
:
"
1
"
,
tagged
:
"
hello WORLD
"
}
}
],
})
.
overrideTemplate
(
PagesComponent
,
''
)
.
overrideTemplate
(
PagesMarkDownViewerComponent
,
''
)
.
compileComponents
();
...
...
@@ -58,35 +62,41 @@ describe('Component Tests', () => {
beforeEach
(()
=>
{
fixture
=
TestBed
.
createComponent
(
PagesComponent
);
/*
const translateService = fixture.debugElement.injector.get(TranslateService);
translateService.currentLang = "de";
spyOn(translateService, 'onLangChange').and.returnValue(of('de'));
*/
comp
=
fixture
.
componentInstance
;
fixtureMD
=
TestBed
.
createComponent
(
PagesMarkDownViewerComponent
);
compMD
=
fixtureMD
.
componentInstance
;
fixtureMarkDown
=
TestBed
.
createComponent
(
MarkdownComponent
);
compMarkDown
=
fixtureMarkDown
.
componentInstance
;
router
=
TestBed
.
get
(
Router
);
route
=
TestBed
.
get
(
ActivatedRoute
);
location
=
TestBed
.
get
(
Location
);
// router = fixture.debugElement.injector.get(Router);
// router = fixture.debugElement.injector.get(Router);
router
.
initialNavigation
();
pagesService
=
fixture
.
debugElement
.
injector
.
get
(
PagesService
);
});
it
(
'
check routing of pages component
'
,
fakeAsync
(()
=>
{
/** unfortunatelly very rudimentary :-(
* router.navigate does not trigger page observers
*/
/** unfortunatelly very rudimentary :-(
* router.navigate does not trigger page observers
*/
// GIVEN
const
translateService
=
fixture
.
debugElement
.
injector
.
get
(
TranslateService
);
translateService
.
currentLang
=
"
de
"
;
comp
.
ngOnInit
();
compMD
.
ngOnInit
();
router
.
navigate
([
'
pages/
d
e/start
'
]);
const
getPageSpy
=
spyOn
(
pagesService
,
'
getPage
'
).
and
.
callFake
((
pagePath
:
string
)
=>
{
return
of
(
{
path
:
pagePath
,
content
:
"
#head
\n
hello world
"
});
router
.
navigate
([
'
pages/e
n
/start
'
]);
const
getPageSpy
=
spyOn
(
pagesService
,
'
getPage
'
).
and
.
callFake
((
pagePath
:
string
)
=>
{
return
of
({
path
:
pagePath
,
content
:
"
#head
\n
hello world
"
});
});
tick
();
// WHEN,
compMD
.
path
=
"
/start
"
;
...
...
@@ -94,10 +104,35 @@ describe('Component Tests', () => {
fixtureMD
.
detectChanges
();
// THEN
expect
(
location
.
path
()).
toBe
(
"
/pages/
d
e/start
"
);
expect
(
location
.
path
()).
toBe
(
"
/pages/e
n
/start
"
);
expect
(
comp
.
pagePath
).
toBe
(
"
start
"
);
expect
(
compMD
.
page
.
path
).
toBe
(
'
de/start
'
);
expect
(
compMD
.
page
.
path
).
toBe
(
'
en/start
'
);
}));
/*
it('check markdown generation', fakeAsync(() => {
// GIVEN
const getPageSpy = spyOn(pagesService, 'getPage').and.callFake((pagePath: string) => {
return of({ path: pagePath, content: "#head\n hello world" });
});
compMD.ngOnInit();
tick();
// WHEN,
compMD.path = "/start";
fixtureMD.detectChanges();
compMarkDown.data = compMD.page.content;
fixtureMarkDown.detectChanges;
let nativeElem = fixtureMarkDown.debugElement.nativeElement;
let h1 = fixtureMarkDown.debugElement.query(By.css("h1"))
// THEN
}));
*/
});
});
})
This diff is collapsed.
Click to expand it.
src/test/javascript/spec/helpers/mock-language.service.ts
+
7
−
1
View file @
e276f690
...
...
@@ -3,6 +3,7 @@ import { JhiLanguageService } from 'ng-jhipster';
import
{
SpyObject
}
from
'
./spyobject
'
;
import
{
TranslateService
}
from
'
@ngx-translate/core
'
;
import
{
of
}
from
'
rxjs
'
;
export
class
MockLanguageService
extends
SpyObject
{
getCurrentLanguageSpy
:
Spy
;
...
...
@@ -16,8 +17,13 @@ export class MockLanguageService extends SpyObject {
export
class
MockTranslateService
extends
SpyObject
{
public
currentLang
=
"
en
"
;
public
onLangChange
=
of
(
'
en
'
);
// onLangChangeSpy: Spy;
constructor
()
{
super
(
TranslateService
);
// this.onLangChangeSpy = this.spy('onLangChange').and.returnValue(
// of('en'));
}
}
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