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
bf803465
Commit
bf803465
authored
Oct 10, 2019
by
Tifenn Guillas
Browse files
WIP: add tests
parent
d14453c8
Changes
5
Show whitespace changes
Inline
Side-by-side
src/app/search/components/criteria/criteria-by-family.component.html
View file @
bf803465
...
...
@@ -92,7 +92,7 @@
[operator]=
"attribute.operator"
[label]=
"attribute.form_label"
[criterion]=
"getCriterion(attribute.id)"
(add)=
"add($event)"
(add
Criterion
)=
"add($event)"
(deleteCriterion)=
"delete($event)"
>
</app-between-date>
</div>
...
...
src/app/search/components/criteria/search-type/between-date.component.html
View file @
bf803465
...
...
@@ -12,7 +12,7 @@
</div>
<div
class=
"col-2 text-center"
>
<button
class=
"btn btn-outline-success"
*ngIf=
"!field.disabled"
[hidden]=
"!field.value"
(click)=
"
addCriterion
()"
>
(click)=
"
emitAdd
()"
>
<span
class=
"fas fa-plus fa-fw"
></span>
</button>
<button
class=
"btn btn-outline-danger"
*ngIf=
"field.disabled"
(click)=
"emitDelete()"
>
...
...
src/app/search/components/criteria/search-type/between-date.component.spec.ts
View file @
bf803465
import
{
async
,
ComponentFixture
,
TestBed
}
from
'
@angular/core/testing
'
;
import
{
BsDatepickerModule
}
from
'
ngx-bootstrap
'
;
import
{
FormsModule
,
ReactiveFormsModule
}
from
'
@angular/forms
'
;
import
{
FormsModule
,
ReactiveFormsModule
,
FormControl
}
from
'
@angular/forms
'
;
import
{
BetweenDateComponent
}
from
'
./between-date.component
'
;
import
{
Criterion
,
BetweenCriterion
}
from
'
../../../store/model
'
;
import
{
BetweenCriterion
}
from
'
../../../store/model
'
;
describe
(
'
[Search][Criteria][SearchType] Component: BetweenDateComponent
'
,
()
=>
{
let
component
:
BetweenDateComponent
;
...
...
@@ -45,15 +45,19 @@ describe('[Search][Criteria][SearchType] Component: BetweenDateComponent', () =>
expect
(
component
.
field
.
disabled
).
toBeTruthy
();
});
// it('raises the add criterion event when clicked', () => {
// component.id = 123;
// component.deleteCriterion.subscribe((event: number) => expect(event).toEqual(component.id));
// component.emitDelete();
// });
it
(
'
raises the add criterion event when clicked
'
,
()
=>
{
component
.
id
=
1
;
const
dateMin
=
'
2019-02-08
'
;
const
dateMax
=
'
2019-02-17
'
;
component
.
field
=
new
FormControl
([
new
Date
(
dateMin
),
new
Date
(
dateMax
)]);
const
expectedCriterion
=
new
BetweenCriterion
(
component
.
id
,
dateMin
,
dateMax
);
component
.
addCriterion
.
subscribe
((
event
:
BetweenCriterion
)
=>
expect
(
event
).
toEqual
(
expectedCriterion
));
component
.
emitAdd
();
});
//
it('raises the delete criterion event when clicked', () => {
//
component.id = 1
23
;
//
component.deleteCriterion.subscribe((event: number) => expect(event).toEqual(
component.id
));
//
component.emitDelete();
//
});
it
(
'
raises the delete criterion event when clicked
'
,
()
=>
{
component
.
id
=
1
;
component
.
deleteCriterion
.
subscribe
((
event
:
number
)
=>
expect
(
event
).
toEqual
(
1
));
component
.
emitDelete
();
});
});
src/app/search/components/criteria/search-type/between-date.component.ts
View file @
bf803465
...
...
@@ -16,20 +16,19 @@ export class BetweenDateComponent {
set
criterion
(
criterion
:
Criterion
)
{
this
.
getDefault
(
criterion
);
}
@
Output
()
add
:
EventEmitter
<
BetweenCriterion
>
=
new
EventEmitter
();
@
Output
()
add
Criterion
:
EventEmitter
<
BetweenCriterion
>
=
new
EventEmitter
();
@
Output
()
deleteCriterion
:
EventEmitter
<
number
>
=
new
EventEmitter
();
field
=
new
FormControl
(
''
);
addCriterion
():
void
{
console
.
log
(
this
.
field
.
value
);
emitAdd
():
void
{
const
dateMin
=
this
.
getDateString
(
this
.
field
.
value
[
0
]);
const
dateMax
=
this
.
getDateString
(
this
.
field
.
value
[
1
]);
const
fd
=
new
BetweenCriterion
(
this
.
id
,
dateMin
,
dateMax
);
this
.
add
.
emit
(
fd
);
this
.
add
Criterion
.
emit
(
fd
);
}
emitDelete
()
{
emitDelete
()
:
void
{
this
.
deleteCriterion
.
emit
(
this
.
id
);
}
...
...
src/app/search/store/model/between-criterion.model.spec.ts
0 → 100644
View file @
bf803465
import
{
BetweenCriterion
}
from
'
./between-criterion.model
'
;
describe
(
'
[Search] Model: BetweenCriterion
'
,
()
=>
{
it
(
'
should print criterion correctly
'
,
()
=>
{
const
dateMin
=
'
2019-02-08
'
;
const
dateMax
=
'
2019-02-17
'
;
const
criterion
=
new
BetweenCriterion
(
1
,
dateMin
,
dateMax
);
const
expectedPrintedCriterion
=
'
∈ [
'
+
dateMin
+
'
;
'
+
dateMax
+
'
]
'
;
expect
(
criterion
.
printCriterion
()).
toEqual
(
expectedPrintedCriterion
);
const
criterionMin
=
new
BetweenCriterion
(
1
,
dateMin
,
''
);
const
expectedPrintedCriterionMin
=
'
>=
'
+
dateMin
;
expect
(
criterionMin
.
printCriterion
()).
toEqual
(
expectedPrintedCriterionMin
);
const
criterionMax
=
new
BetweenCriterion
(
1
,
''
,
dateMax
);
const
expectedPrintedCriterionMax
=
'
<=
'
+
dateMax
;
expect
(
criterionMax
.
printCriterion
()).
toEqual
(
expectedPrintedCriterionMax
);
});
it
(
'
should print criterion url string correctly
'
,
()
=>
{
const
id
=
1
;
const
dateMin
=
'
2019-02-08
'
;
const
dateMax
=
'
2019-02-17
'
;
const
criterion
=
new
BetweenCriterion
(
id
,
dateMin
,
dateMax
);
const
expectedPrintedCriterion
=
id
+
'
::bw::
'
+
dateMin
+
'
|
'
+
dateMax
;
expect
(
criterion
.
getCriterionStr
()).
toEqual
(
expectedPrintedCriterion
);
});
});
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment