-
Notifications
You must be signed in to change notification settings - Fork 123
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
1 parent
c9eac9c
commit 61f2700
Showing
9 changed files
with
270 additions
and
62 deletions.
There are no files selected for viewing
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
63 changes: 31 additions & 32 deletions
63
apps/frontend/src/components/command/tests/commandModal.spec.ts
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 |
---|---|---|
@@ -1,64 +1,63 @@ | ||
import { beforeEach, describe, expect, it, vi } from 'vitest' | ||
import { computed } from 'vue' | ||
import { useCommandModal } from '../commandModal' | ||
import * as misc from '@/composables/misc' | ||
import { fireEvent, useSetup } from '@/tests/helper' | ||
import * as misc from '@/composables/misc' | ||
|
||
describe('CommandModal', () => { | ||
describe('command modal', () => { | ||
beforeEach(() => { | ||
const { closeCommandModal } = useCommandModal() | ||
closeCommandModal() | ||
}) | ||
|
||
it('should be open command modal', () => { | ||
const { openCommandModal, showCommandModal } = useCommandModal() | ||
|
||
openCommandModal() | ||
|
||
expect(showCommandModal.value).toBe(true) | ||
}) | ||
|
||
it('should be close command modal', () => { | ||
const { openCommandModal, closeCommandModal, showCommandModal } = useCommandModal() | ||
openCommandModal() | ||
const { closeCommandModal, showCommandModal } = useCommandModal() | ||
|
||
closeCommandModal() | ||
|
||
expect(showCommandModal.value).toBe(false) | ||
}) | ||
|
||
describe('KeyboardShortcut', () => { | ||
it('should be open command modal when use command + k on Mac', () => { | ||
vi.spyOn(misc, 'useIsMac').mockImplementation(() => computed(() => true)) | ||
const { registerKeyboardShortcut, showCommandModal } = useCommandModal() | ||
|
||
const { wrapper } = useSetup(() => { | ||
registerKeyboardShortcut() | ||
}) | ||
|
||
fireEvent.keydown({ | ||
key: 'k', | ||
metaKey: true, | ||
}) | ||
it('should be open command modal when press cmd+k on Mac', () => { | ||
vi.spyOn(misc, 'useIsMac').mockReturnValue(computed(() => true)) | ||
const { registerKeyboardShortcut, showCommandModal } = useCommandModal() | ||
|
||
expect(showCommandModal.value).toBe(true) | ||
const { wrapper } = useSetup(() => { | ||
registerKeyboardShortcut() | ||
}) | ||
|
||
wrapper.unmount() | ||
fireEvent.keyDown({ | ||
key: 'k', | ||
metaKey: true, | ||
}) | ||
it('should be open command modal when use ctrl + k on Win', () => { | ||
vi.spyOn(misc, 'useIsMac').mockImplementation(() => computed(() => false)) | ||
const { registerKeyboardShortcut, showCommandModal } = useCommandModal() | ||
|
||
const { wrapper } = useSetup(() => { | ||
registerKeyboardShortcut() | ||
}) | ||
expect(showCommandModal.value).toBe(true) | ||
|
||
wrapper.unmount() | ||
}) | ||
|
||
fireEvent.keydown({ | ||
key: 'k', | ||
ctrlKey: true, | ||
}) | ||
it('should be open command modal when press ctrl+k on Win', () => { | ||
vi.spyOn(misc, 'useIsMac').mockReturnValue(computed(() => false)) | ||
const { registerKeyboardShortcut, showCommandModal } = useCommandModal() | ||
|
||
expect(showCommandModal.value).toBe(true) | ||
const { wrapper } = useSetup(() => { | ||
registerKeyboardShortcut() | ||
}) | ||
|
||
wrapper.unmount() | ||
fireEvent.keyDown({ | ||
key: 'k', | ||
ctrlKey: true, | ||
}) | ||
|
||
expect(showCommandModal.value).toBe(true) | ||
|
||
wrapper.unmount() | ||
}) | ||
}) |
186 changes: 186 additions & 0 deletions
186
apps/frontend/src/components/command/tests/search.new.spec.ts
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,186 @@ | ||
import { beforeAll, beforeEach, describe, expect, it, vi } from 'vitest' | ||
import { createTestingPinia } from '@pinia/testing' | ||
import { useSearch } from '../search' | ||
import { useSearchTasks } from '../searchTasks' | ||
import { useSearchCommands } from '../searchCommands' | ||
import { completeSmartProject, useListProjectsStore, useTasksStore } from '@/store' | ||
import { liveListProject, tasks } from '@/tests/fixture' | ||
import { useCommand } from '@/composables/command' | ||
|
||
describe('search new ', () => { | ||
beforeAll(() => { | ||
const { addCommand } = useCommand() | ||
|
||
addCommand({ | ||
name: '回到主页', | ||
execute() {}, | ||
}) | ||
|
||
addCommand({ | ||
name: '切换皮肤', | ||
execute() {}, | ||
}) | ||
}) | ||
beforeEach(() => { | ||
vi.useFakeTimers() | ||
|
||
createTestingPinia({ | ||
createSpy: vi.fn, | ||
}) | ||
|
||
const tasksStore = useTasksStore() | ||
vi.mocked(tasksStore.findAllTasksNotRemoved).mockImplementation(async () => tasks) | ||
|
||
const listProjectsStore = useListProjectsStore() | ||
vi.mocked(listProjectsStore.findProject).mockImplementation(() => liveListProject) | ||
}) | ||
|
||
describe('ui state', () => { | ||
it('should be loading is true when search is start', async () => { | ||
const { search, loading } = useSearch() | ||
|
||
search.value = '吃饭' | ||
|
||
await vi.advanceTimersToNextTimerAsync() | ||
|
||
expect(loading.value).toBe(true) | ||
}) | ||
|
||
it('should be loading is false when search is complete', async () => { | ||
const { search, loading } = useSearch() | ||
|
||
search.value = '吃饭' | ||
|
||
await vi.runAllTimersAsync() | ||
|
||
expect(loading.value).toBe(false) | ||
}) | ||
|
||
it('should be searching is true when search is complete', async () => { | ||
const { search, searching } = useSearch() | ||
|
||
search.value = '吃饭' | ||
|
||
await vi.runAllTimersAsync() | ||
|
||
expect(searching.value).toBe(true) | ||
}) | ||
}) | ||
|
||
describe('search tasks', () => { | ||
it('should be search a task by title', async () => { | ||
const { search } = useSearch() | ||
const { filteredTasks } = useSearchTasks() | ||
|
||
search.value = '吃饭' | ||
|
||
await vi.runAllTimersAsync() | ||
|
||
expect(filteredTasks.value.length).toBe(1) | ||
const item = filteredTasks.value[0].item | ||
expect(item.title).toBe('吃饭') | ||
expect(item).toHaveProperty('id') | ||
expect(item).toHaveProperty('desc') | ||
expect(item).toHaveProperty('done') | ||
expect(item).toHaveProperty('from') | ||
}) | ||
|
||
it('should be search a task by desc', async () => { | ||
const { search } = useSearch() | ||
const { filteredTasks } = useSearchTasks() | ||
|
||
search.value = '吃什么' | ||
await vi.runAllTimersAsync() | ||
|
||
expect(filteredTasks.value.length).toBe(1) | ||
expect(filteredTasks.value[0].item.title).toBe('吃饭') | ||
}) | ||
|
||
it('should not be found when the task does not exist', async () => { | ||
const { search } = useSearch() | ||
const { filteredTasks } = useSearchTasks() | ||
|
||
search.value = '运动' | ||
await vi.runAllTimersAsync() | ||
|
||
expect(filteredTasks.value.length).toBe(0) | ||
}) | ||
|
||
it('should be task\'s project is listProject when status is active', async () => { | ||
const { search } = useSearch() | ||
const { filteredTasks } = useSearchTasks() | ||
|
||
search.value = '吃饭' | ||
await vi.runAllTimersAsync() | ||
|
||
expect(filteredTasks.value[0].item.done).toBe(false) | ||
expect(filteredTasks.value[0].item.from?.name).toBe('生活') | ||
}) | ||
it('should be task\'s project is completeSmartProject when status is complete', async () => { | ||
const { search } = useSearch() | ||
const { filteredTasks } = useSearchTasks() | ||
|
||
search.value = '写代码' | ||
await vi.runAllTimersAsync() | ||
|
||
expect(filteredTasks.value[0].item.done).toBe(true) | ||
expect(filteredTasks.value[0].item.from?.name).toBe(completeSmartProject.name) | ||
}) | ||
}) | ||
|
||
describe('search commands', () => { | ||
it('normal', async () => { | ||
const { search } = useSearch() | ||
const { filteredCommands } = useSearchCommands() | ||
|
||
search.value = '>主页' | ||
|
||
await vi.runAllTimersAsync() | ||
|
||
expect(filteredCommands.value.length).toBe(1) | ||
expect(filteredCommands.value[0].name).toBe('回到主页') | ||
}) | ||
|
||
it('removes the trailing white space', async () => { | ||
const { search } = useSearch() | ||
const { filteredCommands } = useSearchCommands() | ||
|
||
search.value = '>主页 ' | ||
|
||
await vi.runAllTimersAsync() | ||
|
||
expect(filteredCommands.value.length).toBe(1) | ||
expect(filteredCommands.value[0].name).toBe('回到主页') | ||
}) | ||
|
||
it('should be search all commands ', async () => { | ||
const { search } = useSearch() | ||
const { filteredCommands } = useSearchCommands() | ||
|
||
search.value = '>' | ||
|
||
await vi.runAllTimersAsync() | ||
expect(filteredCommands.value.length).toBe(2) | ||
}) | ||
}) | ||
|
||
it('should be reset when search is empty', async () => { | ||
const { search, searching, loading } = useSearch() | ||
const { filteredTasks } = useSearchTasks() | ||
const { filteredCommands } = useSearchCommands() | ||
|
||
search.value = '吃饭' | ||
await vi.runAllTimersAsync() | ||
|
||
search.value = '>主页' | ||
await vi.runAllTimersAsync() | ||
|
||
search.value = '' | ||
await vi.runAllTimersAsync() | ||
|
||
expect(searching.value).toBe(false) | ||
expect(loading.value).toBe(false) | ||
expect(filteredTasks.value.length).toBe(0) | ||
expect(filteredCommands.value.length).toBe(2) | ||
}) | ||
}) |
48 changes: 19 additions & 29 deletions
48
apps/frontend/src/components/command/tests/searchCommands.spec.ts
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 |
---|---|---|
@@ -1,49 +1,39 @@ | ||
import { afterAll, beforeAll, describe, expect, it } from 'vitest' | ||
import { beforeAll, beforeEach, describe, expect, it } from 'vitest' | ||
import { useSearchCommands } from '../searchCommands' | ||
import { useCommand } from '@/composables/command' | ||
|
||
describe('SearchCommands', () => { | ||
describe('search commands', () => { | ||
beforeEach(() => { | ||
const { resetSearchCommands } = useSearchCommands() | ||
resetSearchCommands() | ||
}) | ||
beforeAll(() => { | ||
const { addCommand } = useCommand() | ||
|
||
const mockCommand = { | ||
name: '前往主页', | ||
addCommand({ | ||
name: '回到主页', | ||
execute() {}, | ||
} | ||
|
||
addCommand(mockCommand) | ||
}) | ||
}) | ||
|
||
afterAll(() => { | ||
const { resetCommand } = useCommand() | ||
resetCommand() | ||
addCommand({ | ||
name: '切换皮肤', | ||
execute() {}, | ||
}) | ||
}) | ||
|
||
it('Should search for the go to home command', () => { | ||
it('should be search a command', () => { | ||
const { searchCommands, filteredCommands } = useSearchCommands() | ||
searchCommands('前往主页') | ||
|
||
expect(filteredCommands.value.length).toBe(1) | ||
expect(filteredCommands.value[0].name).toBe('前往主页') | ||
}) | ||
|
||
it('should be reset filtered commands', () => { | ||
const { commands } = useCommand() | ||
const { resetSearchCommands, searchCommands, filteredCommands } = useSearchCommands() | ||
|
||
searchCommands('前往主页') | ||
searchCommands('主页') | ||
|
||
resetSearchCommands() | ||
|
||
expect(filteredCommands.value.length).toBe(commands.length) | ||
expect(filteredCommands.value.length).toBe(1) | ||
expect(filteredCommands.value[0].name).toBe('回到主页') | ||
}) | ||
|
||
it('should return all commands when input is empty', () => { | ||
const { commands } = useCommand() | ||
it('should be search all commands ', () => { | ||
const { searchCommands, filteredCommands } = useSearchCommands() | ||
|
||
searchCommands('') | ||
|
||
expect(filteredCommands.value.length).toBe(commands.length) | ||
expect(filteredCommands.value.length).toBe(2) | ||
}) | ||
}) |
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,2 @@ | ||
export * from './tasks' | ||
export * from './listProject' |
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,8 @@ | ||
import type { ListProject } from '@/store' | ||
import { TasksSelectorType } from '@/store' | ||
|
||
export const liveListProject: ListProject = { | ||
id: '1', | ||
name: '生活', | ||
type: TasksSelectorType.listProject, | ||
} |
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,20 @@ | ||
import { TaskStatus } from '@/store' | ||
|
||
export const tasks = [ | ||
{ | ||
id: '0', | ||
title: '吃饭', | ||
content: '今天吃什么', | ||
status: TaskStatus.ACTIVE, | ||
projectId: '1', | ||
position: 1, | ||
}, | ||
{ | ||
id: '1', | ||
title: '写代码', | ||
content: '今天写代码了嘛', | ||
status: TaskStatus.COMPLETED, | ||
projectId: '1', | ||
position: 2, | ||
}, | ||
] |
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
Oops, something went wrong.
61f2700
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
vue3-dida – ./
vue3-dida-cuixueshe.vercel.app
dida.cuixueshe.com
vue3-dida-eta.vercel.app
vue3-dida-git-main-cuixueshe.vercel.app