diff --git a/src/components/CommunityComponents/CommunityRequestForm.vue b/src/components/CommunityComponents/CommunityRequestForm.vue index 0ea59b7ccf360f9745e9e87c7b407eeb61df68ed..8508efd202f46350266f1c198b5f7419aca8aac3 100644 --- a/src/components/CommunityComponents/CommunityRequestForm.vue +++ b/src/components/CommunityComponents/CommunityRequestForm.vue @@ -43,10 +43,10 @@ </div> <notification-modal - @click="routeToHome" - :visible="sendRequestClicked" - :title="'Vellykket'" - :message="'Forespørsel sendt!'" + @click="routeToHome" + :visible="sendRequestClicked" + :title="'Vellykket'" + :message="'Forespørsel sendt!'" > </notification-modal> </div> diff --git a/src/components/UserProfileComponents/UserItems.vue b/src/components/UserProfileComponents/UserItems.vue index 25038bd7e4c1af6223f5993f85cd72ef4328b299..ea6da154182dbf2a9e4e2ddaed0ecc887313df8f 100644 --- a/src/components/UserProfileComponents/UserItems.vue +++ b/src/components/UserProfileComponents/UserItems.vue @@ -39,7 +39,7 @@ v-for="item in visibleItems" :key="item" > - <ItemCard class="ItemCard w-fit h-fit" :item="item" /> + <ItemCard id="ItemCardPage" class="ItemCard w-fit h-fit" :item="item" /> <TripleDotButton class="DotButton" @click="openDotMenu(item)"> </TripleDotButton> @@ -103,7 +103,7 @@ v-if="showSearchedItems" > <div class="cardContainer" v-for="item in searchedItems" :key="item"> - <ItemCard class="ItemCard" :item="item" /> + <ItemCard id="ItemCardSearch" class="ItemCard" :item="item" /> <TripleDotButton class="DotButton" @click="openDotMenu(item)"> </TripleDotButton> diff --git a/src/components/UserProfileComponents/UserProfile.vue b/src/components/UserProfileComponents/UserProfile.vue index 142f3e612d45c5b27fb4c9172b6513e357cdfb66..28f59e1adbcef880ad6d96f2a865c7d742e792df 100644 --- a/src/components/UserProfileComponents/UserProfile.vue +++ b/src/components/UserProfileComponents/UserProfile.vue @@ -68,10 +68,10 @@ > </li> <li> - <router-link - to="" + <button + @click="deleteUser" class="block py-2 px-4 text-sm text-error-dark hover:bg-gray-100 dark:hover:bg-gray-600 dark:text-gray-200 dark:hover:text-white" - >Slett bruker</router-link + >Slett bruker</button > </li> </ul> @@ -158,6 +158,10 @@ export default { this.renterRating = ratingAsRenter; } }, + async deleteUser(){ + await UserService.deleteUser(); + this.logout(); + }, logout() { this.$store.commit("logout"); this.$router.push("/"); diff --git a/src/services/user.service.js b/src/services/user.service.js index 44b6159bdec5a16ca2f6893037ac792fa66f751c..dbbe29680b64ea39e9f8f262fc24eb4958dc1dd2 100644 --- a/src/services/user.service.js +++ b/src/services/user.service.js @@ -100,5 +100,15 @@ class UserService { }) .catch((err) => console.error(err)); } + + async deleteUser(){ + return await axios + .delete(API_URL + "user/delete",{ + headers: tokenHeader()}) + .then((res) => { + return res.data; + }) + .catch((err) => console.log(err)) + } } export default new UserService(); diff --git a/tests/unit/component-tests/user-component-tests/__snapshots__/login-form.spec.js.snap b/tests/unit/component-tests/user-component-tests/__snapshots__/login-form.spec.js.snap deleted file mode 100644 index 7d3875c13b81280752f1d753d824b2f830373fc9..0000000000000000000000000000000000000000 --- a/tests/unit/component-tests/user-component-tests/__snapshots__/login-form.spec.js.snap +++ /dev/null @@ -1,77 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`LoginForm component renders correctly 1`] = ` -<div - class="md:ring-1 ring-gray-300 rounded-xl overflow-hidden mx-auto mb-auto max-w-md w-full" -> - <div - class="px-6 py-4 mt-4" - > - <div - class="text-xl md:text-2xl font-medium text-center text-primary-light mt-4 mb-8" - > - Logg på - </div> - <div> - <div - class="w-full mt-6" - > - <input - class="block w-full px-4 py-2 mt-2 text-gray-700 placeholder-gray-500 bg-white border rounded-md dark:bg-gray-800 dark:border-gray-600 dark:placeholder-gray-400 focus:border-primary-light dark:focus:border-primary-light focus:ring-opacity-40 focus:outline-none focus:ring focus:ring-primary-light" - placeholder="Skriv inn din e-postadresse *" - required="" - type="email" - /> - <!-- error message --> - - - </div> - <div - class="w-full mt-6" - > - <input - class="block w-full px-4 py-2 mt-2 text-gray-700 placeholder-gray-500 bg-white border rounded-md dark:bg-gray-800 dark:border-gray-600 dark:placeholder-gray-400 focus:border-primary-light dark:focus:border-primary-light focus:ring-opacity-40 focus:outline-none focus:ring focus:ring-primary-light" - placeholder="Vennligst oppgi passordet ditt *" - required="" - type="password" - /> - <!-- error message --> - - - </div> - <div - class="flex items-center justify-between mt-8" - > - <router-link - class="text-primary-medium" - to="/resetPassword" - > - Glemt passord? - </router-link> - <button - class="block text-white bg-primary-medium hover:bg-primary-dark focus:ring-4 focus:outline-none focus:ring-primary-light font-medium rounded-lg text-sm px-5 py-2.5 text-center dark:bg-primary-medium dark:hover:bg-primary-dark dark:focus:ring-primary-light" - > - Logg på - </button> - </div> - </div> - </div> - <div - class="flex items-center justify-center py-4 text-center bg-gray-50 dark:bg-gray-700" - > - <router-link - class="mx-2 text-sm font-bold text-primary-medium dark:text-primary-light hover:underline" - to="/register" - > - Opprette ny konto - </router-link> - </div> - <div - class="flex items-center justify-center text-center bg-gray-50" - > - <label - class="mx-2 text-sm font-bold text-error-medium dark:text-primary-light hover:underline" - /> - </div> -</div> -`; diff --git a/tests/unit/component-tests/user-component-tests/__snapshots__/new-password-form.spec.js.snap b/tests/unit/component-tests/user-component-tests/__snapshots__/new-password-form.spec.js.snap deleted file mode 100644 index 129085284ce0c40121b0be19e799ac65b7361f12..0000000000000000000000000000000000000000 --- a/tests/unit/component-tests/user-component-tests/__snapshots__/new-password-form.spec.js.snap +++ /dev/null @@ -1,88 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`NewPasswordForm component renders correctly 1`] = ` -<div - class="md:ring-1 ring-gray-300 rounded-xl overflow-hidden mx-auto mb-auto max-w-md w-full p-4" -> - <h3 - class="text-xl font-medium text-center text-gray-600 dark:text-gray-200 mt-4 mb-8" - > - Endre passord - </h3> - <div - class="" - id="oldPasswordField" - > - <label - class="block text-sm text-gray-800 dark:text-gray-200" - for="oldPassword" - > - Gammelt passord - </label> - <input - class="block w-full px-4 py-2 mt-2 text-gray-700 placeholder-gray-500 bg-white border rounded-md dark:bg-gray-800 dark:border-gray-600 dark:placeholder-gray-400 focus:border-blue-400 dark:focus:border-blue-300 focus:ring-opacity-40 focus:outline-none focus:ring focus:ring-blue-300" - type="password" - /> - <!-- error message --> - - - </div> - <div - class="mt-4" - id="firstPasswordField" - > - <label - class="block text-sm text-gray-800 dark:text-gray-200" - for="password" - > - Nytt passord - </label> - <input - class="block w-full px-4 py-2 mt-2 text-gray-700 placeholder-gray-500 bg-white border rounded-md dark:bg-gray-800 dark:border-gray-600 dark:placeholder-gray-400 focus:border-blue-400 dark:focus:border-blue-300 focus:ring-opacity-40 focus:outline-none focus:ring focus:ring-blue-300" - type="password" - /> - <!-- error message --> - - - </div> - <div - class="mt-4" - id="secondPasswordField" - > - <div - class="flex items-center justify-between" - > - <label - class="block text-sm text-gray-800 dark:text-gray-200" - for="rePassword" - > - Gjenta nytt passord - </label> - </div> - <input - class="block w-full px-4 py-2 mt-2 text-gray-700 placeholder-gray-500 bg-white border rounded-md dark:bg-gray-800 dark:border-gray-600 dark:placeholder-gray-400 focus:border-blue-400 dark:focus:border-blue-300 focus:ring-opacity-40 focus:outline-none focus:ring focus:ring-blue-300" - type="password" - /> - <!-- error message --> - - - </div> - <div - class="mt-6" - id="buttonsField" - > - <button - class="block text-white bg-primary-medium hover:bg-primary-dark focus:ring-4 focus:outline-none focus:ring-primary-light font-medium rounded-lg text-sm px-5 py-2.5 text-center dark:bg-primary-medium dark:hover:bg-primary-dark dark:focus:ring-primary-light float-right" - > - Sett ny passord - </button> - </div> - <div - class="flex items-center justify-center text-center bg-gray-50" - > - <label - class="mx-2 text-sm font-bold text-error-medium dark:text-primary-light hover:underline" - /> - </div> -</div> -`; diff --git a/tests/unit/component-tests/user-component-tests/__snapshots__/rating.spec.js.snap b/tests/unit/component-tests/user-component-tests/__snapshots__/rating.spec.js.snap deleted file mode 100644 index f22076edecd3620957e0bbf9141873adfd3a6322..0000000000000000000000000000000000000000 --- a/tests/unit/component-tests/user-component-tests/__snapshots__/rating.spec.js.snap +++ /dev/null @@ -1,22 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`Rating component renders correctly 1`] = ` -<ul - class="flex justify-center" -> - <li> - <p - class="ml-2 text-sm font-medium text-gray-500 dark:text-gray-400" - > - : - </p> - </li> - <li> - <p - class="ml-2 text-sm font-medium text-gray-500 dark:text-gray-400" - > - Ingen vurderinger - </p> - </li> -</ul> -`; diff --git a/tests/unit/component-tests/user-component-tests/__snapshots__/register-user-component.spec.js.snap b/tests/unit/component-tests/user-component-tests/__snapshots__/register-user-component.spec.js.snap deleted file mode 100644 index 8adae3ffa2833611c6e3da43443b7e2a381b4e3f..0000000000000000000000000000000000000000 --- a/tests/unit/component-tests/user-component-tests/__snapshots__/register-user-component.spec.js.snap +++ /dev/null @@ -1,96 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`RegisterFormComponent renders correctly 1`] = ` -<div - class="w-full max-w-md mx-auto mb-auto md:ring-1 ring-gray-300 overflow-hidden rounded-xl p-4" -> - <div - class="text-xl md:text-2xl font-medium text-center text-primary-light mt-4 mb-8" - id="registerLabel" - > - Opprett ny konto - </div> - <form> - <div - class="grid grid-cols-1 gap-6 mt-4" - > - <div> - <input - class="block w-full px-4 py-2 mt-2 text-gray-700 placeholder-gray-500 bg-white border rounded-md dark:bg-gray-800 dark:border-gray-600 dark:placeholder-gray-400 focus:border-primary-light dark:focus:border-primary-light focus:ring-opacity-40 focus:outline-none focus:ring focus:ring-primary-light" - id="email" - placeholder="E-post adresse" - type="email" - /> - <!-- error message --> - - - </div> - <div> - <input - class="block w-full px-4 py-2 mt-2 text-gray-700 placeholder-gray-500 bg-white border rounded-md dark:bg-gray-800 dark:border-gray-600 dark:placeholder-gray-400 focus:border-primary-light dark:focus:border-primary-light focus:ring-opacity-40 focus:outline-none focus:ring focus:ring-primary-light" - id="password" - placeholder="Passord" - type="password" - /> - <!-- error message --> - - - </div> - <div> - <input - class="block w-full px-4 py-2 mt-2 text-gray-700 placeholder-gray-500 bg-white border rounded-md dark:bg-gray-800 dark:border-gray-600 dark:placeholder-gray-400 focus:border-primary-light dark:focus:border-primary-light focus:ring-opacity-40 focus:outline-none focus:ring focus:ring-primary-light" - id="confirmPassword" - placeholder="Bekreft passord" - type="password" - /> - <!-- error message --> - - - </div> - <div> - <input - class="block w-full px-4 py-2 mt-2 text-gray-700 placeholder-gray-500 bg-white border rounded-md dark:bg-gray-800 dark:border-gray-600 dark:placeholder-gray-400 focus:border-primary-light dark:focus:border-primary-light focus:ring-opacity-40 focus:outline-none focus:ring focus:ring-primary-light" - data-test="firstNameTest" - id="firstName" - placeholder="Fornavn" - type="text" - /> - <!-- error message --> - - - </div> - <div> - <input - class="block w-full px-4 py-2 mt-2 text-gray-700 placeholder-gray-500 bg-white border rounded-md dark:bg-gray-800 dark:border-gray-600 dark:placeholder-gray-400 focus:border-primary-light dark:focus:border-primary-light focus:ring-opacity-40 focus:outline-none focus:ring focus:ring-primary-light" - id="lastName" - placeholder="Etternavn" - type="text" - /> - <!-- error message --> - - - </div> - <div> - <input - class="block w-full px-4 py-2 mt-2 text-gray-700 placeholder-gray-500 bg-white border rounded-md dark:bg-gray-800 dark:border-gray-600 dark:placeholder-gray-400 focus:border-primary-light dark:focus:border-primary-light focus:ring-opacity-40 focus:outline-none focus:ring focus:ring-primary-light" - id="address" - placeholder="Adresse" - type="text" - /> - <!-- error message --> - - - </div> - </div> - <div - class="flex justify-end mt-6" - > - <button - class="block text-white bg-primary-medium hover:bg-primary-dark focus:ring-4 focus:outline-none focus:ring-primary-light font-medium rounded-lg text-sm px-5 py-2.5 text-center dark:bg-primary-medium dark:hover:bg-primary-dark dark:focus:ring-primary-light" - > - Opprett - </button> - </div> - </form> -</div> -`; diff --git a/tests/unit/component-tests/user-component-tests/__snapshots__/reset-password-form.spec.js.snap b/tests/unit/component-tests/user-component-tests/__snapshots__/reset-password-form.spec.js.snap deleted file mode 100644 index 7b7c1ace2fabdd62b5a782799ce6d1f71ba8bfb1..0000000000000000000000000000000000000000 --- a/tests/unit/component-tests/user-component-tests/__snapshots__/reset-password-form.spec.js.snap +++ /dev/null @@ -1,43 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`ResetPasswordForm component renders correctly 1`] = ` -<div - class="md:ring-1 ring-gray-300 rounded-xl overflow-hidden mx-auto mb-auto max-w-md w-full p-4" -> - <h3 - class="text-xl font-medium text-center text-primary-light mt-4 mb-8" - > - Glemt passordet ditt? - </h3> - <div - class="m-6" - id="emailField" - > - <div - class="mb-6" - > - <label - class="block mb-2 text-sm font-medium text-gray-900 dark:text-gray-300" - for="email" - > - E-post - </label> - <input - class="block w-full px-4 py-2 mt-2 text-gray-700 placeholder-gray-500 bg-white border rounded-md dark:bg-gray-800 dark:border-gray-600 dark:placeholder-gray-400 focus:border-blue-400 dark:focus:border-blue-300 focus:ring-opacity-40 focus:outline-none focus:ring focus:ring-blue-300" - id="email" - placeholder="eksempel@eksempel.no" - required="" - type="email" - /> - <!-- error message --> - - - </div> - <button - class="block text-white bg-primary-medium hover:bg-primary-dark focus:ring-4 focus:outline-none focus:ring-primary-light font-medium rounded-lg text-sm px-5 py-2.5 text-center dark:bg-primary-medium dark:hover:bg-primary-dark dark:focus:ring-primary-light float-right" - > - Tilbakestill passord - </button> - </div> -</div> -`; diff --git a/tests/unit/component-tests/user-component-tests/user-items.spec.js b/tests/unit/component-tests/user-component-tests/user-items.spec.js new file mode 100644 index 0000000000000000000000000000000000000000..32c2729d1b31fa90de8261043eb1f4f85471f54d --- /dev/null +++ b/tests/unit/component-tests/user-component-tests/user-items.spec.js @@ -0,0 +1,41 @@ +import { mount } from "@vue/test-utils"; +import UserItems from "@/components/UserProfileComponents/UserItems.vue"; + +describe("UserItems component", () => { + let wrapper; + + beforeEach(() => { + wrapper = mount(UserItems, { + data() { + return { + items: [ + { + listingID: 1, + img: "", + address: "Veien", + title: "Matboks", + pricePerDay: 50, + toggle: false, + } + ] + } + } + + + + }); + }); + + it("renders correctly", () => { + expect(wrapper.element).toMatchSnapshot(); + }); + + it("is instantiated", () => { + expect(wrapper.exists()).toBeTruthy(); + }); + + it("Check headline", () => { + expect(wrapper.find("#headline").text()).toMatch("Mine gjenstander"); + }); + +});