-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
12 changed files
with
291 additions
and
177 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
121 changes: 121 additions & 0 deletions
121
packages/frontend/core/src/components/pure/cmdk/__tests__/filter-commands.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,121 @@ | ||
/** | ||
* @vitest-environment happy-dom | ||
*/ | ||
import { describe, expect, test } from 'vitest'; | ||
|
||
import { filterSortAndGroupCommands } from '../filter-commands'; | ||
import type { CMDKCommand } from '../types'; | ||
|
||
const commands: CMDKCommand[] = ( | ||
[ | ||
{ | ||
id: 'affine:goto-all-pages', | ||
category: 'affine:navigation', | ||
label: { title: 'Go to All Pages' }, | ||
}, | ||
{ | ||
id: 'affine:goto-page-list', | ||
category: 'affine:navigation', | ||
label: { title: 'Go to Page List' }, | ||
}, | ||
{ | ||
id: 'affine:new-page', | ||
category: 'affine:creation', | ||
alwaysShow: true, | ||
label: { title: 'New Page' }, | ||
}, | ||
{ | ||
id: 'affine:new-edgeless-page', | ||
category: 'affine:creation', | ||
alwaysShow: true, | ||
label: { title: 'New Edgeless' }, | ||
}, | ||
{ | ||
id: 'affine:pages.foo', | ||
category: 'affine:pages', | ||
label: { title: 'New Page', subTitle: 'foo' }, | ||
}, | ||
{ | ||
id: 'affine:pages.bar', | ||
category: 'affine:pages', | ||
label: { title: 'New Page', subTitle: 'bar' }, | ||
}, | ||
] as const | ||
).map(c => { | ||
return { | ||
...c, | ||
run: () => {}, | ||
}; | ||
}); | ||
|
||
describe('filterSortAndGroupCommands', () => { | ||
function defineTest( | ||
name: string, | ||
query: string, | ||
expected: [string, string[]][] | ||
) { | ||
test(name, () => { | ||
// Call the function | ||
const result = filterSortAndGroupCommands(commands, query); | ||
const sortedIds = result.map(([category, commands]) => { | ||
return [category, commands.map(command => command.id)]; | ||
}); | ||
|
||
console.log(JSON.stringify(sortedIds)); | ||
|
||
// Assert the result | ||
expect(sortedIds).toEqual(expected); | ||
}); | ||
} | ||
|
||
defineTest('without query', '', [ | ||
['affine:navigation', ['affine:goto-all-pages', 'affine:goto-page-list']], | ||
['affine:creation', ['affine:new-page', 'affine:new-edgeless-page']], | ||
['affine:pages', ['affine:pages.foo', 'affine:pages.bar']], | ||
]); | ||
|
||
defineTest('with query = a', 'a', [ | ||
[ | ||
'affine:results', | ||
[ | ||
'affine:goto-all-pages', | ||
'affine:pages.foo', | ||
'affine:pages.bar', | ||
'affine:new-page', | ||
'affine:new-edgeless-page', | ||
'affine:goto-page-list', | ||
], | ||
], | ||
]); | ||
|
||
defineTest('with query = nepa', 'nepa', [ | ||
[ | ||
'affine:results', | ||
[ | ||
'affine:pages.foo', | ||
'affine:pages.bar', | ||
'affine:new-page', | ||
'affine:new-edgeless-page', | ||
], | ||
], | ||
]); | ||
|
||
defineTest('with query = new', 'new', [ | ||
[ | ||
'affine:results', | ||
[ | ||
'affine:pages.foo', | ||
'affine:pages.bar', | ||
'affine:new-page', | ||
'affine:new-edgeless-page', | ||
], | ||
], | ||
]); | ||
|
||
defineTest('with query = foo', 'foo', [ | ||
[ | ||
'affine:results', | ||
['affine:pages.foo', 'affine:new-page', 'affine:new-edgeless-page'], | ||
], | ||
]); | ||
}); |
2 changes: 1 addition & 1 deletion
2
...src/hooks/__tests__/use-highlight.spec.ts → ...pure/cmdk/__tests__/use-highlight.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
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.