Tests for Text rendering component

This commit is contained in:
Jeff Avallone 2019-01-31 21:10:33 -05:00
parent f4e7bc0e76
commit ee915c39dc
3 changed files with 147 additions and 0 deletions

View File

@ -6,3 +6,5 @@ Enzyme.configure({ adapter: new Adapter() });
global.___loader = {
enqueue: jest.fn()
};
global.Element.prototype.getBBox = jest.fn();

View File

@ -0,0 +1,92 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Text layout 1`] = `
Object {
"box": Object {
"height": 20,
"width": 100,
},
"children": Array [
"Example content",
],
"props": Object {
"property": "example",
"transform": "translate(0 -18)",
},
"type": "Text",
}
`;
exports[`Text positioning text 1`] = `
<text
style={
Object {
"fontFamily": "Arial",
"fontSize": "16px",
}
}
transform="translate(1 2)"
>
Example
</text>
`;
exports[`Text rendering 1`] = `
<text
style={
Object {
"fontFamily": "Arial",
"fontSize": "16px",
}
}
>
Example
</text>
`;
exports[`Text rendering quoted text 1`] = `
<text
style={
Object {
"fontFamily": "Arial",
"fontSize": "16px",
}
}
>
<tspan
style={
Object {
"fill": "#908c83",
}
}
>
</tspan>
<tspan>
Example
</tspan>
<tspan
style={
Object {
"fill": "#908c83",
}
}
>
</tspan>
</text>
`;
exports[`Text rendering with a theme 1`] = `
<text
style={
Object {
"fill": "#fff",
"fontFamily": "Arial",
"fontSize": "16px",
}
}
>
Example
</text>
`;

View File

@ -0,0 +1,53 @@
import React from 'react';
import { shallow } from 'enzyme';
import Text, { layout } from 'rendering/Text';
describe('Text', () => {
test('rendering', () => {
const component = shallow(
<Text>Example</Text>
);
expect(component).toMatchSnapshot();
});
test('positioning text', () => {
const component = shallow(
<Text transform="translate(1 2)">Example</Text>
);
expect(component).toMatchSnapshot();
});
test('rendering with a theme', () => {
const component = shallow(
<Text theme="anchor">Example</Text>
);
expect(component).toMatchSnapshot();
});
test('rendering quoted text', () => {
const component = shallow(
<Text quoted={ true }>Example</Text>
);
expect(component).toMatchSnapshot();
});
test('layout', () => {
global.Element.prototype.getBBox.mockReturnValue({
width: 100,
height: 20,
y: 18
});
const processed = layout({
type: 'Text',
props: {
property: 'example'
},
children: [
'Example content'
]
});
expect(processed).toMatchSnapshot();
});
});