Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
boco-frontend
Manage
Activity
Members
Labels
Plan
Issues
21
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
idatt2106_2022_02
boco-frontend
Commits
09b037f5
Commit
09b037f5
authored
2 years ago
by
Sander August Heggland Schrader
Browse files
Options
Downloads
Patches
Plain Diff
Added iteminfo tests
parent
aded9ccd
No related branches found
Branches containing commit
No related tags found
1 merge request
!156
Testing2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/components/RentingComponents/ItemInfo.vue
+6
-1
6 additions, 1 deletion
src/components/RentingComponents/ItemInfo.vue
tests/unit/component-tests/renting-compnents-tests/item-info.spec.js
+15
-1
15 additions, 1 deletion
...component-tests/renting-compnents-tests/item-info.spec.js
with
21 additions
and
2 deletions
src/components/RentingComponents/ItemInfo.vue
+
6
−
1
View file @
09b037f5
...
...
@@ -75,6 +75,7 @@
<p
class=
"text-xl font-semibold text-gray-900"
>
Total pris:
{{
totPrice
}}
kr
</p>
<p
v-if=
"error"
style=
"color: red;"
>
Dato er påkrevd
</p>
<button
class=
"px-4 py-2 font-medium tracking-wide text-white capitalize transition-colors duration-200 transform bg-gray-500 rounded-md focus:outline-none focus:ring focus:ring-opacity-80"
v-bind:class=
"
{ colorChange: allowForRent }"
...
...
@@ -107,6 +108,7 @@ export default {
data
()
{
return
{
confirm
:
false
,
error
:
false
,
item
:
{
listingID
:
0
,
title
:
""
,
...
...
@@ -153,6 +155,8 @@ export default {
if
(
this
.
allowForRent
)
{
this
.
confirm
=
true
;
this
.
createPushItem
();
}
else
{
this
.
error
=
true
;
}
},
createPushItem
()
{
...
...
@@ -212,11 +216,12 @@ export default {
this
.
rentingEndDate
=
dateOfsomthing
.
endDate
;
this
.
calculateTotPrice
();
this
.
allowForRent
=
true
;
this
.
error
=
false
;
}
},
calculateTotPrice
()
{
let
amountOfDays
=
this
.
rentingEndDate
-
this
.
rentingStartDate
;
amountOfDays
=
amountOfDays
/
86400000
;
amountOfDays
=
Math
.
ceil
(
amountOfDays
/
86400000
)
;
this
.
totPrice
=
this
.
item
.
pricePerDay
*
amountOfDays
;
},
},
...
...
This diff is collapsed.
Click to expand it.
tests/unit/component-tests/renting-compnents-tests/item-info.spec.js
+
15
−
1
View file @
09b037f5
...
...
@@ -64,17 +64,21 @@ describe("ItemInfo component", () => {
})
it
(
"
Check that button cannot be clicked if date is not selected
"
,
async
()
=>
{
const
jestCreatePushItemMock
=
jest
.
fn
();
wrapper
.
vm
.
createPushItem
=
jestCreatePushItemMock
;
// Click rent button
wrapper
.
find
(
"
button
"
).
trigger
(
"
click
"
);
// wait a tick
await
wrapper
.
vm
.
$nextTick
();
// Check that jestMock was not clicked
expect
(
mockMethod
).
toHaveBeenCalledTimes
(
1
);
expect
(
mockCreatePush
).
toHaveBeenCalledTimes
(
0
);
// Check that the last p contains "Dato er påkrevd"
expect
(
wrapper
.
findAll
(
"
p
"
)[
wrapper
.
findAll
(
"
p
"
).
length
-
1
].
text
()).
toBe
(
"
Dato er påkrevd
"
);
})
it
(
"
Check that send to confirm works
"
,
async
()
=>
{
...
...
@@ -91,5 +95,15 @@ describe("ItemInfo component", () => {
expect
(
mockCreatePush
).
toHaveBeenCalledTimes
(
1
);
})
it
(
"
Test that price calculation works
"
,
async
()
=>
{
wrapper
.
vm
.
setDate
({
startDate
:
new
Date
(
"
2022-01-01
"
),
endDate
:
new
Date
(
"
2022-01-03
"
),
})
// wait a tick
await
wrapper
.
vm
.
$nextTick
();
await
wrapper
.
vm
.
$nextTick
();
expect
(
wrapper
.
vm
.
totPrice
).
toBe
(
200
);
})
});
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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