philomena/assets/js/utils/__tests__/suggestion-model.spec.ts

64 lines
1.3 KiB
TypeScript
Raw Normal View History

import { prefixMatchParts } from '../suggestions-model.ts';
describe('prefixMatchParts', () => {
it('separates the prefix from the plain tag', () => {
expect(prefixMatchParts('foobar', 'foo')).toMatchInlineSnapshot(`
[
{
"matched": "foo",
},
"bar",
]
`);
});
it('separates the prefix from the namespaced tag', () => {
expect(prefixMatchParts('bruh:bar', 'bru')).toMatchInlineSnapshot(`
[
{
"matched": "bru",
},
"h:bar",
]
`);
});
it('separates the prefix after the namespace', () => {
expect(prefixMatchParts('foo:bazz', 'baz')).toMatchInlineSnapshot(`
[
"foo:",
{
"matched": "baz",
},
"z",
]
`);
});
2025-03-17 23:21:54 +00:00
it(`should ignore case when matching`, () => {
expect(prefixMatchParts('FOObar', 'foo')).toMatchInlineSnapshot(`
[
{
"matched": "FOO",
},
"bar",
]
`);
});
it(`should skip empty parts`, () => {
expect(prefixMatchParts('foo', 'foo')).toMatchInlineSnapshot(`
[
{
"matched": "foo",
},
]
`);
expect(prefixMatchParts('foo', 'bar')).toMatchInlineSnapshot(`
[
"foo",
]
`);
});
});