You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
1.6 KiB
72 lines
1.6 KiB
import { describe, expect, it, beforeEach } from 'vitest';
|
|
import type { Morfo } from './types';
|
|
import {
|
|
_resetMorfoRegistryForTesting,
|
|
getRegisteredMorfo,
|
|
listRegisteredMorfos,
|
|
onMorfoRegistered,
|
|
registerMorfo
|
|
} from './registry';
|
|
import { v } from './types';
|
|
|
|
function morfo(kebab = 'sample'): Morfo {
|
|
return {
|
|
name: 'Sample',
|
|
kebab,
|
|
scope: ['soma'],
|
|
texts: {
|
|
label: `#?components.${kebab}.label|Sample`
|
|
},
|
|
parts: [
|
|
{
|
|
name: 'Provider',
|
|
kebab: 'provider',
|
|
kind: 'public',
|
|
defaultElement: 'div',
|
|
optional: false,
|
|
data: [],
|
|
aria: [
|
|
{ attr: 'aria-label', value: v.translationRef(`#?components.${kebab}.label|Sample`) }
|
|
]
|
|
}
|
|
]
|
|
};
|
|
}
|
|
|
|
describe('morfo registry', () => {
|
|
beforeEach(() => {
|
|
_resetMorfoRegistryForTesting();
|
|
});
|
|
|
|
it('compiles and stores the morfo', () => {
|
|
const compiled = registerMorfo(morfo());
|
|
|
|
expect(getRegisteredMorfo('sample')?.compiled).toBe(compiled);
|
|
expect(getRegisteredMorfo('sample')?.morfo.texts?.label).toBe(
|
|
'#?components.sample.label|Sample'
|
|
);
|
|
});
|
|
|
|
it('lists all registered morfos', () => {
|
|
registerMorfo(morfo('alpha'));
|
|
registerMorfo(morfo('beta'));
|
|
|
|
const all = listRegisteredMorfos();
|
|
expect(all.map((r) => r.morfo.kebab).sort()).toEqual(['alpha', 'beta']);
|
|
});
|
|
|
|
it('notifies listeners on first registration', () => {
|
|
const seen: string[] = [];
|
|
const off = onMorfoRegistered((record) => {
|
|
seen.push(record.morfo.kebab);
|
|
});
|
|
|
|
registerMorfo(morfo('gamma'));
|
|
// Re-registering the same kebab does not re-notify listeners.
|
|
registerMorfo(morfo('gamma'));
|
|
|
|
expect(seen).toEqual(['gamma']);
|
|
off();
|
|
});
|
|
});
|