🎨 Simplify import formatting and improve code readability in unit tests for GamemasterExplorer component

This commit is contained in:
2026-01-29 05:05:47 +00:00
parent dbf60a4860
commit e55740782e

View File

@@ -105,9 +105,8 @@ describe('GamemasterExplorer', () => {
}); });
it('shows loading state when isLoading is true', async () => { it('shows loading state when isLoading is true', async () => {
const { useGamemasterFiles } = await import( const { useGamemasterFiles } =
'../../../src/composables/useGamemasterFiles.js' await import('../../../src/composables/useGamemasterFiles.js');
);
useGamemasterFiles.mockReturnValueOnce({ useGamemasterFiles.mockReturnValueOnce({
selectedFile: ref(''), selectedFile: ref(''),
fileContent: ref(''), fileContent: ref(''),
@@ -127,9 +126,8 @@ describe('GamemasterExplorer', () => {
}); });
it('shows error state when fileError exists', async () => { it('shows error state when fileError exists', async () => {
const { useGamemasterFiles } = await import( const { useGamemasterFiles } =
'../../../src/composables/useGamemasterFiles.js' await import('../../../src/composables/useGamemasterFiles.js');
);
useGamemasterFiles.mockReturnValueOnce({ useGamemasterFiles.mockReturnValueOnce({
selectedFile: ref(''), selectedFile: ref(''),
fileContent: ref(''), fileContent: ref(''),
@@ -149,9 +147,8 @@ describe('GamemasterExplorer', () => {
}); });
it('shows no files state when hasFiles is false', async () => { it('shows no files state when hasFiles is false', async () => {
const { useGamemasterFiles } = await import( const { useGamemasterFiles } =
'../../../src/composables/useGamemasterFiles.js' await import('../../../src/composables/useGamemasterFiles.js');
);
useGamemasterFiles.mockReturnValueOnce({ useGamemasterFiles.mockReturnValueOnce({
selectedFile: ref(''), selectedFile: ref(''),
fileContent: ref(''), fileContent: ref(''),
@@ -179,45 +176,47 @@ describe('GamemasterExplorer', () => {
it('includes all child components', () => { it('includes all child components', () => {
const wrapper = mount(GamemasterExplorer); const wrapper = mount(GamemasterExplorer);
// Check for FileSelector component // Check for FileSelector component
expect(wrapper.findComponent({ name: 'FileSelector' }).exists()).toBe(true); expect(wrapper.findComponent({ name: 'FileSelector' }).exists()).toBe(true);
// Check for SearchBar component // Check for SearchBar component
expect(wrapper.findComponent({ name: 'SearchBar' }).exists()).toBe(true); expect(wrapper.findComponent({ name: 'SearchBar' }).exists()).toBe(true);
// Check for FilterPanel component // Check for FilterPanel component
expect(wrapper.findComponent({ name: 'FilterPanel' }).exists()).toBe(true); expect(wrapper.findComponent({ name: 'FilterPanel' }).exists()).toBe(true);
// Check for JsonViewer component // Check for JsonViewer component
expect(wrapper.findComponent({ name: 'JsonViewer' }).exists()).toBe(true); expect(wrapper.findComponent({ name: 'JsonViewer' }).exists()).toBe(true);
// Check for ActionToolbar component // Check for ActionToolbar component
expect(wrapper.findComponent({ name: 'ActionToolbar' }).exists()).toBe(true); expect(wrapper.findComponent({ name: 'ActionToolbar' }).exists()).toBe(
true
);
}); });
it('toggles help panel', async () => { it('toggles help panel', async () => {
const wrapper = mount(GamemasterExplorer); const wrapper = mount(GamemasterExplorer);
expect(wrapper.find('.help-panel').exists()).toBe(false); expect(wrapper.find('.help-panel').exists()).toBe(false);
// Click help button // Click help button
const helpButton = wrapper.findAll('.btn-icon')[0]; const helpButton = wrapper.findAll('.btn-icon')[0];
await helpButton.trigger('click'); await helpButton.trigger('click');
expect(wrapper.find('.help-panel').exists()).toBe(true); expect(wrapper.find('.help-panel').exists()).toBe(true);
expect(wrapper.text()).toContain('Keyboard Shortcuts'); expect(wrapper.text()).toContain('Keyboard Shortcuts');
}); });
it('toggles settings panel', async () => { it('toggles settings panel', async () => {
const wrapper = mount(GamemasterExplorer); const wrapper = mount(GamemasterExplorer);
expect(wrapper.find('.settings-panel').exists()).toBe(false); expect(wrapper.find('.settings-panel').exists()).toBe(false);
// Click settings button // Click settings button
const settingsButton = wrapper.findAll('.btn-icon')[1]; const settingsButton = wrapper.findAll('.btn-icon')[1];
await settingsButton.trigger('click'); await settingsButton.trigger('click');
expect(wrapper.find('.settings-panel').exists()).toBe(true); expect(wrapper.find('.settings-panel').exists()).toBe(true);
expect(wrapper.text()).toContain('Settings'); expect(wrapper.text()).toContain('Settings');
}); });
@@ -225,15 +224,14 @@ describe('GamemasterExplorer', () => {
it('has back to home link', () => { it('has back to home link', () => {
const wrapper = mount(GamemasterExplorer); const wrapper = mount(GamemasterExplorer);
const backLink = wrapper.find('.back-button'); const backLink = wrapper.find('.back-button');
expect(backLink.exists()).toBe(true); expect(backLink.exists()).toBe(true);
expect(backLink.attributes('to')).toBe('/'); expect(backLink.attributes('to')).toBe('/');
}); });
it('calls loadStatus on mount', async () => { it('calls loadStatus on mount', async () => {
const { useGamemasterFiles } = await import( const { useGamemasterFiles } =
'../../../src/composables/useGamemasterFiles.js' await import('../../../src/composables/useGamemasterFiles.js');
);
const mockLoadStatus = vi.fn(); const mockLoadStatus = vi.fn();
useGamemasterFiles.mockReturnValueOnce({ useGamemasterFiles.mockReturnValueOnce({
selectedFile: ref(''), selectedFile: ref(''),
@@ -249,23 +247,22 @@ describe('GamemasterExplorer', () => {
}); });
mount(GamemasterExplorer); mount(GamemasterExplorer);
// loadStatus should be called on mount // loadStatus should be called on mount
expect(mockLoadStatus).toHaveBeenCalled(); expect(mockLoadStatus).toHaveBeenCalled();
}); });
it('computes filterData from fileContent', () => { it('computes filterData from fileContent', () => {
const wrapper = mount(GamemasterExplorer); const wrapper = mount(GamemasterExplorer);
// Component should parse JSON content for filtering // Component should parse JSON content for filtering
const filterData = wrapper.vm.filterData; const filterData = wrapper.vm.filterData;
expect(filterData).toBeDefined(); expect(filterData).toBeDefined();
}); });
it('displays toast messages for clipboard operations', async () => { it('displays toast messages for clipboard operations', async () => {
const { useClipboard } = await import( const { useClipboard } =
'../../../src/composables/useClipboard.js' await import('../../../src/composables/useClipboard.js');
);
useClipboard.mockReturnValueOnce({ useClipboard.mockReturnValueOnce({
copied: ref(true), copied: ref(true),
error: ref(null), error: ref(null),