-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
385 additions
and
27 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
|
||
import { vi, beforeEach, expect, test } from 'vitest' | ||
import { mount } from '@vue/test-utils' | ||
import Commands from '../../src/screens/Commands.vue' | ||
import defaults from '../../defaults/settings.json' | ||
|
||
window.api = { | ||
config: { | ||
load: vi.fn(() => defaults), | ||
}, | ||
commands: { | ||
load: vi.fn(() => [ | ||
{ id: 1, icon: '1', label: 'Command 1', shortcut: '1', action: 'chat_window', state: 'enabled' }, | ||
{ id: 2, icon: '2', label: 'Command 2', shortcut: '2', action: 'paste_below', state: 'enabled' }, | ||
{ id: 3, icon: '3', label: 'Command 3', shortcut: '3', action: 'paste_in_place', state: 'enabled' }, | ||
{ id: 4, icon: '4', label: 'Command 4', shortcut: '4', action: 'clipboard_copy', state: 'enabled' }, | ||
{ id: 5, icon: '5', label: 'Command 5', shortcut: '5', action: 'chat_window', state: 'disabled' }, | ||
]), | ||
run: vi.fn(), | ||
cancel: vi.fn(), | ||
closePalette: vi.fn(), | ||
} | ||
} | ||
|
||
beforeEach(() => { | ||
vi.clearAllMocks() | ||
}) | ||
|
||
test('Renders correctly', () => { | ||
const wrapper = mount(Commands) | ||
expect(wrapper.exists()).toBe(true) | ||
expect(wrapper.find('.commands').exists()).toBe(true) | ||
expect(wrapper.findAll('.command')).toHaveLength(4) | ||
|
||
for (let i=0; i<4; i++) { | ||
const command = wrapper.findAll('.command').at(i) | ||
expect(command.find('.icon').text()).toBe(`${i+1}`) | ||
expect(command.find('.label').text()).toBe(`Command ${i+1}`) | ||
} | ||
}) | ||
|
||
// test('Closes on Escape', async () => { | ||
// const wrapper = mount(Commands) | ||
// await wrapper.trigger('keyup', { key: 'Escape' }) | ||
// expect(window.api.commands.closePalette).toHaveBeenCalled() | ||
// }) | ||
|
||
test('Runs command on click', async () => { | ||
const wrapper = mount(Commands, { props: { extra: { textId: 6 }}}) | ||
const command = wrapper.findAll('.command').at(0) | ||
await command.trigger('click') | ||
expect(window.api.commands.run).toHaveBeenCalledWith({ | ||
command: { | ||
action: 'chat_window', | ||
icon: '1', | ||
id: 1, | ||
shortcut: '1', | ||
label: 'Command 1', | ||
state: 'enabled', | ||
}, | ||
textId: 6, | ||
}) | ||
}) | ||
|
||
// test('Runs command on shortcut', async () => { | ||
// const wrapper = mount(Commands, { props: { extra: { textId: 6 }}}) | ||
// await wrapper.trigger('keyup', { key: '2' }) | ||
// expect(window.api.commands.run).toHaveBeenCalledWith({ | ||
// command: { | ||
// action: 'paste_below', | ||
// icon: '2', | ||
// id: 2, | ||
// shortcut: '2', | ||
// label: 'Command 2', | ||
// state: 'enabled', | ||
// }, | ||
// textId: 6, | ||
// }) | ||
// }) | ||
|
||
// test('Uses chat on shift', async () => { | ||
// const wrapper = mount(Commands, { props: { extra: { textId: 6 }}}) | ||
// await wrapper.trigger('keyup', { key: '3', shiftKey: true}) | ||
// expect(window.api.commands.run).toHaveBeenCalledWith({ | ||
// command: { | ||
// action: 'chat_window', | ||
// icon: '3', | ||
// id: 3, | ||
// shortcut: '3', | ||
// label: 'Command 3', | ||
// state: 'enabled', | ||
// }, | ||
// textId: 6, | ||
// }) | ||
|
||
// }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
|
||
import { vi, beforeEach, expect, test } from 'vitest' | ||
import { mount } from '@vue/test-utils' | ||
import { store } from '../../src/services/store' | ||
import Main from '../../src/screens/Main.vue' | ||
import Sidebar from '../../src/components/Sidebar.vue' | ||
import ChatArea from '../../src/components/ChatArea.vue' | ||
import Settings from '../../src/screens/Settings.vue' | ||
import defaults from '../../defaults/settings.json' | ||
import * as _Assistant from '../../src/services/assistant' | ||
|
||
import useEventBus from '../../src/composables/useEventBus' | ||
const { emitEvent } = useEventBus() | ||
|
||
window.api = { | ||
config: { | ||
load: vi.fn(() => defaults), | ||
}, | ||
commands: { | ||
load: vi.fn(() => []), | ||
}, | ||
prompts: { | ||
load: vi.fn(() => []), | ||
}, | ||
history: { | ||
load: vi.fn(() => []), | ||
}, | ||
on: vi.fn(), | ||
} | ||
|
||
vi.mock('../../src/services/assistant', async () => { | ||
const Assistant = vi.fn() | ||
Assistant.prototype.setChat = vi.fn() | ||
Assistant.prototype.initLlm = vi.fn() | ||
Assistant.prototype.hasLlm = vi.fn(() => true) | ||
Assistant.prototype.prompt = vi.fn() | ||
Assistant.prototype.stop = vi.fn() | ||
return { default: Assistant } | ||
}) | ||
|
||
beforeEach(() => { | ||
vi.clearAllMocks() | ||
}) | ||
|
||
test('Renders correctly', () => { | ||
const wrapper = mount(Main) | ||
expect(wrapper.exists()).toBe(true) | ||
expect(wrapper.find('.main').exists()).toBe(true) | ||
expect(wrapper.findComponent(Sidebar).exists()).toBe(true) | ||
expect(wrapper.findComponent(ChatArea).exists()).toBe(true) | ||
expect(wrapper.findComponent(Settings).exists()).toBe(true) | ||
}) | ||
|
||
test('Resets assistant', async () => { | ||
mount(Main) | ||
emitEvent('newChat') | ||
expect(_Assistant.default.prototype.setChat).toHaveBeenCalledWith(null) | ||
}) | ||
|
||
test('Attach/Detach file', async () => { | ||
mount(Main) | ||
expect(store.pendingAttachment).toBeNull() | ||
emitEvent('attachFile', 'file') | ||
expect(store.pendingAttachment).toBe('file') | ||
emitEvent('detachFile') | ||
expect(store.pendingAttachment).toBeNull() | ||
}) | ||
|
||
test('Sends prompt', async () => { | ||
mount(Main) | ||
emitEvent('sendPrompt', 'prompt') | ||
expect(_Assistant.default.prototype.initLlm).toHaveBeenCalled() | ||
expect(_Assistant.default.prototype.prompt).toHaveBeenCalledWith('prompt', { attachment: null }, expect.any(Function)) | ||
}) | ||
|
||
test('Sends prompt with attachment', async () => { | ||
mount(Main) | ||
emitEvent('attachFile', 'file') | ||
expect(store.pendingAttachment).toBe('file') | ||
emitEvent('sendPrompt', 'prompt') | ||
expect(_Assistant.default.prototype.initLlm).toHaveBeenCalled() | ||
expect(_Assistant.default.prototype.prompt).toHaveBeenCalledWith('prompt', { attachment: 'file' }, expect.any(Function)) | ||
}) | ||
|
||
test('Stop assistant', async () => { | ||
mount(Main) | ||
emitEvent('stopAssistant') | ||
expect(_Assistant.default.prototype.stop).toHaveBeenCalled() | ||
}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
|
||
import { vi, beforeEach, expect, test } from 'vitest' | ||
import { mount } from '@vue/test-utils' | ||
import Prompt from '../../src/components/Prompt.vue' | ||
import PromptAnywhere from '../../src/screens/PromptAnywhere.vue' | ||
import defaults from '../../defaults/settings.json' | ||
|
||
import useEventBus from '../../src/composables/useEventBus' | ||
const { emitEvent } = useEventBus() | ||
|
||
window.api = { | ||
config: { | ||
load: vi.fn(() => defaults), | ||
}, | ||
anywhere: { | ||
prompt: vi.fn(), | ||
cancel: vi.fn(), | ||
resize: vi.fn(), | ||
}, | ||
} | ||
|
||
beforeEach(() => { | ||
vi.clearAllMocks() | ||
}) | ||
|
||
test('Renders correctly', () => { | ||
const wrapper = mount(PromptAnywhere) | ||
expect(wrapper.exists()).toBe(true) | ||
expect(wrapper.find('.anywhere').exists()).toBe(true) | ||
expect(wrapper.findComponent(Prompt).exists()).toBe(true) | ||
}) | ||
|
||
// test('Closes on Escape', async () => { | ||
// const wrapper = mount(PromptAnywhere) | ||
// await wrapper.trigger('keyup', { key: 'Escape' }) | ||
// expect(window.api.anywhere.cancel).toHaveBeenCalled() | ||
// }) | ||
|
||
test('Prompts on Enter', async () => { | ||
const wrapper = mount(PromptAnywhere) | ||
emitEvent('sendPrompt', 'prompt') | ||
expect(window.api.anywhere.prompt).toHaveBeenCalled() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
|
||
import { vi, expect, test } from 'vitest' | ||
import { mount } from '@vue/test-utils' | ||
import Wait from '../../src/screens/Wait.vue' | ||
|
||
window.api = { | ||
commands: { | ||
cancel: vi.fn() | ||
}, | ||
anywhere: { | ||
cancel: vi.fn() | ||
} | ||
} | ||
|
||
test('Renders correctly', () => { | ||
const wrapper = mount(Wait) | ||
expect(wrapper.exists()).toBe(true) | ||
expect(wrapper.find('.wait').exists()).toBe(true) | ||
expect(wrapper.find('.loader').exists()).toBe(true) | ||
expect(wrapper.find('.cancel').exists()).toBe(true) | ||
expect(wrapper.find('.loader').isVisible()).toBe(true) | ||
expect(wrapper.find('.cancel').isVisible()).toBe(false) | ||
}) | ||
|
||
test('Toggles cancel Button', async () => { | ||
const wrapper = mount(Wait) | ||
await wrapper.find('.wait').trigger('mouseenter') | ||
expect(wrapper.find('.loader').isVisible()).toBe(false) | ||
expect(wrapper.find('.cancel').isVisible()).toBe(true) | ||
await wrapper.find('.wait').trigger('mouseleave') | ||
expect(wrapper.find('.loader').isVisible()).toBe(true) | ||
expect(wrapper.find('.cancel').isVisible()).toBe(false) | ||
}) | ||
|
||
test('Cancels command', () => { | ||
const wrapper = mount(Wait) | ||
wrapper.find('.cancel').trigger('click') | ||
expect(window.api.commands.cancel).toHaveBeenCalled() | ||
expect(window.api.anywhere.cancel).toHaveBeenCalled() | ||
}) |
Oops, something went wrong.