diff --git a/src/test/ContactBulkActions.test.ts b/src/test/ContactBulkActions.test.ts new file mode 100644 index 00000000..48979192 --- /dev/null +++ b/src/test/ContactBulkActions.test.ts @@ -0,0 +1,303 @@ +import { describe, it, expect, beforeEach, vi } from 'vitest' +import { mount } from '@vue/test-utils' +import ContactBulkActions from '@/components/ContactBulkActions.vue' + +/** + * ContactBulkActions Component Tests + * + * Comprehensive test suite for the ContactBulkActions component. + * Tests component rendering, props, events, and user interactions. + * + * @author Matthew Raymer + */ +describe('ContactBulkActions', () => { + let wrapper: any + + /** + * Test setup - creates a fresh component instance before each test + */ + beforeEach(() => { + wrapper = null + }) + + /** + * Helper function to mount component with props + * @param props - Component props + * @returns Vue test wrapper + */ + const mountComponent = (props = {}) => { + return mount(ContactBulkActions, { + props: { + showGiveNumbers: false, + allContactsSelected: false, + copyButtonClass: 'btn-primary', + copyButtonDisabled: false, + ...props + } + }) + } + + describe('Component Rendering', () => { + it('should render when all props are provided', () => { + wrapper = mountComponent() + + expect(wrapper.exists()).toBe(true) + expect(wrapper.find('div').exists()).toBe(true) + }) + + it('should render checkbox when showGiveNumbers is false', () => { + wrapper = mountComponent({ showGiveNumbers: false }) + + expect(wrapper.find('input[type="checkbox"]').exists()).toBe(true) + }) + + it('should not render checkbox when showGiveNumbers is true', () => { + wrapper = mountComponent({ showGiveNumbers: true }) + + expect(wrapper.find('input[type="checkbox"]').exists()).toBe(false) + }) + + it('should render copy button when showGiveNumbers is false', () => { + wrapper = mountComponent({ showGiveNumbers: false }) + + expect(wrapper.find('button').exists()).toBe(true) + expect(wrapper.find('button').text()).toBe('Copy') + }) + + it('should not render copy button when showGiveNumbers is true', () => { + wrapper = mountComponent({ showGiveNumbers: true }) + + expect(wrapper.find('button').exists()).toBe(false) + }) + }) + + describe('Component Styling', () => { + it('should have correct container CSS classes', () => { + wrapper = mountComponent() + const container = wrapper.find('div') + + expect(container.classes()).toContain('mt-2') + expect(container.classes()).toContain('w-full') + expect(container.classes()).toContain('text-left') + }) + + it('should have correct checkbox CSS classes', () => { + wrapper = mountComponent() + const checkbox = wrapper.find('input[type="checkbox"]') + + expect(checkbox.classes()).toContain('align-middle') + expect(checkbox.classes()).toContain('ml-2') + expect(checkbox.classes()).toContain('h-6') + expect(checkbox.classes()).toContain('w-6') + }) + + it('should apply custom copy button class', () => { + wrapper = mountComponent({ copyButtonClass: 'custom-btn-class' }) + const button = wrapper.find('button') + + expect(button.classes()).toContain('custom-btn-class') + }) + }) + + describe('Component Props', () => { + it('should accept showGiveNumbers prop', () => { + wrapper = mountComponent({ showGiveNumbers: true }) + expect(wrapper.vm.showGiveNumbers).toBe(true) + }) + + it('should accept allContactsSelected prop', () => { + wrapper = mountComponent({ allContactsSelected: true }) + expect(wrapper.vm.allContactsSelected).toBe(true) + }) + + it('should accept copyButtonClass prop', () => { + wrapper = mountComponent({ copyButtonClass: 'test-class' }) + expect(wrapper.vm.copyButtonClass).toBe('test-class') + }) + + it('should accept copyButtonDisabled prop', () => { + wrapper = mountComponent({ copyButtonDisabled: true }) + expect(wrapper.vm.copyButtonDisabled).toBe(true) + }) + + it('should handle all props together', () => { + wrapper = mountComponent({ + showGiveNumbers: true, + allContactsSelected: true, + copyButtonClass: 'test-class', + copyButtonDisabled: true + }) + + expect(wrapper.vm.showGiveNumbers).toBe(true) + expect(wrapper.vm.allContactsSelected).toBe(true) + expect(wrapper.vm.copyButtonClass).toBe('test-class') + expect(wrapper.vm.copyButtonDisabled).toBe(true) + }) + }) + + describe('Checkbox Behavior', () => { + it('should be checked when allContactsSelected is true', () => { + wrapper = mountComponent({ allContactsSelected: true }) + const checkbox = wrapper.find('input[type="checkbox"]') + + expect(checkbox.element.checked).toBe(true) + }) + + it('should not be checked when allContactsSelected is false', () => { + wrapper = mountComponent({ allContactsSelected: false }) + const checkbox = wrapper.find('input[type="checkbox"]') + + expect(checkbox.element.checked).toBe(false) + }) + + it('should have correct test ID', () => { + wrapper = mountComponent() + const checkbox = wrapper.find('input[type="checkbox"]') + + expect(checkbox.attributes('data-testid')).toBe('contactCheckAllBottom') + }) + }) + + describe('Button Behavior', () => { + it('should be disabled when copyButtonDisabled is true', () => { + wrapper = mountComponent({ copyButtonDisabled: true }) + const button = wrapper.find('button') + + expect(button.attributes('disabled')).toBeDefined() + }) + + it('should not be disabled when copyButtonDisabled is false', () => { + wrapper = mountComponent({ copyButtonDisabled: false }) + const button = wrapper.find('button') + + expect(button.attributes('disabled')).toBeUndefined() + }) + + it('should have correct text', () => { + wrapper = mountComponent() + const button = wrapper.find('button') + + expect(button.text()).toBe('Copy') + }) + }) + + describe('User Interactions', () => { + it('should emit toggle-all-selection event when checkbox is clicked', async () => { + wrapper = mountComponent() + const checkbox = wrapper.find('input[type="checkbox"]') + + await checkbox.trigger('click') + + expect(wrapper.emitted('toggle-all-selection')).toBeTruthy() + expect(wrapper.emitted('toggle-all-selection')).toHaveLength(1) + }) + + it('should emit copy-selected event when button is clicked', async () => { + wrapper = mountComponent() + const button = wrapper.find('button') + + await button.trigger('click') + + expect(wrapper.emitted('copy-selected')).toBeTruthy() + expect(wrapper.emitted('copy-selected')).toHaveLength(1) + }) + + it('should emit multiple events when clicked multiple times', async () => { + wrapper = mountComponent() + const checkbox = wrapper.find('input[type="checkbox"]') + const button = wrapper.find('button') + + await checkbox.trigger('click') + await button.trigger('click') + await checkbox.trigger('click') + + expect(wrapper.emitted('toggle-all-selection')).toHaveLength(2) + expect(wrapper.emitted('copy-selected')).toHaveLength(1) + }) + }) + + describe('Component Methods', () => { + it('should have all required props', () => { + wrapper = mountComponent() + + expect(wrapper.vm.showGiveNumbers).toBeDefined() + expect(wrapper.vm.allContactsSelected).toBeDefined() + expect(wrapper.vm.copyButtonClass).toBeDefined() + expect(wrapper.vm.copyButtonDisabled).toBeDefined() + }) + }) + + describe('Edge Cases', () => { + it('should handle rapid clicks efficiently', async () => { + wrapper = mountComponent() + const checkbox = wrapper.find('input[type="checkbox"]') + const button = wrapper.find('button') + + // Simulate rapid clicks + await Promise.all([ + checkbox.trigger('click'), + button.trigger('click'), + checkbox.trigger('click') + ]) + + expect(wrapper.emitted('toggle-all-selection')).toHaveLength(2) + expect(wrapper.emitted('copy-selected')).toHaveLength(1) + }) + + it('should maintain component state after prop changes', async () => { + wrapper = mountComponent({ showGiveNumbers: false }) + expect(wrapper.find('input[type="checkbox"]').exists()).toBe(true) + + await wrapper.setProps({ showGiveNumbers: true }) + expect(wrapper.find('input[type="checkbox"]').exists()).toBe(false) + + await wrapper.setProps({ showGiveNumbers: false }) + expect(wrapper.find('input[type="checkbox"]').exists()).toBe(true) + }) + + it('should handle disabled button clicks', async () => { + wrapper = mountComponent({ copyButtonDisabled: true }) + const button = wrapper.find('button') + + await button.trigger('click') + + // Disabled buttons typically don't emit events + expect(wrapper.emitted('copy-selected')).toBeUndefined() + }) + }) + + describe('Accessibility', () => { + it('should have proper semantic structure', () => { + wrapper = mountComponent() + + expect(wrapper.find('div').exists()).toBe(true) + expect(wrapper.find('input[type="checkbox"]').exists()).toBe(true) + expect(wrapper.find('button').exists()).toBe(true) + }) + + it('should have proper form controls', () => { + wrapper = mountComponent() + const checkbox = wrapper.find('input[type="checkbox"]') + const button = wrapper.find('button') + + expect(checkbox.attributes('type')).toBe('checkbox') + expect(button.text()).toBe('Copy') + }) + }) + + describe('Conditional Rendering', () => { + it('should show both controls when showGiveNumbers is false', () => { + wrapper = mountComponent({ showGiveNumbers: false }) + + expect(wrapper.find('input[type="checkbox"]').exists()).toBe(true) + expect(wrapper.find('button').exists()).toBe(true) + }) + + it('should hide both controls when showGiveNumbers is true', () => { + wrapper = mountComponent({ showGiveNumbers: true }) + + expect(wrapper.find('input[type="checkbox"]').exists()).toBe(false) + expect(wrapper.find('button').exists()).toBe(false) + }) + }) +}) \ No newline at end of file diff --git a/src/test/LargeIdenticonModal.test.ts b/src/test/LargeIdenticonModal.test.ts new file mode 100644 index 00000000..9e72fbe6 --- /dev/null +++ b/src/test/LargeIdenticonModal.test.ts @@ -0,0 +1,230 @@ +import { describe, it, expect, beforeEach } from 'vitest' +import { mount } from '@vue/test-utils' +import LargeIdenticonModal from '@/components/LargeIdenticonModal.vue' +import { Contact } from '@/db/tables/contacts' + +/** + * LargeIdenticonModal Component Tests + * + * Comprehensive test suite for the LargeIdenticonModal component. + * Tests component rendering, props, events, and user interactions. + * + * @author Matthew Raymer + */ +describe('LargeIdenticonModal', () => { + let wrapper: any + let mockContact: Contact + + /** + * Test setup - creates a fresh component instance before each test + */ + beforeEach(() => { + wrapper = null + mockContact = { + id: 1, + name: 'Test Contact', + did: 'did:ethr:test', + createdAt: new Date(), + updatedAt: new Date() + } as Contact + }) + + /** + * Helper function to mount component with props + * @param props - Component props + * @returns Vue test wrapper + */ + const mountComponent = (props = {}) => { + return mount(LargeIdenticonModal, { + props: { + contact: mockContact, + ...props + }, + global: { + stubs: { + EntityIcon: { + template: '
', + props: ['contact', 'iconSize', 'class'] + } + } + } + }) + } + + describe('Component Rendering', () => { + it('should render when contact is provided', () => { + wrapper = mountComponent() + + expect(wrapper.exists()).toBe(true) + expect(wrapper.find('.fixed').exists()).toBe(true) + expect(wrapper.find('.absolute').exists()).toBe(true) + expect(wrapper.find('.entity-icon-stub').exists()).toBe(true) + }) + + it('should not render when contact is undefined', () => { + wrapper = mountComponent({ contact: undefined }) + + expect(wrapper.find('.fixed').exists()).toBe(false) + }) + + it('should not render when contact is null', () => { + wrapper = mountComponent({ contact: null }) + + expect(wrapper.find('.fixed').exists()).toBe(false) + }) + }) + + describe('Component Styling', () => { + it('should have correct modal CSS classes', () => { + wrapper = mountComponent() + const modal = wrapper.find('.fixed') + + expect(modal.classes()).toContain('fixed') + expect(modal.classes()).toContain('z-[100]') + expect(modal.classes()).toContain('top-0') + expect(modal.classes()).toContain('inset-x-0') + expect(modal.classes()).toContain('w-full') + }) + + it('should have correct overlay CSS classes', () => { + wrapper = mountComponent() + const overlay = wrapper.find('.absolute') + + expect(overlay.classes()).toContain('absolute') + expect(overlay.classes()).toContain('inset-0') + expect(overlay.classes()).toContain('h-screen') + expect(overlay.classes()).toContain('flex') + expect(overlay.classes()).toContain('flex-col') + expect(overlay.classes()).toContain('items-center') + expect(overlay.classes()).toContain('justify-center') + expect(overlay.classes()).toContain('bg-slate-900/50') + }) + + it('should have EntityIcon component', () => { + wrapper = mountComponent() + const entityIcon = wrapper.find('.entity-icon-stub') + + expect(entityIcon.exists()).toBe(true) + }) + }) + + describe('Component Props', () => { + it('should accept contact prop', () => { + wrapper = mountComponent() + expect(wrapper.vm.contact).toStrictEqual(mockContact) + }) + + it('should render EntityIcon component', () => { + wrapper = mountComponent() + const entityIcon = wrapper.find('.entity-icon-stub') + + expect(entityIcon.exists()).toBe(true) + }) + }) + + describe('User Interactions', () => { + it('should emit close event when EntityIcon is clicked', async () => { + wrapper = mountComponent() + const entityIcon = wrapper.find('.entity-icon-stub') + + await entityIcon.trigger('click') + + expect(wrapper.emitted('close')).toBeTruthy() + expect(wrapper.emitted('close')).toHaveLength(1) + }) + + it('should emit close event multiple times when clicked multiple times', async () => { + wrapper = mountComponent() + const entityIcon = wrapper.find('.entity-icon-stub') + + await entityIcon.trigger('click') + await entityIcon.trigger('click') + await entityIcon.trigger('click') + + expect(wrapper.emitted('close')).toBeTruthy() + expect(wrapper.emitted('close')).toHaveLength(3) + }) + }) + + describe('Component Methods', () => { + it('should have contact prop', () => { + wrapper = mountComponent() + expect(wrapper.vm.contact).toBeDefined() + }) + }) + + describe('Edge Cases', () => { + it('should handle rapid clicks efficiently', async () => { + wrapper = mountComponent() + const entityIcon = wrapper.find('.entity-icon-stub') + + // Simulate rapid clicks + await Promise.all([ + entityIcon.trigger('click'), + entityIcon.trigger('click'), + entityIcon.trigger('click') + ]) + + expect(wrapper.emitted('close')).toBeTruthy() + expect(wrapper.emitted('close')).toHaveLength(3) + }) + + it('should maintain component state after prop changes', async () => { + wrapper = mountComponent() + expect(wrapper.find('.fixed').exists()).toBe(true) + + await wrapper.setProps({ contact: undefined }) + expect(wrapper.find('.fixed').exists()).toBe(false) + + await wrapper.setProps({ contact: mockContact }) + expect(wrapper.find('.fixed').exists()).toBe(true) + }) + }) + + describe('Accessibility', () => { + it('should have proper semantic structure', () => { + wrapper = mountComponent() + + expect(wrapper.find('.fixed').exists()).toBe(true) + expect(wrapper.find('.absolute').exists()).toBe(true) + expect(wrapper.find('.entity-icon-stub').exists()).toBe(true) + }) + + it('should be clickable for closing', () => { + wrapper = mountComponent() + const entityIcon = wrapper.find('.entity-icon-stub') + + expect(entityIcon.exists()).toBe(true) + expect(entityIcon.isVisible()).toBe(true) + }) + }) + + describe('Modal Behavior', () => { + it('should cover full screen', () => { + wrapper = mountComponent() + const modal = wrapper.find('.fixed') + const overlay = wrapper.find('.absolute') + + expect(modal.classes()).toContain('inset-x-0') + expect(modal.classes()).toContain('w-full') + expect(overlay.classes()).toContain('inset-0') + expect(overlay.classes()).toContain('h-screen') + }) + + it('should have high z-index for overlay', () => { + wrapper = mountComponent() + const modal = wrapper.find('.fixed') + + expect(modal.classes()).toContain('z-[100]') + }) + + it('should center content', () => { + wrapper = mountComponent() + const overlay = wrapper.find('.absolute') + + expect(overlay.classes()).toContain('flex') + expect(overlay.classes()).toContain('items-center') + expect(overlay.classes()).toContain('justify-center') + }) + }) +}) \ No newline at end of file diff --git a/src/test/ProjectIcon.test.ts b/src/test/ProjectIcon.test.ts new file mode 100644 index 00000000..28ae9e6b --- /dev/null +++ b/src/test/ProjectIcon.test.ts @@ -0,0 +1,263 @@ +import { describe, it, expect, beforeEach, vi } from 'vitest' +import { mount } from '@vue/test-utils' +import ProjectIcon from '@/components/ProjectIcon.vue' + +/** + * ProjectIcon Component Tests + * + * Comprehensive test suite for the ProjectIcon component. + * Tests component rendering, props, icon generation, and user interactions. + * + * @author Matthew Raymer + */ +describe('ProjectIcon', () => { + let wrapper: any + + /** + * Test setup - creates a fresh component instance before each test + */ + beforeEach(() => { + wrapper = null + }) + + /** + * Helper function to mount component with props + * @param props - Component props + * @returns Vue test wrapper + */ + const mountComponent = (props = {}) => { + return mount(ProjectIcon, { + props: { + entityId: 'test-entity', + iconSize: 64, + imageUrl: '', + linkToFullImage: false, + ...props + } + }) + } + + describe('Component Rendering', () => { + it('should render when all props are provided', () => { + wrapper = mountComponent() + + expect(wrapper.exists()).toBe(true) + expect(wrapper.find('div').exists()).toBe(true) + }) + + it('should render as link when linkToFullImage and imageUrl are provided', () => { + wrapper = mountComponent({ + imageUrl: 'test-image.jpg', + linkToFullImage: true + }) + + expect(wrapper.find('a').exists()).toBe(true) + expect(wrapper.find('a').attributes('href')).toBe('test-image.jpg') + expect(wrapper.find('a').attributes('target')).toBe('_blank') + }) + + it('should render as div when not a link', () => { + wrapper = mountComponent({ + imageUrl: 'test-image.jpg', + linkToFullImage: false + }) + + expect(wrapper.find('div').exists()).toBe(true) + expect(wrapper.find('a').exists()).toBe(false) + }) + + it('should render as div when no imageUrl', () => { + wrapper = mountComponent({ + imageUrl: '', + linkToFullImage: true + }) + + expect(wrapper.find('div').exists()).toBe(true) + expect(wrapper.find('a').exists()).toBe(false) + }) + }) + + describe('Component Styling', () => { + it('should have correct container CSS classes', () => { + wrapper = mountComponent() + const container = wrapper.find('div') + + expect(container.classes()).toContain('h-full') + expect(container.classes()).toContain('w-full') + expect(container.classes()).toContain('object-contain') + }) + + it('should have correct link CSS classes when rendered as link', () => { + wrapper = mountComponent({ + imageUrl: 'test-image.jpg', + linkToFullImage: true + }) + const link = wrapper.find('a') + + expect(link.classes()).toContain('h-full') + expect(link.classes()).toContain('w-full') + expect(link.classes()).toContain('object-contain') + }) + }) + + describe('Component Props', () => { + it('should accept entityId prop', () => { + wrapper = mountComponent({ entityId: 'test-entity-id' }) + expect(wrapper.vm.entityId).toBe('test-entity-id') + }) + + it('should accept iconSize prop', () => { + wrapper = mountComponent({ iconSize: 128 }) + expect(wrapper.vm.iconSize).toBe(128) + }) + + it('should accept imageUrl prop', () => { + wrapper = mountComponent({ imageUrl: 'test-image.png' }) + expect(wrapper.vm.imageUrl).toBe('test-image.png') + }) + + it('should accept linkToFullImage prop', () => { + wrapper = mountComponent({ linkToFullImage: true }) + expect(wrapper.vm.linkToFullImage).toBe(true) + }) + + it('should handle all props together', () => { + wrapper = mountComponent({ + entityId: 'test-entity', + iconSize: 64, + imageUrl: 'test-image.jpg', + linkToFullImage: true + }) + + expect(wrapper.vm.entityId).toBe('test-entity') + expect(wrapper.vm.iconSize).toBe(64) + expect(wrapper.vm.imageUrl).toBe('test-image.jpg') + expect(wrapper.vm.linkToFullImage).toBe(true) + }) + }) + + describe('Icon Generation', () => { + it('should generate image HTML when imageUrl is provided', () => { + wrapper = mountComponent({ imageUrl: 'test-image.jpg' }) + const generatedIcon = wrapper.vm.generateIcon() + + expect(generatedIcon).toContain('