Skip to content
Snippets Groups Projects
Commit 4b716232 authored by Zara Mudassar's avatar Zara Mudassar
Browse files

Tests rendering and setting valus of input fields on AddNewItem component

parent 54261665
No related branches found
No related tags found
2 merge requests!19Item card,!17Item card
Pipeline #175584 passed
...@@ -9,8 +9,8 @@ ...@@ -9,8 +9,8 @@
<div class="mb-6" :class="{ error: v$.item.title.$errors.length }"> <div class="mb-6" :class="{ error: v$.item.title.$errors.length }">
<label <label
class="block mb-2 text-sm font-medium text-gray-900 dark:text-gray-300" class="block mb-2 text-sm font-medium text-gray-900 dark:text-gray-300"
>Tittel</label id="titleLabel"
> >Tittel</label>
<input <input
type="text" type="text"
id="title" id="title"
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
<div class="mb-6"> <div class="mb-6">
<label <label
class="block mb-2 text-sm font-medium text-gray-900 dark:text-gray-400" class="block mb-2 text-sm font-medium text-gray-900 dark:text-gray-400"
id="selectCategoryLabel"
>Kategori</label >Kategori</label
> >
<select <select
...@@ -70,6 +71,7 @@ ...@@ -70,6 +71,7 @@
<div class="mb-6" :class="{ error: v$.item.price.$errors.length }"> <div class="mb-6" :class="{ error: v$.item.price.$errors.length }">
<label <label
class="block mb-2 text-sm font-medium text-gray-900 dark:text-gray-300" class="block mb-2 text-sm font-medium text-gray-900 dark:text-gray-300"
id="priceLabel"
>Pris</label >Pris</label
> >
<input <input
...@@ -96,6 +98,7 @@ ...@@ -96,6 +98,7 @@
<div class="mb-6" :class="{ error: v$.item.description.$errors.length }"> <div class="mb-6" :class="{ error: v$.item.description.$errors.length }">
<label <label
class="block mb-2 text-sm font-medium text-gray-900 dark:text-gray-400" class="block mb-2 text-sm font-medium text-gray-900 dark:text-gray-400"
id="descriptionLabel"
>Beskrivelse</label >Beskrivelse</label
> >
<textarea <textarea
...@@ -122,6 +125,7 @@ ...@@ -122,6 +125,7 @@
<div> <div>
<label <label
class="block mb-2 text-sm font-medium text-gray-900 dark:text-gray-400" class="block mb-2 text-sm font-medium text-gray-900 dark:text-gray-400"
id="imageLabel"
> >
Bilder Bilder
</label> </label>
...@@ -152,6 +156,7 @@ ...@@ -152,6 +156,7 @@
<button <button
@click="saveClicked" @click="saveClicked"
class="content-center text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm sm:w-auto px-5 py-2.5 text-center dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800" class="content-center text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm sm:w-auto px-5 py-2.5 text-center dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800"
id="saveButton"
> >
Lagre Lagre
</button> </button>
......
import { shallowMount } from "@vue/test-utils";
import AddNewItem from "@/components/AddNewItem.vue";
describe("addNewItem elements rendering", () => {
it("renders all labels", () => {
const wrapper = shallowMount(AddNewItem);
expect(wrapper.find('#titleLabel').text()).toMatch("Tittel");
expect(wrapper.find('#selectCategoryLabel').text()).toMatch("Kategori");
expect(wrapper.find('#priceLabel').text()).toMatch("Pris");
expect(wrapper.find('#descriptionLabel').text()).toMatch("Beskrivelse");
expect(wrapper.find('#imageLabel').text()).toMatch("Bilde");
});
it("Tests setting values of input field", async() => {
const wrapper = shallowMount(AddNewItem);
const titleInput = wrapper.find('#title');
await titleInput.setValue("Dyson");
expect(titleInput.element.value).toBe("Dyson");
const selectedCategory = wrapper.find('#categories');
await selectedCategory.setValue("Hage");
expect(selectedCategory.element.value).toBe("Hage");
const priceInput = wrapper.find('#price');
await priceInput.setValue(500);
expect(priceInput.element.value).toBe("500");
const descriptionInput = wrapper.find('#description');
await descriptionInput.setValue("Dette er en støvsuer fra Dyson");
expect(descriptionInput.element.value).toBe("Dette er en støvsuer fra Dyson");
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment