Add component tests for ModalHeader, IconChecked, and Conformance result components

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-05 19:45:30 +08:00
parent fa58e665d5
commit 676b70caa0
5 changed files with 230 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
import { describe, it, expect } from 'vitest';
import { mount } from '@vue/test-utils';
import IconChecked from '@/components/icons/IconChecked.vue';
describe('IconChecked', () => {
it('shows gray frame when not checked', () => {
const wrapper = mount(IconChecked, {
props: { isChecked: false },
});
const imgs = wrapper.findAll('img[alt="checkbox"]');
// When not checked: gray frame visible, blue frame hidden, check mark hidden
expect(imgs.length).toBe(1);
});
it('shows blue frame and check mark when checked', () => {
const wrapper = mount(IconChecked, {
props: { isChecked: true },
});
const imgs = wrapper.findAll('img[alt="checkbox"]');
// When checked: blue frame + check mark visible (2 imgs), gray frame hidden
expect(imgs.length).toBe(2);
});
it('updates rendering when isChecked prop changes', async () => {
const wrapper = mount(IconChecked, {
props: { isChecked: false },
});
expect(wrapper.findAll('img[alt="checkbox"]').length).toBe(1);
await wrapper.setProps({ isChecked: true });
expect(wrapper.findAll('img[alt="checkbox"]').length).toBe(2);
});
});

View File

@@ -0,0 +1,46 @@
import { describe, it, expect, beforeEach, vi } from 'vitest';
import { mount } from '@vue/test-utils';
import { setActivePinia, createPinia } from 'pinia';
import ModalHeader from '@/views/AccountManagement/ModalHeader.vue';
import { useModalStore } from '@/stores/modal.js';
describe('ModalHeader', () => {
let pinia;
beforeEach(() => {
pinia = createPinia();
setActivePinia(pinia);
});
const mountModalHeader = (headerText = 'Test Header') => {
return mount(ModalHeader, {
props: { headerText },
global: { plugins: [pinia] },
});
};
it('renders header text from prop', () => {
const wrapper = mountModalHeader('Account Info');
expect(wrapper.find('h1').text()).toBe('Account Info');
});
it('renders close button (X icon)', () => {
const wrapper = mountModalHeader();
const img = wrapper.find('img[alt="X"]');
expect(img.exists()).toBe(true);
});
it('calls closeModal when X is clicked', async () => {
const wrapper = mountModalHeader();
const store = useModalStore();
store.isModalOpen = true;
store.whichModal = 'SOME_MODAL';
const img = wrapper.find('img[alt="X"]');
await img.trigger('click');
// closeModal only sets isModalOpen to false; whichModal is not reset
expect(store.isModalOpen).toBe(false);
expect(store.whichModal).toBe('SOME_MODAL');
});
});

View File

@@ -0,0 +1,39 @@
import { describe, it, expect } from 'vitest';
import { mount } from '@vue/test-utils';
import ResultArrow from '@/components/Discover/Conformance/ConformanceSidebar/ResultArrow.vue';
describe('ResultArrow', () => {
it('renders list items from data prop', () => {
const wrapper = mount(ResultArrow, {
props: {
data: ['Activity A', 'Activity B', 'Activity C'],
select: null,
},
});
const items = wrapper.findAll('li');
expect(items.length).toBe(3);
expect(items[0].text()).toContain('Activity A');
expect(items[1].text()).toContain('Activity B');
expect(items[2].text()).toContain('Activity C');
});
it('renders empty list when data is null', () => {
const wrapper = mount(ResultArrow, {
props: { data: null, select: null },
});
const items = wrapper.findAll('li');
expect(items.length).toBe(0);
});
it('renders arrow_circle_down icon for each item', () => {
const wrapper = mount(ResultArrow, {
props: {
data: ['Task 1'],
select: null,
},
});
expect(wrapper.find('span.material-symbols-outlined').text()).toContain(
'arrow_circle_down',
);
});
});

View File

@@ -0,0 +1,61 @@
import { describe, it, expect } from 'vitest';
import { mount } from '@vue/test-utils';
import ResultCheck from '@/components/Discover/Conformance/ConformanceSidebar/ResultCheck.vue';
// Mock $emitter to prevent errors
const mockEmitter = { on: () => {}, emit: () => {} };
describe('ResultCheck', () => {
const mountResultCheck = (props = {}) => {
return mount(ResultCheck, {
props: {
data: null,
select: null,
...props,
},
global: {
mocks: {
$emitter: mockEmitter,
},
},
});
};
it('renders list from select prop on creation', () => {
const wrapper = mountResultCheck({
select: ['Activity X', 'Activity Y'],
});
const items = wrapper.findAll('li');
expect(items.length).toBe(2);
expect(items[0].text()).toContain('Activity X');
expect(items[1].text()).toContain('Activity Y');
});
it('renders empty when select is null', () => {
const wrapper = mountResultCheck({ select: null });
const items = wrapper.findAll('li');
expect(items.length).toBe(0);
});
it('renders check_circle icon for each item', () => {
const wrapper = mountResultCheck({ select: ['Task 1'] });
expect(wrapper.find('span.material-symbols-outlined').text()).toContain(
'check_circle',
);
});
it('updates list when data prop changes', async () => {
const wrapper = mountResultCheck({ select: ['Initial'] });
expect(wrapper.findAll('li').length).toBe(1);
await wrapper.setProps({ data: ['New A', 'New B'] });
expect(wrapper.findAll('li').length).toBe(2);
expect(wrapper.text()).toContain('New A');
});
it('updates list when select prop changes', async () => {
const wrapper = mountResultCheck({ select: ['Old'] });
await wrapper.setProps({ select: ['Changed'] });
expect(wrapper.text()).toContain('Changed');
});
});

View File

@@ -0,0 +1,51 @@
import { describe, it, expect } from 'vitest';
import { mount } from '@vue/test-utils';
import ResultDot from '@/components/Discover/Conformance/ConformanceSidebar/ResultDot.vue';
// Mock $emitter to prevent errors
const mockEmitter = { on: () => {}, emit: () => {} };
describe('ResultDot', () => {
const mountResultDot = (props = {}) => {
return mount(ResultDot, {
props: {
timeResultData: null,
select: null,
...props,
},
global: {
mocks: {
$emitter: mockEmitter,
},
},
});
};
it('renders list from select prop on creation', () => {
const data = [
{ category: 'Start', task: 'Task A' },
{ category: 'End', task: 'Task B' },
];
const wrapper = mountResultDot({ select: data });
const items = wrapper.findAll('li');
expect(items.length).toBe(2);
expect(items[0].text()).toContain('Start');
expect(items[0].text()).toContain('Task A');
});
it('renders empty when select is null', () => {
const wrapper = mountResultDot({ select: null });
const items = wrapper.findAll('li');
expect(items.length).toBe(0);
});
it('updates list when timeResultData prop changes', async () => {
const wrapper = mountResultDot({ select: null });
expect(wrapper.findAll('li').length).toBe(0);
const newData = [{ category: 'Mid', task: 'Task C' }];
await wrapper.setProps({ timeResultData: newData });
expect(wrapper.findAll('li').length).toBe(1);
expect(wrapper.text()).toContain('Task C');
});
});