This commit is contained in:
75
node_modules/decap-cms-editor-component-image/src/__tests__/index.spec.js
generated
vendored
Normal file
75
node_modules/decap-cms-editor-component-image/src/__tests__/index.spec.js
generated
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
import component from '../index';
|
||||
|
||||
function getAsset(path) {
|
||||
return path;
|
||||
}
|
||||
|
||||
const image = '/image';
|
||||
const alt = 'alt';
|
||||
const title = 'title';
|
||||
|
||||
describe('editor component image', () => {
|
||||
it('should generate empty markdown image from empty object', () => {
|
||||
expect(component.toBlock({})).toEqual(`![]()`);
|
||||
});
|
||||
|
||||
it('should generate valid markdown from path', () => {
|
||||
expect(component.toBlock({ image })).toEqual(``);
|
||||
});
|
||||
|
||||
it('should generate valid markdown from path and alt text', () => {
|
||||
expect(component.toBlock({ image, alt })).toEqual(``);
|
||||
});
|
||||
|
||||
it('should generate valid markdown from path and title', () => {
|
||||
expect(component.toBlock({ image, title })).toEqual(``);
|
||||
});
|
||||
|
||||
it('should generate valid markdown from path, alt text, and title ', () => {
|
||||
expect(component.toBlock({ image, alt, title })).toEqual(``);
|
||||
});
|
||||
|
||||
it('should escape quotes in title', () => {
|
||||
expect(component.toBlock({ image, alt, title: `"ti"tle"` })).toEqual(
|
||||
``,
|
||||
);
|
||||
});
|
||||
|
||||
it('should generate valid react props', () => {
|
||||
expect(component.toPreview({ image, alt, title }, getAsset)).toMatchObject({
|
||||
props: { src: image, alt, title },
|
||||
});
|
||||
});
|
||||
|
||||
it('should match markdown with no properties defined', () => {
|
||||
expect(`![]()`).toMatch(component.pattern);
|
||||
});
|
||||
|
||||
it('should match markdown with path', () => {
|
||||
expect(``).toMatch(component.pattern);
|
||||
});
|
||||
|
||||
it('should match markdown with path and alt text', () => {
|
||||
expect(``).toMatch(component.pattern);
|
||||
});
|
||||
|
||||
it('should match markdown with path and title', () => {
|
||||
expect(``).toMatch(component.pattern);
|
||||
});
|
||||
|
||||
it('should match markdown with path, alt text, and title', () => {
|
||||
expect(``).toMatch(component.pattern);
|
||||
});
|
||||
|
||||
it('should match markdown with path, alt text, and title', () => {
|
||||
expect(``).toMatch(component.pattern);
|
||||
});
|
||||
|
||||
it('should match markdown with arbitrary amount of whitespace', () => {
|
||||
expect(``).toMatch(component.pattern);
|
||||
});
|
||||
|
||||
it('should match markdown with quoted title', () => {
|
||||
expect(``).toMatch(component.pattern);
|
||||
});
|
||||
});
|
||||
42
node_modules/decap-cms-editor-component-image/src/index.js
generated
vendored
Normal file
42
node_modules/decap-cms-editor-component-image/src/index.js
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
import React from 'react';
|
||||
|
||||
const image = {
|
||||
label: 'Image',
|
||||
id: 'image',
|
||||
fromBlock: match =>
|
||||
match && {
|
||||
image: match[2],
|
||||
alt: match[1],
|
||||
title: match[4],
|
||||
},
|
||||
toBlock: ({ alt, image, title }) =>
|
||||
`}"` : ''})`,
|
||||
// eslint-disable-next-line react/display-name
|
||||
toPreview: ({ alt, image, title }, getAsset, fields) => {
|
||||
const imageField = fields?.find(f => f.get('widget') === 'image');
|
||||
const src = getAsset(image, imageField);
|
||||
return <img src={src || ''} alt={alt || ''} title={title || ''} />;
|
||||
},
|
||||
pattern: /^!\[(.*)\]\((.*?)(\s"(.*)")?\)$/,
|
||||
fields: [
|
||||
{
|
||||
label: 'Image',
|
||||
name: 'image',
|
||||
widget: 'image',
|
||||
media_library: {
|
||||
allow_multiple: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
label: 'Alt Text',
|
||||
name: 'alt',
|
||||
},
|
||||
{
|
||||
label: 'Title',
|
||||
name: 'title',
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
export const DecapCmsEditorComponentImage = image;
|
||||
export default image;
|
||||
Reference in New Issue
Block a user