UNPKG

@mozaic-ds/vue

Version:

Mozaic-Vue is the Vue.js implementation of ADEO Design system

104 lines (91 loc) 3.34 kB
import { mount } from '@vue/test-utils'; import { describe, it, expect } from 'vitest'; import MStatusNotification from './MStatusNotification.vue'; import InfoCircleFilled32 from '@mozaic-ds/icons-vue/src/components/InfoCircleFilled32/InfoCircleFilled32.vue'; import WarningCircleFilled32 from '@mozaic-ds/icons-vue/src/components/WarningCircleFilled32/WarningCircleFilled32.vue'; import CrossCircleFilled32 from '@mozaic-ds/icons-vue/src/components/CrossCircleFilled32/CrossCircleFilled32.vue'; import CheckCircleFilled32 from '@mozaic-ds/icons-vue/src/components/CheckCircleFilled32/CheckCircleFilled32.vue'; describe('MStatusNotification.vue', () => { it('should render correctly with the default props', () => { const wrapper = mount(MStatusNotification, { props: { title: 'Test Title', description: 'Test Description', }, }); expect(wrapper.text()).toContain('Test Title'); expect(wrapper.text()).toContain('Test Description'); expect(wrapper.findComponent(InfoCircleFilled32).exists()).toBe(true); // Default icon is InfoCircle32 expect(wrapper.classes()).toContain('mc-status-notification'); }); it('should display the correct icon based on the status prop', () => { const wrapperSuccess = mount(MStatusNotification, { props: { title: 'Success', description: 'Success Description', status: 'success', }, }); expect(wrapperSuccess.findComponent(CheckCircleFilled32).exists()).toBe( true, ); const wrapperWarning = mount(MStatusNotification, { props: { title: 'Warning', description: 'Warning Description', status: 'warning', }, }); expect(wrapperWarning.findComponent(WarningCircleFilled32).exists()).toBe( true, ); const wrapperError = mount(MStatusNotification, { props: { title: 'Error', description: 'Error Description', status: 'error', }, }); expect(wrapperError.findComponent(CrossCircleFilled32).exists()).toBe(true); }); it('should show the close button if closable prop is true', () => { const wrapper = mount(MStatusNotification, { props: { title: 'Closable Test', description: 'Test Description', closable: true, }, }); expect( wrapper.find('button.mc-status-notification-closable__close').exists(), ).toBe(true); }); it('should emit a close event when the close button is clicked', async () => { const wrapper = mount(MStatusNotification, { props: { title: 'Closable Test', description: 'Test Description', closable: true, }, }); const closeButton = wrapper.find( 'button.mc-status-notification-closable__close', ); await closeButton.trigger('click'); // Check if the "close" event was emitted expect(wrapper.emitted()).toHaveProperty('close'); }); it('should render footer slot if provided', () => { const footerSlotContent = '<button>Footer Button</button>'; const wrapper = mount(MStatusNotification, { props: { title: 'With Footer', description: 'Description with footer', }, slots: { footer: footerSlotContent, }, }); expect(wrapper.html()).toContain(footerSlotContent); }); });