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