Skip to content
Snippets Groups Projects
Commit c93076ab authored by Ina Martini's avatar Ina Martini
Browse files

refactor:

update modal componant and tests
parent 93dcf7f5
No related branches found
No related tags found
3 merge requests!66Final merge,!18Update login page and implement forgot password feature,!4Pipeline fix
...@@ -6,23 +6,14 @@ ...@@ -6,23 +6,14 @@
<div class="bg-white p-6 rounded-lg shadow-lg max-w-sm w-full"> <div class="bg-white p-6 rounded-lg shadow-lg max-w-sm w-full">
<h2 class="font-bold mb-4">{{ title }}</h2> <h2 class="font-bold mb-4">{{ title }}</h2>
<p class="mb-4">{{ message }}</p> <p class="mb-4">{{ message }}</p>
<input
v-if="showInput" <slot name="input"></slot>
:type="typeValue"
v-model="inputValue"
@input="$emit('update:inputValue', inputValue)"
class="border border-gray-300 p-2 w-full"
:placeholder="inputPlaceholder"
/>
<div class="flex flex-col justify-center items-center gap-3 mt-3 w-full"> <div class="flex flex-col justify-center items-center gap-3 mt-3 w-full">
<button <slot name="buttons"></slot>
v-if="showButton" </div>
:disabled="!isInputValid"
@click="buttonAction && buttonAction!()" <div class="flex justify-center mt-4">
class="active-button font-bold py-2 px-4 w-1/2 hover:bg-[#f7da7c] border-2 border-[#f7da7c] disabled:border-transparent"
>
{{ button1 }}
</button>
<button <button
@click="closeModal" @click="closeModal"
class="font-bold py-2 px-4 w-1/2 bg-white border-2 border-[#f7da7c] hover:bg-[#f7da7c]" class="font-bold py-2 px-4 w-1/2 bg-white border-2 border-[#f7da7c] hover:bg-[#f7da7c]"
...@@ -36,29 +27,16 @@ ...@@ -36,29 +27,16 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ref } from 'vue'
defineProps({ defineProps({
title: String, title: String,
message: String, message: String,
button1: String,
isModalOpen: Boolean, isModalOpen: Boolean,
buttonAction: {
type: Function,
default: () => {}
},
showButton: Boolean,
showInput: Boolean,
typeValue: String,
inputPlaceholder: String,
isInputValid: Boolean
}) })
const emits = defineEmits(['update:isModalOpen', 'update:inputValue']) const emits = defineEmits(['update:isModalOpen'])
const inputValue = ref('')
function closeModal() { function closeModal() {
inputValue.value = ''
emits('update:isModalOpen', false) emits('update:isModalOpen', false)
} }
</script> </script>
...@@ -39,30 +39,4 @@ describe('ModalComponent', () => { ...@@ -39,30 +39,4 @@ describe('ModalComponent', () => {
throw new Error('Close button not found') throw new Error('Close button not found')
} }
}) })
it('button is shown when showButton is true', async () => {
expect(wrapper.props().showButton).toBe(true)
expect(wrapper.find('.active-button').exists()).toBe(true)
})
it('button is not shown when showButton is false', async () => {
await wrapper.setProps({ showButton: false })
await wrapper.vm.$nextTick()
expect(wrapper.props().showButton).toBe(false)
expect(wrapper.find('.active-button').exists()).toBe(false)
})
it('input is shown when showInput is true', async () => {
await wrapper.setProps({ showInput: true })
await wrapper.vm.$nextTick()
expect(wrapper.props().showInput).toBe(true)
expect(wrapper.find('input').exists()).toBe(true)
})
it('input is not shown when showInput is false', async () => {
expect(wrapper.props().showInput).toBe(false)
expect(wrapper.find('input').exists()).toBe(false)
})
}) })
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