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 Monday, March 24th
Show more breadcrumbs
vtechworks
Dspace7 Angular
Commits
e9bff44b
Commit
e9bff44b
authored
6 years ago
by
Kristof De Langhe
Browse files
Options
Downloads
Patches
Plain Diff
59695: BrowseByStartsWithDate tests
parent
51242ecd
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/shared/browse-by/browse-by-starts-with/date/browse-by-starts-with-date.component.spec.ts
+128
-0
128 additions, 0 deletions
...ts-with/date/browse-by-starts-with-date.component.spec.ts
with
128 additions
and
0 deletions
src/app/shared/browse-by/browse-by-starts-with/date/browse-by-starts-with-date.component.spec.ts
0 → 100644
+
128
−
0
View file @
e9bff44b
import
{
BrowseByStartsWithDateComponent
}
from
'
./browse-by-starts-with-date.component
'
;
import
{
async
,
ComponentFixture
,
TestBed
}
from
'
@angular/core/testing
'
;
import
{
CommonModule
}
from
'
@angular/common
'
;
import
{
RouterTestingModule
}
from
'
@angular/router/testing
'
;
import
{
TranslateModule
}
from
'
@ngx-translate/core
'
;
import
{
NgbModule
}
from
'
@ng-bootstrap/ng-bootstrap
'
;
import
{
EnumKeysPipe
}
from
'
../../../utils/enum-keys-pipe
'
;
import
{
ActivatedRoute
,
Router
}
from
'
@angular/router
'
;
import
{
DebugElement
,
NO_ERRORS_SCHEMA
}
from
'
@angular/core
'
;
import
{
ActivatedRouteStub
}
from
'
../../../testing/active-router-stub
'
;
import
{
of
as
observableOf
}
from
'
rxjs/internal/observable/of
'
;
import
{
RouterStub
}
from
'
../../../testing/router-stub
'
;
import
{
By
}
from
'
@angular/platform-browser
'
;
describe
(
'
BrowseByStartsWithDateComponent
'
,
()
=>
{
let
comp
:
BrowseByStartsWithDateComponent
;
let
fixture
:
ComponentFixture
<
BrowseByStartsWithDateComponent
>
;
let
route
:
ActivatedRoute
;
let
router
:
Router
;
const
options
=
[
2019
,
2018
,
2017
,
2016
,
2015
];
const
activatedRouteStub
=
Object
.
assign
(
new
ActivatedRouteStub
(),
{
params
:
observableOf
({}),
queryParams
:
observableOf
({})
});
beforeEach
(
async
(()
=>
{
TestBed
.
configureTestingModule
({
imports
:
[
CommonModule
,
RouterTestingModule
.
withRoutes
([]),
TranslateModule
.
forRoot
(),
NgbModule
.
forRoot
()],
declarations
:
[
BrowseByStartsWithDateComponent
,
EnumKeysPipe
],
providers
:
[
{
provide
:
'
startsWithOptions
'
,
useValue
:
options
},
{
provide
:
ActivatedRoute
,
useValue
:
activatedRouteStub
},
{
provide
:
Router
,
useValue
:
new
RouterStub
()
}
],
schemas
:
[
NO_ERRORS_SCHEMA
]
}).
compileComponents
();
}));
beforeEach
(()
=>
{
fixture
=
TestBed
.
createComponent
(
BrowseByStartsWithDateComponent
);
comp
=
fixture
.
componentInstance
;
fixture
.
detectChanges
();
route
=
(
comp
as
any
).
route
;
router
=
(
comp
as
any
).
router
;
});
it
(
'
should create a FormGroup containing a startsWith FormControl
'
,
()
=>
{
expect
(
comp
.
formData
.
value
.
startsWith
).
toBeDefined
();
});
describe
(
'
when selecting the first option in the dropdown
'
,
()
=>
{
let
select
;
beforeEach
(()
=>
{
select
=
fixture
.
debugElement
.
query
(
By
.
css
(
'
select
'
)).
nativeElement
;
select
.
value
=
select
.
options
[
0
].
value
;
select
.
dispatchEvent
(
new
Event
(
'
change
'
));
fixture
.
detectChanges
();
});
it
(
'
should set startsWith to undefined
'
,
()
=>
{
expect
(
comp
.
startsWith
).
toBeUndefined
();
});
it
(
'
should not add a startsWith query parameter
'
,
()
=>
{
route
.
queryParams
.
subscribe
((
params
)
=>
{
expect
(
params
.
startsWith
).
toBeUndefined
();
});
});
});
describe
(
'
when selecting the second option in the dropdown
'
,
()
=>
{
let
select
;
let
input
;
const
expectedValue
=
''
+
options
[
0
];
const
extras
=
{
queryParams
:
Object
.
assign
({
startsWith
:
expectedValue
}),
queryParamsHandling
:
'
merge
'
};
beforeEach
(()
=>
{
select
=
fixture
.
debugElement
.
query
(
By
.
css
(
'
select
'
)).
nativeElement
;
input
=
fixture
.
debugElement
.
query
(
By
.
css
(
'
input
'
)).
nativeElement
;
select
.
value
=
select
.
options
[
1
].
value
;
select
.
dispatchEvent
(
new
Event
(
'
change
'
));
fixture
.
detectChanges
();
});
it
(
'
should set startsWith to the correct value
'
,
()
=>
{
expect
(
comp
.
startsWith
).
toEqual
(
expectedValue
);
});
it
(
'
should add a startsWith query parameter
'
,
()
=>
{
expect
(
router
.
navigate
).
toHaveBeenCalledWith
([],
extras
);
});
it
(
'
should automatically fill in the input field
'
,
()
=>
{
expect
(
input
.
value
).
toEqual
(
expectedValue
);
});
});
describe
(
'
when filling in the input form
'
,
()
=>
{
let
form
;
const
expectedValue
=
'
2015
'
;
const
extras
=
{
queryParams
:
Object
.
assign
({
startsWith
:
expectedValue
}),
queryParamsHandling
:
'
merge
'
};
beforeEach
(()
=>
{
form
=
fixture
.
debugElement
.
query
(
By
.
css
(
'
form
'
));
comp
.
formData
.
value
.
startsWith
=
expectedValue
;
form
.
triggerEventHandler
(
'
ngSubmit
'
,
null
);
fixture
.
detectChanges
();
});
it
(
'
should set startsWith to the correct value
'
,
()
=>
{
expect
(
comp
.
startsWith
).
toEqual
(
expectedValue
);
});
it
(
'
should add a startsWith query parameter
'
,
()
=>
{
expect
(
router
.
navigate
).
toHaveBeenCalledWith
([],
extras
);
});
});
});
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