Skip to content
Snippets Groups Projects
Commit 09b037f5 authored by Sander August Heggland Schrader's avatar Sander August Heggland Schrader
Browse files

Added iteminfo tests

parent aded9ccd
Branches
No related tags found
1 merge request!156Testing2
...@@ -75,6 +75,7 @@ ...@@ -75,6 +75,7 @@
<p class="text-xl font-semibold text-gray-900"> <p class="text-xl font-semibold text-gray-900">
Total pris: {{ totPrice }} kr Total pris: {{ totPrice }} kr
</p> </p>
<p v-if="error" style="color: red;">Dato er påkrevd</p>
<button <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" 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 }" v-bind:class="{ colorChange: allowForRent }"
...@@ -107,6 +108,7 @@ export default { ...@@ -107,6 +108,7 @@ export default {
data() { data() {
return { return {
confirm: false, confirm: false,
error: false,
item: { item: {
listingID: 0, listingID: 0,
title: "", title: "",
...@@ -153,6 +155,8 @@ export default { ...@@ -153,6 +155,8 @@ export default {
if (this.allowForRent) { if (this.allowForRent) {
this.confirm = true; this.confirm = true;
this.createPushItem(); this.createPushItem();
} else {
this.error = true;
} }
}, },
createPushItem() { createPushItem() {
...@@ -212,11 +216,12 @@ export default { ...@@ -212,11 +216,12 @@ export default {
this.rentingEndDate = dateOfsomthing.endDate; this.rentingEndDate = dateOfsomthing.endDate;
this.calculateTotPrice(); this.calculateTotPrice();
this.allowForRent = true; this.allowForRent = true;
this.error = false;
} }
}, },
calculateTotPrice() { calculateTotPrice() {
let amountOfDays = this.rentingEndDate - this.rentingStartDate; let amountOfDays = this.rentingEndDate - this.rentingStartDate;
amountOfDays = amountOfDays / 86400000; amountOfDays = Math.ceil(amountOfDays / 86400000);
this.totPrice = this.item.pricePerDay * amountOfDays; this.totPrice = this.item.pricePerDay * amountOfDays;
}, },
}, },
......
...@@ -64,17 +64,21 @@ describe("ItemInfo component", () => { ...@@ -64,17 +64,21 @@ describe("ItemInfo component", () => {
}) })
it("Check that button cannot be clicked if date is not selected", async () => { it("Check that button cannot be clicked if date is not selected", async () => {
const jestCreatePushItemMock = jest.fn(); const jestCreatePushItemMock = jest.fn();
wrapper.vm.createPushItem = jestCreatePushItemMock; wrapper.vm.createPushItem = jestCreatePushItemMock;
// Click rent button // Click rent button
wrapper.find("button").trigger("click"); wrapper.find("button").trigger("click");
// wait a tick // wait a tick
await wrapper.vm.$nextTick(); await wrapper.vm.$nextTick();
// Check that jestMock was not clicked // Check that jestMock was not clicked
expect(mockMethod).toHaveBeenCalledTimes(1); expect(mockMethod).toHaveBeenCalledTimes(1);
expect(mockCreatePush).toHaveBeenCalledTimes(0); 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 () => { it("Check that send to confirm works", async () => {
...@@ -91,5 +95,15 @@ describe("ItemInfo component", () => { ...@@ -91,5 +95,15 @@ describe("ItemInfo component", () => {
expect(mockCreatePush).toHaveBeenCalledTimes(1); 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment