mirror of
https://github.com/strapi/strapi.git
synced 2025-11-15 17:49:57 +00:00
Add tests
This commit is contained in:
parent
cb10c9a81a
commit
1931224373
@ -438,7 +438,60 @@ describe('Attributes', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO custom field
|
describe('Custom field', () => {
|
||||||
|
test('No custom field', () => {
|
||||||
|
const attribute = {};
|
||||||
|
const modifiers = getAttributeModifiers(attribute);
|
||||||
|
|
||||||
|
expect(modifiers).toHaveLength(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Basic custom field', () => {
|
||||||
|
const attribute = {
|
||||||
|
type: 'customField',
|
||||||
|
customField: 'plugin::color-picker.color',
|
||||||
|
};
|
||||||
|
const modifiers = getAttributeModifiers(attribute);
|
||||||
|
|
||||||
|
expect(modifiers).toHaveLength(1);
|
||||||
|
expect(modifiers[0].kind).toBe(ts.SyntaxKind.TypeReference);
|
||||||
|
expect(modifiers[0].typeName.escapedText).toBe('CustomField');
|
||||||
|
expect(modifiers[0].typeArguments).toHaveLength(1);
|
||||||
|
expect(modifiers[0].typeArguments[0].kind).toBe(ts.SyntaxKind.StringLiteral);
|
||||||
|
expect(modifiers[0].typeArguments[0].text).toBe('plugin::color-picker.color');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Advanced custom field', () => {
|
||||||
|
const attribute = {
|
||||||
|
type: 'customField',
|
||||||
|
customField: 'plugin::color-picker.color',
|
||||||
|
options: {
|
||||||
|
format: 'hex',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
const modifiers = getAttributeModifiers(attribute);
|
||||||
|
|
||||||
|
expect(modifiers).toHaveLength(1);
|
||||||
|
expect(modifiers[0].kind).toBe(ts.SyntaxKind.TypeReference);
|
||||||
|
expect(modifiers[0].typeName.escapedText).toBe('CustomField');
|
||||||
|
expect(modifiers[0].typeArguments).toHaveLength(2);
|
||||||
|
expect(modifiers[0].typeArguments[0].kind).toBe(ts.SyntaxKind.StringLiteral);
|
||||||
|
expect(modifiers[0].typeArguments[0].text).toBe('plugin::color-picker.color');
|
||||||
|
expect(modifiers[0].typeArguments[1].kind).toBe(ts.SyntaxKind.TypeLiteral);
|
||||||
|
expect(modifiers[0].typeArguments[1].members).toHaveLength(1);
|
||||||
|
expect(modifiers[0].typeArguments[1].members[0].kind).toBe(
|
||||||
|
ts.SyntaxKind.PropertyDeclaration
|
||||||
|
);
|
||||||
|
expect(modifiers[0].typeArguments[1].members[0].name.escapedText).toBe('format');
|
||||||
|
expect(modifiers[0].typeArguments[1].members[0].kind).toBe(
|
||||||
|
ts.SyntaxKind.PropertyDeclaration
|
||||||
|
);
|
||||||
|
expect(modifiers[0].typeArguments[1].members[0].type.kind).toBe(
|
||||||
|
ts.SyntaxKind.StringLiteral
|
||||||
|
);
|
||||||
|
expect(modifiers[0].typeArguments[1].members[0].type.text).toBe('hex');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('Plugin Options', () => {
|
describe('Plugin Options', () => {
|
||||||
test('No plugin options', () => {
|
test('No plugin options', () => {
|
||||||
|
|||||||
@ -75,14 +75,14 @@ const getAttributeModifiers = (attribute) => {
|
|||||||
addImport('CustomField');
|
addImport('CustomField');
|
||||||
|
|
||||||
const customFieldUid = factory.createStringLiteral(attribute.customField);
|
const customFieldUid = factory.createStringLiteral(attribute.customField);
|
||||||
const typeParams = [customFieldUid];
|
const typeArguments = [customFieldUid];
|
||||||
|
|
||||||
if (attribute.options) {
|
if (attribute.options) {
|
||||||
typeParams.push(toTypeLiteral(attribute.options));
|
typeArguments.push(toTypeLiteral(attribute.options));
|
||||||
}
|
}
|
||||||
|
|
||||||
modifiers.push(
|
modifiers.push(
|
||||||
factory.createTypeReferenceNode(factory.createIdentifier('CustomField'), typeParams)
|
factory.createTypeReferenceNode(factory.createIdentifier('CustomField'), typeArguments)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user