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

test(modal): test that modal works as expected

parent 62afd8e8
No related branches found
No related tags found
3 merge requests!66Final merge,!18Update login page and implement forgot password feature,!4Pipeline fix
import { describe, it, expect, beforeEach } from 'vitest'
import { shallowMount } from '@vue/test-utils'
import ModalComponent from '@/components/ModalComponent.vue'
describe('ModalComponent', () => {
let wrapper: any
beforeEach(() => {
wrapper = shallowMount(ModalComponent, {
props: {
title: 'Test Title',
message: 'Test Message',
button1: 'Test button',
isModalOpen: true,
showButton: true,
showInput: false,
typeValue: 'text',
inputPlaceholder: 'Placeholder',
isInputValid: true,
}
})
})
it('opens modal when button is clicked', async () => {
expect(wrapper.props().isModalOpen).toBe(true);
})
it('closes modal when close button is clicked', async () => {
await wrapper.setProps({ isModalOpen: true });
await wrapper.vm.$nextTick();
const closeButton = wrapper.find('button[aria-label="close"]');
if (closeButton.exists()) {
await closeButton.trigger('click');
expect(wrapper.emitted()['update:isModalOpen']).toBeTruthy();
expect(wrapper.emitted()['update:isModalOpen'][0]).toEqual([false]);
} else {
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