Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
Dspace7 Angular
Manage
Activity
Members
Labels
Plan
Issues
42
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Admin message
code.vt.edu will be down for maintenance from 0530-0630 EDT Wednesday, March 26th
Show more breadcrumbs
vtechworks
Dspace7 Angular
Commits
c09010e1
Commit
c09010e1
authored
5 years ago
by
Giuseppe Digilio
Browse files
Options
Downloads
Patches
Plain Diff
Added test for TopLevelCommunityList Component
parent
b18cfcbd
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/app/+home-page/top-level-community-list/top-level-community-list.component.spec.ts
+161
-0
161 additions, 0 deletions
...community-list/top-level-community-list.component.spec.ts
with
161 additions
and
0 deletions
src/app/+home-page/top-level-community-list/top-level-community-list.component.spec.ts
0 → 100644
+
161
−
0
View file @
c09010e1
import
{
async
,
ComponentFixture
,
TestBed
}
from
'
@angular/core/testing
'
;
import
{
TranslateModule
}
from
'
@ngx-translate/core
'
;
import
{
NO_ERRORS_SCHEMA
}
from
'
@angular/core
'
;
import
{
RouterTestingModule
}
from
'
@angular/router/testing
'
;
import
{
NoopAnimationsModule
}
from
'
@angular/platform-browser/animations
'
;
import
{
By
}
from
'
@angular/platform-browser
'
;
import
{
NgbModule
}
from
'
@ng-bootstrap/ng-bootstrap
'
;
import
{
TopLevelCommunityListComponent
}
from
'
./top-level-community-list.component
'
;
import
{
Community
}
from
'
../../core/shared/community.model
'
;
import
{
PaginatedList
}
from
'
../../core/data/paginated-list
'
;
import
{
PageInfo
}
from
'
../../core/shared/page-info.model
'
;
import
{
SharedModule
}
from
'
../../shared/shared.module
'
;
import
{
createSuccessfulRemoteDataObject$
}
from
'
../../shared/testing/utils
'
;
import
{
FindListOptions
}
from
'
../../core/data/request.models
'
;
import
{
HostWindowService
}
from
'
../../shared/host-window.service
'
;
import
{
HostWindowServiceStub
}
from
'
../../shared/testing/host-window-service-stub
'
;
import
{
CommunityDataService
}
from
'
../../core/data/community-data.service
'
;
import
{
SelectableListService
}
from
'
../../shared/object-list/selectable-list/selectable-list.service
'
;
describe
(
'
TopLevelCommunityList Component
'
,
()
=>
{
let
comp
:
TopLevelCommunityListComponent
;
let
fixture
:
ComponentFixture
<
TopLevelCommunityListComponent
>
;
let
communityDataServiceStub
:
any
;
const
topCommList
=
[
Object
.
assign
(
new
Community
(),
{
id
:
'
123456789-1
'
,
metadata
:
{
'
dc.title
'
:
[
{
language
:
'
en_US
'
,
value
:
'
TopCommunity 1
'
}
]
}
}),
Object
.
assign
(
new
Community
(),
{
id
:
'
123456789-2
'
,
metadata
:
{
'
dc.title
'
:
[
{
language
:
'
en_US
'
,
value
:
'
TopCommunity 2
'
}
]
}
}),
Object
.
assign
(
new
Community
(),
{
id
:
'
123456789-3
'
,
metadata
:
{
'
dc.title
'
:
[
{
language
:
'
en_US
'
,
value
:
'
TopCommunity 3
'
}
]
}
}),
Object
.
assign
(
new
Community
(),
{
id
:
'
12345678942
'
,
metadata
:
{
'
dc.title
'
:
[
{
language
:
'
en_US
'
,
value
:
'
TopCommunity 4
'
}
]
}
}),
Object
.
assign
(
new
Community
(),
{
id
:
'
123456789-5
'
,
metadata
:
{
'
dc.title
'
:
[
{
language
:
'
en_US
'
,
value
:
'
TopCommunity 5
'
}
]
}
}),
Object
.
assign
(
new
Community
(),
{
id
:
'
123456789-6
'
,
metadata
:
{
'
dc.title
'
:
[
{
language
:
'
en_US
'
,
value
:
'
TopCommunity 6
'
}
]
}
}),
Object
.
assign
(
new
Community
(),
{
id
:
'
123456789-7
'
,
metadata
:
{
'
dc.title
'
:
[
{
language
:
'
en_US
'
,
value
:
'
TopCommunity 7
'
}
]
}
})
];
communityDataServiceStub
=
{
findTop
(
options
:
FindListOptions
=
{})
{
let
currentPage
=
options
.
currentPage
;
let
elementsPerPage
=
options
.
elementsPerPage
;
if
(
currentPage
===
undefined
)
{
currentPage
=
1
}
elementsPerPage
=
5
;
const
startPageIndex
=
(
currentPage
-
1
)
*
elementsPerPage
;
let
endPageIndex
=
(
currentPage
*
elementsPerPage
);
if
(
endPageIndex
>
topCommList
.
length
)
{
endPageIndex
=
topCommList
.
length
;
}
return
createSuccessfulRemoteDataObject
$
(
new
PaginatedList
(
new
PageInfo
(),
topCommList
.
slice
(
startPageIndex
,
endPageIndex
)));
}
};
beforeEach
(
async
(()
=>
{
TestBed
.
configureTestingModule
({
imports
:
[
TranslateModule
.
forRoot
(),
SharedModule
,
RouterTestingModule
.
withRoutes
([]),
NgbModule
.
forRoot
(),
NoopAnimationsModule
],
declarations
:
[
TopLevelCommunityListComponent
],
providers
:
[
{
provide
:
CommunityDataService
,
useValue
:
communityDataServiceStub
},
{
provide
:
HostWindowService
,
useValue
:
new
HostWindowServiceStub
(
0
)
},
{
provide
:
SelectableListService
,
useValue
:
{}
},
],
schemas
:
[
NO_ERRORS_SCHEMA
]
}).
compileComponents
();
}));
beforeEach
(()
=>
{
fixture
=
TestBed
.
createComponent
(
TopLevelCommunityListComponent
);
comp
=
fixture
.
componentInstance
;
fixture
.
detectChanges
();
});
it
(
'
should display a list of top-communities
'
,
()
=>
{
const
subComList
=
fixture
.
debugElement
.
queryAll
(
By
.
css
(
'
li
'
));
expect
(
subComList
.
length
).
toEqual
(
5
);
expect
(
subComList
[
0
].
nativeElement
.
textContent
).
toContain
(
'
TopCommunity 1
'
);
expect
(
subComList
[
1
].
nativeElement
.
textContent
).
toContain
(
'
TopCommunity 2
'
);
expect
(
subComList
[
2
].
nativeElement
.
textContent
).
toContain
(
'
TopCommunity 3
'
);
expect
(
subComList
[
3
].
nativeElement
.
textContent
).
toContain
(
'
TopCommunity 4
'
);
expect
(
subComList
[
4
].
nativeElement
.
textContent
).
toContain
(
'
TopCommunity 5
'
);
});
it
(
'
should update list of top-communities on pagination change
'
,
()
=>
{
const
pagination
=
Object
.
create
({
pagination
:{
id
:
comp
.
pageId
,
currentPage
:
2
,
pageSize
:
5
},
sort
:
{
field
:
'
dc.title
'
,
direction
:
'
ASC
'
}
});
comp
.
onPaginationChange
(
pagination
);
fixture
.
detectChanges
();
const
collList
=
fixture
.
debugElement
.
queryAll
(
By
.
css
(
'
li
'
));
expect
(
collList
.
length
).
toEqual
(
2
);
expect
(
collList
[
0
].
nativeElement
.
textContent
).
toContain
(
'
TopCommunity 6
'
);
expect
(
collList
[
1
].
nativeElement
.
textContent
).
toContain
(
'
TopCommunity 7
'
);
});
});
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